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.

194 lines
6.9 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. ota:
  29. password: "Password-For-Flashing-This-Device-Over-The-Air"
  30. # The log level can be raised when needed for debugging the firmware. For
  31. # production, a low log level is recommended. Mainly because high volume log
  32. # output might interfere with the API/WiFi connection stability. So when
  33. # raising the log level, beware that you might see dropped connections from
  34. # 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 lamp.
  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. # This component controls the LED lights of the lamp.
  53. light:
  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 indicator
  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_illumination}
  70. level: 0
  71. else:
  72. - output.set_level:
  73. id: ${id_front_panel_illumination}
  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. # By setting the name, the text_sensor will show up as an entity
  108. # for the lamp in Home Assistant.
  109. text_sensor:
  110. - platform: xiaomi_bslamp2
  111. name: ${name} Light Mode
  112. id: ${id_light_mode}
  113. # This float output controls the front panel illumination + level indicator.
  114. # Value 0.0 turns off the illumination.
  115. # Other values (up to 1.0) turn on the illumination and set the level
  116. # indicator to the requested level.
  117. output:
  118. - platform: xiaomi_bslamp2
  119. id: ${id_front_panel_illumination}
  120. # Binary sensors can be created for handling front panel touch / release
  121. # events. To specify what part of the front panel to look at, the "part"
  122. # parameter can be set to: "any" (i.e. the default), "power button",
  123. # "color button" or "slider".
  124. binary_sensor:
  125. # When tapping the power button, toggle the light.
  126. # When holding the power button, turn on night light mode.
  127. - platform: xiaomi_bslamp2
  128. id: ${id_power_button}
  129. part: power button
  130. on_multi_click:
  131. - timing:
  132. - ON for at most 0.8s
  133. then:
  134. - light.toggle: ${id_light}
  135. - timing:
  136. - ON for at least 0.8s
  137. then:
  138. - light.turn_on:
  139. id: ${id_light}
  140. red: 1
  141. green: 1
  142. blue: 1
  143. brightness: 0.01
  144. # When tapping the color button, acivate the next preset.
  145. # When holding the color button, activate the next preset group.
  146. - platform: xiaomi_bslamp2
  147. id: ${id_color_button}
  148. part: color button
  149. on_multi_click:
  150. - timing:
  151. - ON for at most 0.6s
  152. then:
  153. - preset.activate:
  154. next: preset
  155. - timing:
  156. - ON for at least 0.6s
  157. then:
  158. - preset.activate:
  159. next: group
  160. # This sensor component publishes touch events for the front panel slider.
  161. # The published value represents the level at which the slider was touched.
  162. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  163. # be modified using the "range_from" and "range_to" parameters.
  164. sensor:
  165. # When the slider is touched, update the brightness.
  166. # Brightness 0.01 initiates the light night mode, which has already
  167. # been handled above (by holding the power button). Therefore, brightness
  168. # starts from 0.02 here, to not trigger night mode using the slider.
  169. - platform: xiaomi_bslamp2
  170. id: ${id_slider_level}
  171. range_from: 0.02
  172. on_value:
  173. then:
  174. - light.turn_on:
  175. id: ${id_light}
  176. brightness: !lambda return x;