Browse Source

Fixed front panel brightness indicator scale + random color button.

The indicator was not halfway when using 0.5 as the output value.

Also added an example of how the output could be wrapped in a
light component, to expose it to Home Assistant as a monochromatic
light. Not that useful probably, but a nice display of ESPHome's
flexibility.

The example.yaml now also updates the brightness indicator when
the light brightness changes. When switching the device to night
light mode, it will turn off the front panel illumation completely.

And last but not least: the example configuration now shows a way
to set the device to a random color when touching the color button.
pull/9/head
Maurice Makaay 3 years ago
parent
commit
402f57f040
3 changed files with 50 additions and 21 deletions
  1. +39
    -10
      doc/example.yaml
  2. +9
    -9
      front_panel_hal.h
  3. +2
    -2
      output/output.h

+ 39
- 10
doc/example.yaml View File

@ -5,7 +5,7 @@
substitutions: substitutions:
name: bedside_lamp name: bedside_lamp
friendly_name: Bedside Lamp friendly_name: Bedside Lamp
transition_length: 800ms
transition_length: 700ms
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Use your own preferences for these components. # Use your own preferences for these components.
@ -30,7 +30,7 @@ ota:
logger: logger:
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Configureation specific for the Yeelight Bedside Lamp 2.
# Configuration specific for the Yeelight Bedside Lamp 2.
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Special platform + package are used for enabling unicore and disabling the # Special platform + package are used for enabling unicore and disabling the
@ -45,12 +45,20 @@ esphome:
platform_packages: |-4 platform_packages: |-4
framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6 framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
# This component controls the light of the device.
light: light:
# This component controls the LED lights of the device.
- platform: yeelight_bs2 - platform: yeelight_bs2
id: ${name} id: ${name}
name: ${friendly_name} RGBW Light name: ${friendly_name} RGBW Light
default_transition_length: ${transition_length} default_transition_length: ${transition_length}
# When the brightness is changed, then update the level indication
# on the front panel accordingly. In night light mode, turn off
# the front panel illumination.
on_brightness:
then:
- output.set_level:
id: ${name}_front_panel_light
level: !lambda if (x < 0.012f) return 0; else return x;
# You can use any effects that you like. These are just examples. # You can use any effects that you like. These are just examples.
effects: effects:
- random: - random:
@ -62,9 +70,20 @@ light:
transition_length: 3s transition_length: 3s
update_interval: 3s update_interval: 3s
# This output component controls the front panel light + level.
# Value 0.0 turns off the front panel light.
# Other values (up to 1.0) turn on the light + slider light level.
# A fun thing you could do with the front panel output component
# (as defined below): wrap it in a light component, so you can
# treat the front panel illumination as a monochromatic light
# from within Home Assitant.
- platform: monochromatic
name: $friendly_name Front Panel Light
output: ${name}_front_panel_light
default_transition_length: 0s
gamma_correct: 1
# This output controls the front panel illumination + level indication.
# Value 0.0 turns off the illumination.
# Other values (up to 1.0) turn on the illumination and set the level
# indication to the requested level.
output: output:
- platform: yeelight_bs2 - platform: yeelight_bs2
id: ${name}_front_panel_light id: ${name}_front_panel_light
@ -81,20 +100,30 @@ binary_sensor:
on_press: on_press:
then: then:
- light.toggle: ${name} - light.toggle: ${name}
# When touching the color button, set a random color.
# When holding the color button, turn on night light mode. # When holding the color button, turn on night light mode.
- platform: yeelight_bs2 - platform: yeelight_bs2
id: ${name}_color_button id: ${name}_color_button
part: color button part: color button
on_multi_click: on_multi_click:
- timing:
- ON for at most 0.8s
then:
- light.turn_on:
id: ${name}
red: !lambda return random_float();
green: !lambda return random_float();
blue: !lambda return random_float();
white: 0
- timing: - timing:
- ON for at least 0.8s - ON for at least 0.8s
then: then:
- light.turn_on: - light.turn_on:
id: ${name} id: ${name}
brightness: 0.01
red: 0
red: 1
green: 1 green: 1
blue: 0
blue: 1
brightness: 0.01
# This sensor component publishes touch events for the front panel slider. # This sensor component publishes touch events for the front panel slider.
# The published value represents the level at which the slider was touched. # The published value represents the level at which the slider was touched.
@ -103,7 +132,7 @@ binary_sensor:
sensor: sensor:
# When the slider is touched, update the brightness. # When the slider is touched, update the brightness.
# Brightness 0.01 initiates the light night mode, which has already # Brightness 0.01 initiates the light night mode, which has already
# been handle above. Therefore, brightness starts from 0.02 here,
# been handled above. Therefore, brightness starts from 0.02 here,
# so night mode is not triggered from the slider. # so night mode is not triggered from the slider.
- platform: yeelight_bs2 - platform: yeelight_bs2
id: ${name}_slider_level id: ${name}_slider_level


