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.

199 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. # 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. Other values (up to 1.0) turn on
  121. # the illumination and set the level indicator to the requested level.
  122. output:
  123. - platform: xiaomi_bslamp2
  124. id: ${id_front_panel_illumination}
  125. # Binary sensors can be created for handling front panel touch / release
  126. # events. To specify what part of the front panel to look at, the "part"
  127. # parameter can be set to: "any" (i.e. the default), "POWER_BUTTON",
  128. # "COLOR_BUTTON" or "SLIDER".
  129. binary_sensor:
  130. # When tapping the power button, toggle the light.
  131. # When holding the power button, turn on night light mode.
  132. - platform: xiaomi_bslamp2
  133. id: ${id_power_button}
  134. part: POWER_BUTTON
  135. on_multi_click:
  136. - timing:
  137. - ON for at most 0.8s
  138. then:
  139. - light.toggle: ${id_light}
  140. - timing:
  141. - ON for at least 0.8s
  142. then:
  143. - light.turn_on:
  144. id: ${id_light}
  145. red: 1
  146. green: 1
  147. blue: 1
  148. brightness: 0.01
  149. # When tapping the color button, acivate the next preset.
  150. # When holding the color button, activate the next preset group.
  151. - platform: xiaomi_bslamp2
  152. id: ${id_color_button}
  153. part: COLOR_BUTTON
  154. on_multi_click:
  155. - timing:
  156. - ON for at most 0.6s
  157. then:
  158. - preset.activate:
  159. next: preset
  160. - timing:
  161. - ON for at least 0.6s
  162. then:
  163. - preset.activate:
  164. next: group
  165. # This sensor component publishes touch events for the front panel slider.
  166. # The published value represents the level at which the slider was touched.
  167. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  168. # be modified using the "range_from" and "range_to" parameters.
  169. sensor:
  170. # When the slider is touched, update the brightness.
  171. # Brightness 0.01 initiates the light night mode, which has already
  172. # been handled above (by holding the power button). Therefore, brightness
  173. # starts from 0.02 here, to not trigger night mode using the slider.
  174. - platform: xiaomi_bslamp2
  175. id: ${id_slider_level}
  176. range_from: 0.02
  177. on_value:
  178. then:
  179. - light.turn_on:
  180. id: ${id_light}
  181. brightness: !lambda return x;