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.

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