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.

243 lines
8.5 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. # Derive component identifiers, based on the name.
  9. id_light: ${name}
  10. id_light_mode: ${name}_light_mode
  11. id_power_button: ${name}_power_button
  12. id_color_button: ${name}_color_button
  13. id_slider_level: ${name}_slider_level
  14. id_front_panel_illumination: ${name}_front_panel_illumination
  15. # --------------------------------------------------------------------------
  16. # Use your own preferences for these components.
  17. # --------------------------------------------------------------------------
  18. wifi:
  19. ssid: "Your-SSID"
  20. password: "Your-WiFi-Network-Password"
  21. # Enable fallback hotspot (for captive portal) in case wifi connection fails
  22. ap:
  23. ssid: "ESPHome $friendly_name"
  24. password: "Password-For-Connecting-To-Captive-Portal"
  25. captive_portal:
  26. api:
  27. password: "Password-To-Link-HomeAssistant-To-This-Device"
  28. # Disable the reboot timeout. By default, the lamp reboots after 15
  29. # minutes without any client connections (e.g. when home assistant is off
  30. # line, or when the WiFi is broken). Reboots are annoying though, because
  31. # the RGBWW LEDs will turn off during the reboot, causing the light to
  32. # flicker.
  33. reboot_timeout: 0s
  34. ota:
  35. password: "Password-For-Flashing-This-Device-Over-The-Air"
  36. # These OTA triggers are used to provide some visual feedback during the OTA
  37. # flashing process. The light is turned blue when the upgrade starts, the
  38. # brightness indicator will represent the update progress (fills up from 0%
  39. # to 100%), the light will flash red when the upgrade fails or green when the
  40. # upgrade succeeds.
  41. # You can safely remove these if you don't want the visual feedback.
  42. on_begin:
  43. then:
  44. - light.disco_on:
  45. id: ${id_light}
  46. red: 0%
  47. green: 0%
  48. blue: 100%
  49. brightness: 2%
  50. transition_length: 0s
  51. on_progress:
  52. then:
  53. - output.set_level:
  54. id: ${id_front_panel_illumination}
  55. level: !lambda return (x / 100.0f);
  56. on_end:
  57. then:
  58. - light.disco_on:
  59. id: ${id_light}
  60. red: 0%
  61. green: 100%
  62. blue: 0%
  63. brightness: 2%
  64. transition_length: 0s
  65. on_error:
  66. then:
  67. - light.disco_on:
  68. id: ${id_light}
  69. red: 100%
  70. green: 0%
  71. blue: 0%
  72. brightness: 2%
  73. - delay: 1s
  74. - light.disco_off:
  75. id: ${id_light}
  76. # The log level can be raised when needed for debugging the firmware. For
  77. # production, a low log level is recommended. Mainly because high volume log
  78. # output might interfere with the API/WiFi connection stability. So when
  79. # raising the log level, beware that you might see dropped connections from
  80. # Home Assistant and the network log viewer.
  81. logger:
  82. level: WARN
  83. # --------------------------------------------------------------------------
  84. # Configuration specific for the Xiaomi Mijia Bedside Lamp 2.
  85. # This is just an example. You can of course modify it for your own needs.
  86. # --------------------------------------------------------------------------
  87. # Retrieve the code for the xiaomi_bslamp2 platform from GitHub.
  88. external_components:
  89. - source:
  90. type: git
  91. url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
  92. ref: main
  93. # A special platform package is used for enabling unicore and disabling the
  94. # efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
  95. # chip that is used in the lamp.
  96. esphome:
  97. name: ${name}
  98. platform: ESP32
  99. board: esp32doit-devkit-v1
  100. platformio_options:
  101. platform: espressif32@3.2.0
  102. platform_packages: |-
  103. framework-arduinoespressif32 @ https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc#v1.0.6
  104. # This component controls the LED lights of the lamp.
  105. light:
  106. - platform: xiaomi_bslamp2
  107. id: ${id_light}
  108. name: ${friendly_name} RGBWW Light
  109. default_transition_length: ${transition_length}
  110. # When the brightness is changed, then update the level indicator
  111. # on the front panel accordingly. In night light mode, turn off
  112. # the front panel illumination.
  113. on_brightness:
  114. - if:
  115. condition:
  116. text_sensor.state:
  117. id: ${id_light_mode}
  118. state: night
  119. then:
  120. - output.set_level:
  121. id: ${id_front_panel_illumination}
  122. level: 0
  123. else:
  124. - output.set_level:
  125. id: ${id_front_panel_illumination}
  126. level: !lambda return x;
  127. # You can use any effects that you like. These are just examples.
  128. effects:
  129. - random:
  130. name: "Slow Random"
  131. transition_length: 30s
  132. update_interval: 30s
  133. - random:
  134. name: "Fast Random"
  135. transition_length: 3s
  136. update_interval: 3s
  137. # You can define one or more groups of presets. These presets can
  138. # be activated using various "preset.activate" action options.
  139. # The presets can for example be used to mimic the behavior of the
  140. # original firmware (tapping the color button = go to next preset,
  141. # holding the color button = switch between RGB and white light mode).
  142. # These bindings have been setup below, using the binary_sensor for
  143. # the color button.
  144. presets:
  145. rgb:
  146. red: { red: 100%, green: 0%, blue: 0% }
  147. green: { red: 0%, green: 100%, blue: 0% }
  148. blue: { red: 0%, green: 0%, blue: 100% }
  149. yellow: { red: 100%, green: 100%, blue: 0% }
  150. purple: { red: 100%, green: 0%, blue: 100% }
  151. randomize: { effect: Fast Random }
  152. white:
  153. cold: { color_temperature: 153 mireds }
  154. chilly: { color_temperature: 275 mireds }
  155. luke: { color_temperature: 400 mireds }
  156. warm: { color_temperature: 588 mireds }
  157. # This text sensor propagates the currently active light mode.
  158. # The possible light modes are: "off", "rgb", "white" and "night".
  159. # By setting the name, the text_sensor will show up as an entity
  160. # for the lamp in Home Assistant.
  161. text_sensor:
  162. - platform: xiaomi_bslamp2
  163. name: ${name} Light Mode
  164. id: ${id_light_mode}
  165. # This float output controls the front panel illumination + level indicator.
  166. # Value 0.0 turns off the illumination. Other values (up to 1.0) turn on
  167. # the illumination and set the level indicator to the requested level.
  168. output:
  169. - platform: xiaomi_bslamp2
  170. id: ${id_front_panel_illumination}
  171. # Binary sensors can be created for handling front panel touch / release
  172. # events. To specify what part of the front panel to look at, the "for"
  173. # parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
  174. binary_sensor:
  175. # When tapping the power button, toggle the light.
  176. # When holding the power button, turn on night light mode.
  177. - platform: xiaomi_bslamp2
  178. id: ${id_power_button}
  179. for: POWER_BUTTON
  180. on_multi_click:
  181. - timing:
  182. - ON for at most 0.8s
  183. then:
  184. - light.toggle: ${id_light}
  185. - timing:
  186. - ON for at least 0.8s
  187. then:
  188. - light.turn_on:
  189. id: ${id_light}
  190. brightness: 1%
  191. # When tapping the color button, acivate the next preset.
  192. # When holding the color button, activate the next preset group.
  193. - platform: xiaomi_bslamp2
  194. id: ${id_color_button}
  195. for: COLOR_BUTTON
  196. on_multi_click:
  197. - timing:
  198. - ON for at most 0.6s
  199. then:
  200. - preset.activate:
  201. next: preset
  202. - timing:
  203. - ON for at least 0.6s
  204. then:
  205. - preset.activate:
  206. next: group
  207. # This sensor component publishes touch events for the front panel slider.
  208. # The published value represents the level at which the slider was touched.
  209. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  210. # be modified using the "range_from" and "range_to" parameters.
  211. sensor:
  212. # When the slider is touched, update the brightness.
  213. # Brightness 0.01 initiates the light night mode, which has already
  214. # been handled above (by holding the power button). Therefore, brightness
  215. # starts from 0.02 here, to not trigger night mode using the slider.
  216. - platform: xiaomi_bslamp2
  217. id: ${id_slider_level}
  218. range_from: 0.02
  219. on_value:
  220. then:
  221. - light.turn_on:
  222. id: ${id_light}
  223. brightness: !lambda return x;