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.

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