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.

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