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.

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