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.

200 lines
7.2 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_front_panel_illumination: ${name}_front_panel_output
  11. id_power_button: ${name}_power_button
  12. id_color_button: ${name}_color_button
  13. id_slider_level: ${name}_slider_level
  14. id_light_mode: ${name}_light_mode
  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
  29. # after 15 minutes without any client connections (e.g. when
  30. # home assistant is off line, or when the WiFi is broken).
  31. # Reboots are annoying though, because the RGBWW LEDs will turn
  32. # off during the reboot, causing the light to 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. # Special platform + package are used for enabling unicore and disabling the
  48. # efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
  49. # chip that is used in the lamp.
  50. esphome:
  51. name: ${name}
  52. platform: ESP32
  53. board: esp32doit-devkit-v1
  54. platformio_options:
  55. platform: espressif32@3.2.0
  56. platform_packages: |-4
  57. framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
  58. # This component controls the LED lights of the lamp.
  59. light:
  60. - platform: xiaomi_bslamp2
  61. id: ${id_light}
  62. name: ${friendly_name} RGBW Light
  63. default_transition_length: ${transition_length}
  64. # When the brightness is changed, then update the level indicator
  65. # on the front panel accordingly. In night light mode, turn off
  66. # the front panel illumination.
  67. on_brightness:
  68. - if:
  69. condition:
  70. text_sensor.state:
  71. id: ${id_light_mode}
  72. state: night
  73. then:
  74. - output.set_level:
  75. id: ${id_front_panel_illumination}
  76. level: 0
  77. else:
  78. - output.set_level:
  79. id: ${id_front_panel_illumination}
  80. level: !lambda return x;
  81. # You can use any effects that you like. These are just examples.
  82. effects:
  83. - random:
  84. name: "Slow Random"
  85. transition_length: 30s
  86. update_interval: 30s
  87. - random:
  88. name: "Fast Random"
  89. transition_length: 3s
  90. update_interval: 3s
  91. # You can define one or more groups of presets. These presets can
  92. # be activated using various "preset.activate" action options.
  93. # The presets can for example be used to mimic the behavior of the
  94. # original firmware (tapping the color button = go to next preset,
  95. # holding the color button = switch between RGB and white light mode).
  96. # These bindings have been setup below, using the binary_sensor for
  97. # the color button.
  98. presets:
  99. rgb:
  100. red: { red: 100%, green: 0%, blue: 0% }
  101. green: { red: 0%, green: 100%, blue: 0% }
  102. blue: { red: 0%, green: 0%, blue: 100% }
  103. yellow: { red: 100%, green: 100%, blue: 0% }
  104. purple: { red: 100%, green: 0%, blue: 100% }
  105. randomize: { effect: Fast Random }
  106. white:
  107. cold: { color_temperature: 153 mireds }
  108. chilly: { color_temperature: 275 mireds }
  109. luke: { color_temperature: 400 mireds }
  110. warm: { color_temperature: 588 mireds }
  111. # This text sensor propagates the currently active light mode.
  112. # The possible light modes are: "off", "rgb", "white" and "night".
  113. # By setting the name, the text_sensor will show up as an entity
  114. # for the lamp in Home Assistant.
  115. text_sensor:
  116. - platform: xiaomi_bslamp2
  117. name: ${name} Light Mode
  118. id: ${id_light_mode}
  119. # This float output controls the front panel illumination + level indicator.
  120. # Value 0.0 turns off the illumination.
  121. # Other values (up to 1.0) turn on the illumination and set the level
  122. # indicator to the requested level.
  123. output:
  124. - platform: xiaomi_bslamp2
  125. id: ${id_front_panel_illumination}
  126. # Binary sensors can be created for handling front panel touch / release
  127. # events. To specify what part of the front panel to look at, the "part"
  128. # parameter can be set to: "any" (i.e. the default), "POWER_BUTTON",
  129. # "COLOR_BUTTON" or "SLIDER".
  130. binary_sensor:
  131. # When tapping the power button, toggle the light.
  132. # When holding the power button, turn on night light mode.
  133. - platform: xiaomi_bslamp2
  134. id: ${id_power_button}
  135. part: POWER_BUTTON
  136. on_multi_click:
  137. - timing:
  138. - ON for at most 0.8s
  139. then:
  140. - light.toggle: ${id_light}
  141. - timing:
  142. - ON for at least 0.8s
  143. then:
  144. - light.turn_on:
  145. id: ${id_light}
  146. red: 1
  147. green: 1
  148. blue: 1
  149. brightness: 0.01
  150. # When tapping the color button, acivate the next preset.
  151. # When holding the color button, activate the next preset group.
  152. - platform: xiaomi_bslamp2
  153. id: ${id_color_button}
  154. part: COLOR_BUTTON
  155. on_multi_click:
  156. - timing:
  157. - ON for at most 0.6s
  158. then:
  159. - preset.activate:
  160. next: preset
  161. - timing:
  162. - ON for at least 0.6s
  163. then:
  164. - preset.activate:
  165. next: group
  166. # This sensor component publishes touch events for the front panel slider.
  167. # The published value represents the level at which the slider was touched.
  168. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  169. # be modified using the "range_from" and "range_to" parameters.
  170. sensor:
  171. # When the slider is touched, update the brightness.
  172. # Brightness 0.01 initiates the light night mode, which has already
  173. # been handled above (by holding the power button). Therefore, brightness
  174. # starts from 0.02 here, to not trigger night mode using the slider.
  175. - platform: xiaomi_bslamp2
  176. id: ${id_slider_level}
  177. range_from: 0.02
  178. on_value:
  179. then:
  180. - light.turn_on:
  181. id: ${id_light}
  182. brightness: !lambda return x;