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.

258 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. # 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. - front_panel.set_level: !lambda return (x / 100.0f);
  68. - front_panel.update_leds:
  69. on_end:
  70. then:
  71. - light.disco_on:
  72. id: ${id_light}
  73. red: 0%
  74. green: 100%
  75. blue: 0%
  76. brightness: 2%
  77. transition_length: 0s
  78. on_error:
  79. then:
  80. - light.disco_on:
  81. id: ${id_light}
  82. red: 100%
  83. green: 0%
  84. blue: 0%
  85. brightness: 2%
  86. - delay: 1s
  87. - light.disco_off:
  88. id: ${id_light}
  89. # The log level can be raised when needed for debugging the firmware. For
  90. # production, a low log level is recommended. Mainly because high volume log
  91. # output might interfere with the API/WiFi connection stability. So when
  92. # raising the log level, beware that you might see dropped connections from
  93. # Home Assistant and the network log viewer.
  94. logger:
  95. level: WARN
  96. # --------------------------------------------------------------------------
  97. # Configuration specific for the Xiaomi Mijia Bedside Lamp 2.
  98. # This is just an example. You can of course modify it for your own needs.
  99. # --------------------------------------------------------------------------
  100. # Retrieve the code for the xiaomi_bslamp2 platform from GitHub.
  101. external_components:
  102. - source:
  103. type: git
  104. url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
  105. ref: main
  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: ${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;