# --------------------------------------------------------------------------
|
|
# A few practical configuration substitutions.
|
|
# --------------------------------------------------------------------------
|
|
|
|
substitutions:
|
|
name: bedside_lamp
|
|
friendly_name: Bedside Lamp
|
|
transition_length: 500ms
|
|
|
|
# Some derived identifiers for the device components.
|
|
id_light: ${name}
|
|
id_front_panel_light: ${name}_front_panel_light
|
|
id_front_panel_output: ${name}_front_panel_output
|
|
id_power_button: ${name}_power_button
|
|
id_color_button: ${name}_color_button
|
|
id_slider_level: ${name}_slider_level
|
|
id_light_mode: ${name}_light_mode
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Use your own preferences for these components.
|
|
# --------------------------------------------------------------------------
|
|
|
|
wifi:
|
|
ssid: "Your-SSID"
|
|
password: "Your-Password"
|
|
use_address: 192.168.10.12
|
|
|
|
# Enable fallback hotspot (for captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: "ESPHome $friendly_name"
|
|
password: "bedside2021"
|
|
|
|
captive_portal:
|
|
|
|
api:
|
|
|
|
ota:
|
|
|
|
logger:
|
|
|
|
# --------------------------------------------------------------------------
|
|
# Configuration specific for the Yeelight Bedside Lamp 2.
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Special platform + package are used for enabling unicore and disabling the
|
|
# efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
|
|
# chip that is used in the device.
|
|
esphome:
|
|
name: ${name}
|
|
platform: ESP32
|
|
board: esp32doit-devkit-v1
|
|
platformio_options:
|
|
platform: espressif32@3.2.0
|
|
platform_packages: |-4
|
|
framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
|
|
|
|
light:
|
|
# This component controls the LED lights of the device.
|
|
- platform: yeelight_bs2
|
|
id: ${id_light}
|
|
name: ${friendly_name} RGBW Light
|
|
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: ${id_front_panel_output}
|
|
level: !lambda if (x < 0.012f) return 0; else return x;
|
|
# You can use any effects that you like. These are just examples.
|
|
effects:
|
|
- random:
|
|
name: "Slow Random"
|
|
transition_length: 30s
|
|
update_interval: 30s
|
|
- random:
|
|
name: "Fast Random"
|
|
transition_length: 3s
|
|
update_interval: 3s
|
|
|
|
# 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.
|
|
# This is primarily a demo. It's barely useful for a device that
|
|
# one has running in production.
|
|
- platform: monochromatic
|
|
name: $friendly_name Front Panel Light
|
|
id: ${id_front_panel_light}
|
|
output: ${id_front_panel_output}
|
|
default_transition_length: 0s
|
|
gamma_correct: 1
|
|
effects:
|
|
- lambda:
|
|
name: Random Level
|
|
update_interval: 150ms
|
|
lambda: |-
|
|
auto call = id(${id_front_panel_light}).turn_on();
|
|
call.set_transition_length(150);
|
|
call.set_brightness(random_float());
|
|
call.perform();
|
|
|
|
|
|
# This text sensor propagates the currently active light mode.
|
|
# The possible light modes are: "off", "rgb", "white" and "night".
|
|
text_sensor:
|
|
- platform: yeelight_bs2
|
|
name: ${name} Light Mode
|
|
id: ${id_light_mode}
|
|
|
|
# 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:
|
|
- platform: yeelight_bs2
|
|
id: ${id_front_panel_output}
|
|
|
|
# Binary sensors can be created for handling front panel touch / release
|
|
# events. To specify what part of the front panel to look at, the "part"
|
|
# parameter can be set to: "any" (i.e. the default), "power button",
|
|
# "color button" or "slider".
|
|
binary_sensor:
|
|
# When touching the power button, toggle the light.
|
|
# When holding the power button, turn on night light mode.
|
|
- platform: yeelight_bs2
|
|
id: ${id_power_button}
|
|
part: power button
|
|
on_multi_click:
|
|
- timing:
|
|
- ON for at most 0.8s
|
|
then:
|
|
- light.toggle: ${id_light}
|
|
- timing:
|
|
- ON for at least 0.8s
|
|
then:
|
|
- light.turn_on:
|
|
id: ${id_light}
|
|
red: 1
|
|
green: 1
|
|
blue: 1
|
|
brightness: 0.01
|
|
|
|
# When touching the color button, set a random color.
|
|
- platform: yeelight_bs2
|
|
id: ${id_color_button}
|
|
part: color button
|
|
on_multi_click:
|
|
- timing:
|
|
- ON for at most 0.8s
|
|
then:
|
|
- light.turn_on:
|
|
id: ${id_light}
|
|
red: !lambda return random_float();
|
|
green: !lambda return random_float();
|
|
blue: !lambda return random_float();
|
|
|
|
# This sensor component publishes touch events for the front panel slider.
|
|
# The published value represents the level at which the slider was touched.
|
|
# By default, values range from 0.01 to 1.00 (in 20 steps). This range can
|
|
# be modified using the "range_from" and "range_to" parameters.
|
|
sensor:
|
|
# When the slider is touched, update the brightness.
|
|
# Brightness 0.01 initiates the light night mode, which has already
|
|
# been handled above. Therefore, brightness starts from 0.02 here,
|
|
# so night mode is not triggered from the slider.
|
|
- platform: yeelight_bs2
|
|
id: ${id_slider_level}
|
|
range_from: 0.02
|
|
on_value:
|
|
then:
|
|
- light.turn_on:
|
|
id: ${id_light}
|
|
brightness: !lambda return x;
|
|
|