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.

176 lines
5.7 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. # Some derived identifiers for the device components.
  9. id_light: ${name}
  10. id_front_panel_light: ${name}_front_panel_light
  11. id_front_panel_output: ${name}_front_panel_output
  12. id_power_button: ${name}_power_button
  13. id_color_button: ${name}_color_button
  14. id_slider_level: ${name}_slider_level
  15. id_light_mode: ${name}_light_mode
  16. # --------------------------------------------------------------------------
  17. # Use your own preferences for these components.
  18. # --------------------------------------------------------------------------
  19. wifi:
  20. ssid: "Your-SSID"
  21. password: "Your-Password"
  22. use_address: 192.168.10.12
  23. # Enable fallback hotspot (for captive portal) in case wifi connection fails
  24. ap:
  25. ssid: "ESPHome $friendly_name"
  26. password: "bedside2021"
  27. captive_portal:
  28. api:
  29. ota:
  30. logger:
  31. # --------------------------------------------------------------------------
  32. # Configuration specific for the Yeelight Bedside Lamp 2.
  33. # --------------------------------------------------------------------------
  34. # Special platform + package are used for enabling unicore and disabling the
  35. # efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
  36. # chip that is used in the device.
  37. esphome:
  38. name: ${name}
  39. platform: ESP32
  40. board: esp32doit-devkit-v1
  41. platformio_options:
  42. platform: espressif32@3.2.0
  43. platform_packages: |-4
  44. framework-arduinoespressif32 @ https://github.com/pauln/arduino-esp32.git#solo-no-mac-crc/1.0.6
  45. light:
  46. # This component controls the LED lights of the device.
  47. - platform: yeelight_bs2
  48. id: ${id_light}
  49. name: ${friendly_name} RGBW Light
  50. default_transition_length: ${transition_length}
  51. # When the brightness is changed, then update the level indication
  52. # on the front panel accordingly. In night light mode, turn off
  53. # the front panel illumination.
  54. on_brightness:
  55. then:
  56. - output.set_level:
  57. id: ${id_front_panel_output}
  58. level: !lambda if (x < 0.012f) return 0; else return x;
  59. # You can use any effects that you like. These are just examples.
  60. effects:
  61. - random:
  62. name: "Slow Random"
  63. transition_length: 30s
  64. update_interval: 30s
  65. - random:
  66. name: "Fast Random"
  67. transition_length: 3s
  68. update_interval: 3s
  69. # A fun thing you could do with the front panel output component
  70. # (as defined below): wrap it in a light component, so you can
  71. # treat the front panel illumination as a monochromatic light
  72. # from within Home Assitant.
  73. # This is primarily a demo. It's barely useful for a device that
  74. # one has running in production.
  75. - platform: monochromatic
  76. name: $friendly_name Front Panel Light
  77. id: ${id_front_panel_light}
  78. output: ${id_front_panel_output}
  79. default_transition_length: 0s
  80. gamma_correct: 1
  81. effects:
  82. - lambda:
  83. name: Random Level
  84. update_interval: 150ms
  85. lambda: |-
  86. auto call = id(${id_front_panel_light}).turn_on();
  87. call.set_transition_length(150);
  88. call.set_brightness(random_float());
  89. call.perform();
  90. # This text sensor propagates the currently active light mode.
  91. # The possible light modes are: "off", "rgb", "white" and "night".
  92. text_sensor:
  93. - platform: yeelight_bs2
  94. name: ${name} Light Mode
  95. id: ${id_light_mode}
  96. # This output controls the front panel illumination + level indication.
  97. # Value 0.0 turns off the illumination.
  98. # Other values (up to 1.0) turn on the illumination and set the level
  99. # indication to the requested level.
  100. output:
  101. - platform: yeelight_bs2
  102. id: ${id_front_panel_output}
  103. # Binary sensors can be created for handling front panel touch / release
  104. # events. To specify what part of the front panel to look at, the "part"
  105. # parameter can be set to: "any" (i.e. the default), "power button",
  106. # "color button" or "slider".
  107. binary_sensor:
  108. # When touching the power button, toggle the light.
  109. # When holding the power button, turn on night light mode.
  110. - platform: yeelight_bs2
  111. id: ${id_power_button}
  112. part: power button
  113. on_multi_click:
  114. - timing:
  115. - ON for at most 0.8s
  116. then:
  117. - light.toggle: ${id_light}
  118. - timing:
  119. - ON for at least 0.8s
  120. then:
  121. - light.turn_on:
  122. id: ${id_light}
  123. red: 1
  124. green: 1
  125. blue: 1
  126. brightness: 0.01
  127. # When touching the color button, set a random color.
  128. - platform: yeelight_bs2
  129. id: ${id_color_button}
  130. part: color button
  131. on_multi_click:
  132. - timing:
  133. - ON for at most 0.8s
  134. then:
  135. - light.turn_on:
  136. id: ${id_light}
  137. red: !lambda return random_float();
  138. green: !lambda return random_float();
  139. blue: !lambda return random_float();
  140. # This sensor component publishes touch events for the front panel slider.
  141. # The published value represents the level at which the slider was touched.
  142. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  143. # be modified using the "range_from" and "range_to" parameters.
  144. sensor:
  145. # When the slider is touched, update the brightness.
  146. # Brightness 0.01 initiates the light night mode, which has already
  147. # been handled above. Therefore, brightness starts from 0.02 here,
  148. # so night mode is not triggered from the slider.
  149. - platform: yeelight_bs2
  150. id: ${id_slider_level}
  151. range_from: 0.02
  152. on_value:
  153. then:
  154. - light.turn_on:
  155. id: ${id_light}
  156. brightness: !lambda return x;