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.

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