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.

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