+ 9
- 9
front_panel_hal.h View File

@ -215,23 +215,23 @@ public:
void set_light_level(float level) { void set_light_level(float level) {
if (level == 0.0f) if (level == 0.0f)
write_bytes_raw(TURN_OFF, MSG_LEN); write_bytes_raw(TURN_OFF, MSG_LEN);
else if (level < 0.10)
else if (level < 0.15)
write_bytes_raw(SET_LEVEL_1, MSG_LEN); write_bytes_raw(SET_LEVEL_1, MSG_LEN);
else if (level < 0.20)
else if (level < 0.25)
write_bytes_raw(SET_LEVEL_2, MSG_LEN); write_bytes_raw(SET_LEVEL_2, MSG_LEN);
else if (level < 0.30)
else if (level < 0.35)
write_bytes_raw(SET_LEVEL_3, MSG_LEN); write_bytes_raw(SET_LEVEL_3, MSG_LEN);
else if (level < 0.40)
else if (level < 0.45)
write_bytes_raw(SET_LEVEL_4, MSG_LEN); write_bytes_raw(SET_LEVEL_4, MSG_LEN);
else if (level < 0.50)
else if (level < 0.55)
write_bytes_raw(SET_LEVEL_5, MSG_LEN); write_bytes_raw(SET_LEVEL_5, MSG_LEN);
else if (level < 0.60)
else if (level < 0.65)
write_bytes_raw(SET_LEVEL_6, MSG_LEN); write_bytes_raw(SET_LEVEL_6, MSG_LEN);
else if (level < 0.70)
else if (level < 0.75)
write_bytes_raw(SET_LEVEL_7, MSG_LEN); write_bytes_raw(SET_LEVEL_7, MSG_LEN);
else if (level < 0.80)
else if (level < 0.85)
write_bytes_raw(SET_LEVEL_8, MSG_LEN); write_bytes_raw(SET_LEVEL_8, MSG_LEN);
else if (level < 0.90)
else if (level < 0.95)
write_bytes_raw(SET_LEVEL_9, MSG_LEN); write_bytes_raw(SET_LEVEL_9, MSG_LEN);
else else
write_bytes_raw(SET_LEVEL_10, MSG_LEN); write_bytes_raw(SET_LEVEL_10, MSG_LEN);


+ 2
- 2
output/output.h View File

@ -10,8 +10,8 @@ namespace yeelight {
namespace bs2 { namespace bs2 {
/** /**
* An output, used for controlling the front panel light on the
* Yeelight Bedside Lamp 2 front panel.
* An output, used for controlling the front panel illumination and
* brightness level indicator on the Yeelight Bedside Lamp 2 front panel.
*/ */
class YeelightBS2FrontPanelLight : public output::FloatOutput, public Component { class YeelightBS2FrontPanelLight : public output::FloatOutput, public Component {
public: public:


Loading…
Cancel
Save