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.

256 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. # A special platform package is used for enabling unicore and disabling the
  106. # efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
  107. # chip that is used in the lamp.
  108. esphome:
  109. name: ${name}
  110. platform: ESP32
  111. board: esp32doit-devkit-v1
  112. platformio_options:
  113. platform: espressif32@3.2.0
  114. platform_packages: |-
  115. framework-arduinoespressif32 @ https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc#v1.0.6
  116. # This component controls the LED lights of the lamp.
  117. light:
  118. - platform: xiaomi_bslamp2
  119. id: ${id_light}
  120. name: ${friendly_name} RGBWW Light
  121. default_transition_length: ${transition_length}
  122. # When the brightness is changed, then update the level indicator
  123. # on the front panel accordingly. In night light mode, turn off
  124. # the front panel illumination.
  125. on_brightness:
  126. - if:
  127. condition:
  128. text_sensor.state:
  129. id: ${id_light_mode}
  130. state: night
  131. then:
  132. - output.set_level:
  133. id: ${id_front_panel_illumination}
  134. level: 0
  135. else:
  136. - output.set_level:
  137. id: ${id_front_panel_illumination}
  138. level: !lambda return x;
  139. # You can use any effects that you like. These are just examples.
  140. effects:
  141. - random:
  142. name: "Slow Random"
  143. transition_length: 30s
  144. update_interval: 30s
  145. - random:
  146. name: "Fast Random"
  147. transition_length: 3s
  148. update_interval: 3s
  149. # You can define one or more groups of presets. These presets can
  150. # be activated using various "preset.activate" action options.
  151. # The presets can for example be used to mimic the behavior of the
  152. # original firmware (tapping the color button = go to next preset,
  153. # holding the color button = switch between RGB and white light mode).
  154. # These bindings have been setup below, using the binary_sensor for
  155. # the color button.
  156. presets:
  157. rgb:
  158. red: { red: 100%, green: 0%, blue: 0% }
  159. green: { red: 0%, green: 100%, blue: 0% }
  160. blue: { red: 0%, green: 0%, blue: 100% }
  161. yellow: { red: 100%, green: 100%, blue: 0% }
  162. purple: { red: 100%, green: 0%, blue: 100% }
  163. randomize: { effect: Fast Random }
  164. white:
  165. cold: { color_temperature: 153 mireds }
  166. chilly: { color_temperature: 275 mireds }
  167. luke: { color_temperature: 400 mireds }
  168. warm: { color_temperature: 588 mireds }
  169. # This text sensor propagates the currently active light mode.
  170. # The possible light modes are: "off", "rgb", "white" and "night".
  171. # By setting the name, the text_sensor will show up as an entity
  172. # for the lamp in Home Assistant.
  173. text_sensor:
  174. - platform: xiaomi_bslamp2
  175. name: ${friendly_name} Light Mode
  176. id: ${id_light_mode}
  177. # This float output controls the front panel illumination + level indicator.
  178. # Value 0.0 turns off the illumination. Other values (up to 1.0) turn on
  179. # the illumination and set the level indicator to the requested level.
  180. output:
  181. - platform: xiaomi_bslamp2
  182. id: ${id_front_panel_illumination}
  183. # Binary sensors can be created for handling front panel touch / release
  184. # events. To specify what part of the front panel to look at, the "for"
  185. # parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
  186. binary_sensor:
  187. # When tapping the power button, toggle the light.
  188. # When holding the power button, turn on night light mode.
  189. - platform: xiaomi_bslamp2
  190. id: ${id_power_button}
  191. for: POWER_BUTTON
  192. on_multi_click:
  193. - timing:
  194. - ON for at most 0.8s
  195. then:
  196. - light.toggle: ${id_light}
  197. - timing:
  198. - ON for at least 0.8s
  199. then:
  200. - light.turn_on:
  201. id: ${id_light}
  202. brightness: 1%
  203. # When tapping the color button, acivate the next preset.
  204. # When holding the color button, activate the next preset group.
  205. - platform: xiaomi_bslamp2
  206. id: ${id_color_button}
  207. for: COLOR_BUTTON
  208. on_multi_click:
  209. - timing:
  210. - ON for at most 0.6s
  211. then:
  212. - preset.activate:
  213. next: preset
  214. - timing:
  215. - ON for at least 0.6s
  216. then:
  217. - preset.activate:
  218. next: group
  219. # This sensor component publishes touch events for the front panel slider.
  220. # The published value represents the level at which the slider was touched.
  221. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  222. # be modified using the "range_from" and "range_to" parameters.
  223. sensor:
  224. # When the slider is touched, update the brightness.
  225. # Brightness 0.01 initiates the light night mode, which has already
  226. # been handled above (by holding the power button). Therefore, brightness
  227. # starts from 0.02 here, to not trigger night mode using the slider.
  228. - platform: xiaomi_bslamp2
  229. id: ${id_slider_level}
  230. range_from: 0.02
  231. on_value:
  232. then:
  233. - light.turn_on:
  234. id: ${id_light}
  235. brightness: !lambda return x;