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.

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