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