You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.2 KiB

  1. # --------------------------------------------------------------------------
  2. # A few practical configuration substitutions.
  3. # --------------------------------------------------------------------------
  4. substitutions:
  5. name: bedside_lamp
  6. friendly_name: Bedside Lamp
  7. transition_length: 500ms
  8. # Some derived identifiers for the device components.
  9. id_light: ${name}
  10. id_front_panel_light: ${name}_front_panel_light
  11. id_front_panel_output: ${name}_front_panel_output
  12. id_power_button: ${name}_power_button
  13. id_color_button: ${name}_color_button
  14. id_slider_level: ${name}_slider_level
  15. id_light_mode: ${name}_light_mode
  16. # --------------------------------------------------------------------------
  17. # Use your own preferences for these components.
  18. # --------------------------------------------------------------------------
  19. wifi:
  20. ssid: "Your-SSID"
  21. password: "Your-Password"
  22. use_address: 192.168.10.12
  23. # Enable fallback hotspot (for captive portal) in case wifi connection fails
  24. ap:
  25. ssid: "ESPHome $friendly_name"
  26. password: "bedside2021"
  27. captive_portal:
  28. api:
  29. ota:
  30. logger:
  31. # --------------------------------------------------------------------------
  32. # Configuration specific for the Yeelight Bedside Lamp 2.
  33. # --------------------------------------------------------------------------
  34. # Special platform + package are used for enabling unicore and disabling the
  35. # efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
  36. # chip that is used in the device.
  37. esphome:
  38. name: ${name}
  39. platform: ESP32
  40. board: esp32doit-devkit-v1
  41. platformio_options:
  42. platform: espressif32@3.2.0
  43. platform_packages: |-4
  44. framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
  45. light:
  46. # This component controls the LED lights of the device.
  47. - platform: yeelight_bs2
  48. id: ${id_light}
  49. name: ${friendly_name} RGBW Light
  50. default_transition_length: ${transition_length}
  51. # When the brightness is changed, then update the level indication
  52. # on the front panel accordingly. In night light mode, turn off
  53. # the front panel illumination.
  54. on_brightness:
  55. - if:
  56. condition:
  57. text_sensor.state:
  58. id: ${id_light_mode}
  59. state: night
  60. then:
  61. - output.set_level:
  62. id: ${id_front_panel_output}
  63. level: 0
  64. else:
  65. - output.set_level:
  66. id: ${id_front_panel_output}
  67. level: !lambda return x;
  68. # You can use any effects that you like. These are just examples.
  69. effects:
  70. - random:
  71. name: "Slow Random"
  72. transition_length: 30s
  73. update_interval: 30s
  74. - random:
  75. name: "Fast Random"
  76. transition_length: 3s
  77. update_interval: 3s
  78. # This text sensor propagates the currently active light mode.
  79. # The possible light modes are: "off", "rgb", "white" and "night".
  80. text_sensor:
  81. - platform: yeelight_bs2
  82. name: ${name} Light Mode
  83. id: ${id_light_mode}
  84. # This output controls the front panel illumination + level indication.
  85. # Value 0.0 turns off the illumination.
  86. # Other values (up to 1.0) turn on the illumination and set the level
  87. # indication to the requested level.
  88. output:
  89. - platform: yeelight_bs2
  90. id: ${id_front_panel_output}
  91. # Binary sensors can be created for handling front panel touch / release
  92. # events. To specify what part of the front panel to look at, the "part"
  93. # parameter can be set to: "any" (i.e. the default), "power button",
  94. # "color button" or "slider".
  95. binary_sensor:
  96. # When touching the power button, toggle the light.
  97. # When holding the power button, turn on night light mode.
  98. - platform: yeelight_bs2
  99. id: ${id_power_button}
  100. part: power button
  101. on_multi_click:
  102. - timing:
  103. - ON for at most 0.8s
  104. then:
  105. - light.toggle: ${id_light}
  106. - timing:
  107. - ON for at least 0.8s
  108. then:
  109. - light.turn_on:
  110. id: ${id_light}
  111. red: 1
  112. green: 1
  113. blue: 1
  114. brightness: 0.01
  115. # When touching the color button, set a random color.
  116. - platform: yeelight_bs2
  117. id: ${id_color_button}
  118. part: color button
  119. on_multi_click:
  120. - timing:
  121. - ON for at most 0.8s
  122. then:
  123. - light.turn_on:
  124. id: ${id_light}
  125. red: !lambda return random_float();
  126. green: !lambda return random_float();
  127. blue: !lambda return random_float();
  128. # This sensor component publishes touch events for the front panel slider.
  129. # The published value represents the level at which the slider was touched.
  130. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  131. # be modified using the "range_from" and "range_to" parameters.
  132. sensor:
  133. # When the slider is touched, update the brightness.
  134. # Brightness 0.01 initiates the light night mode, which has already
  135. # been handled above. Therefore, brightness starts from 0.02 here,
  136. # so night mode is not triggered from the slider.
  137. - platform: yeelight_bs2
  138. id: ${id_slider_level}
  139. range_from: 0.02
  140. on_value:
  141. then:
  142. - light.turn_on:
  143. id: ${id_light}
  144. brightness: !lambda return x;