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.

183 lines
6.1 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. presets:
  86. - rgb:
  87. - red_bright: { red: 100% }
  88. - green: { green: 100% }
  89. - blue_dimmed: { blue: 100% }
  90. - yellow: { red: 100%, green: 100% }
  91. - purple: { red: 100%, blue: 100% }
  92. - white:
  93. - cold: { color_temperature: 153 }
  94. - chilly: { color_temperature: 275 }
  95. - luke: { color_temperature: 400 }
  96. - warm: { color_temperature: 587 }
  97. # This text sensor propagates the currently active light mode.
  98. # The possible light modes are: "off", "rgb", "white" and "night".
  99. text_sensor:
  100. - platform: xiaomi_bslamp2
  101. name: ${name} Light Mode
  102. id: ${id_light_mode}
  103. # This output controls the front panel illumination + level indication.
  104. # Value 0.0 turns off the illumination.
  105. # Other values (up to 1.0) turn on the illumination and set the level
  106. # indication to the requested level.
  107. output:
  108. - platform: xiaomi_bslamp2
  109. id: ${id_front_panel_output}
  110. # Binary sensors can be created for handling front panel touch / release
  111. # events. To specify what part of the front panel to look at, the "part"
  112. # parameter can be set to: "any" (i.e. the default), "power button",
  113. # "color button" or "slider".
  114. binary_sensor:
  115. # When touching the power button, toggle the light.
  116. # When holding the power button, turn on night light mode.
  117. - platform: xiaomi_bslamp2
  118. id: ${id_power_button}
  119. part: power button
  120. on_multi_click:
  121. - timing:
  122. - ON for at most 0.8s
  123. then:
  124. - light.toggle: ${id_light}
  125. - timing:
  126. - ON for at least 0.8s
  127. then:
  128. - light.turn_on:
  129. id: ${id_light}
  130. red: 1
  131. green: 1
  132. blue: 1
  133. brightness: 0.01
  134. # When touching the color button, set a random color.
  135. - platform: xiaomi_bslamp2
  136. id: ${id_color_button}
  137. part: color button
  138. on_multi_click:
  139. - timing:
  140. - ON for at most 0.6s
  141. then:
  142. - preset.activate:
  143. next: preset
  144. - timing:
  145. - ON for at least 0.6s
  146. then:
  147. - preset.activate:
  148. next: group
  149. # This sensor component publishes touch events for the front panel slider.
  150. # The published value represents the level at which the slider was touched.
  151. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  152. # be modified using the "range_from" and "range_to" parameters.
  153. sensor:
  154. # When the slider is touched, update the brightness.
  155. # Brightness 0.01 initiates the light night mode, which has already
  156. # been handled above. Therefore, brightness starts from 0.02 here,
  157. # so night mode is not triggered from the slider.
  158. - platform: xiaomi_bslamp2
  159. id: ${id_slider_level}
  160. range_from: 0.02
  161. on_value:
  162. then:
  163. - light.turn_on:
  164. id: ${id_light}
  165. brightness: !lambda return x;