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.

180 lines
5.8 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. then:
  56. - output.set_level:
  57. id: ${id_front_panel_output}
  58. level: !lambda |-
  59. if (id(${id_light_mode}).state == "night")
  60. return 0;
  61. else
  62. return x;
  63. # You can use any effects that you like. These are just examples.
  64. effects:
  65. - random:
  66. name: "Slow Random"
  67. transition_length: 30s
  68. update_interval: 30s
  69. - random:
  70. name: "Fast Random"
  71. transition_length: 3s
  72. update_interval: 3s
  73. # A fun thing you could do with the front panel output component
  74. # (as defined below): wrap it in a light component, so you can
  75. # treat the front panel illumination as a monochromatic light
  76. # from within Home Assitant.
  77. # This is primarily a demo. It's barely useful for a device that
  78. # one has running in production.
  79. - platform: monochromatic
  80. name: $friendly_name Front Panel Light
  81. id: ${id_front_panel_light}
  82. output: ${id_front_panel_output}
  83. default_transition_length: 0s
  84. gamma_correct: 1
  85. effects:
  86. - lambda:
  87. name: Random Level
  88. update_interval: 150ms
  89. lambda: |-
  90. auto call = id(${id_front_panel_light}).turn_on();
  91. call.set_transition_length(150);
  92. call.set_brightness(random_float());
  93. call.perform();
  94. # This text sensor propagates the currently active light mode.
  95. # The possible light modes are: "off", "rgb", "white" and "night".
  96. text_sensor:
  97. - platform: yeelight_bs2
  98. name: ${name} Light Mode
  99. id: ${id_light_mode}
  100. # This output controls the front panel illumination + level indication.
  101. # Value 0.0 turns off the illumination.
  102. # Other values (up to 1.0) turn on the illumination and set the level
  103. # indication to the requested level.
  104. output:
  105. - platform: yeelight_bs2
  106. id: ${id_front_panel_output}
  107. # Binary sensors can be created for handling front panel touch / release
  108. # events. To specify what part of the front panel to look at, the "part"
  109. # parameter can be set to: "any" (i.e. the default), "power button",
  110. # "color button" or "slider".
  111. binary_sensor:
  112. # When touching the power button, toggle the light.
  113. # When holding the power button, turn on night light mode.
  114. - platform: yeelight_bs2
  115. id: ${id_power_button}
  116. part: power button
  117. on_multi_click:
  118. - timing:
  119. - ON for at most 0.8s
  120. then:
  121. - light.toggle: ${id_light}
  122. - timing:
  123. - ON for at least 0.8s
  124. then:
  125. - light.turn_on:
  126. id: ${id_light}
  127. red: 1
  128. green: 1
  129. blue: 1
  130. brightness: 0.01
  131. # When touching the color button, set a random color.
  132. - platform: yeelight_bs2
  133. id: ${id_color_button}
  134. part: color button
  135. on_multi_click:
  136. - timing:
  137. - ON for at most 0.8s
  138. then:
  139. - light.turn_on:
  140. id: ${id_light}
  141. red: !lambda return random_float();
  142. green: !lambda return random_float();
  143. blue: !lambda return random_float();
  144. # This sensor component publishes touch events for the front panel slider.
  145. # The published value represents the level at which the slider was touched.
  146. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  147. # be modified using the "range_from" and "range_to" parameters.
  148. sensor:
  149. # When the slider is touched, update the brightness.
  150. # Brightness 0.01 initiates the light night mode, which has already
  151. # been handled above. Therefore, brightness starts from 0.02 here,
  152. # so night mode is not triggered from the slider.
  153. - platform: yeelight_bs2
  154. id: ${id_slider_level}
  155. range_from: 0.02
  156. on_value:
  157. then:
  158. - light.turn_on:
  159. id: ${id_light}
  160. brightness: !lambda return x;