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.

163 lines
5.7 KiB

  1. # A global variable to keep track of the brightness level. This one is
  2. # used by the update_front_panel script to represent the brightness level
  3. # using the front panel illumination.
  4. #
  5. # This variable is used instead of querying the light component directly,
  6. # because that brightness level may vary during a light transition. The
  7. # behavior that I want: when you touch the front panel slider at 75%, then
  8. # the illumination rises directly to that level, while the light might do
  9. # a smooth transition.
  10. globals:
  11. - id: current_brightness
  12. type: float
  13. initial_value: "0.0"
  14. # This script updates the front panel illumination.
  15. script:
  16. - id: update_front_panel
  17. mode: restart
  18. then:
  19. - front_panel.turn_off_leds: ALL
  20. # In rgb or white light mode, turn on the front panel illumination,
  21. # and show the current brightness level.
  22. - if:
  23. condition:
  24. or:
  25. - text_sensor.state:
  26. id: my_light_mode
  27. state: rgb
  28. - text_sensor.state:
  29. id: my_light_mode
  30. state: white
  31. then:
  32. - front_panel.turn_on_leds: [ POWER, COLOR ]
  33. - front_panel.set_level: !lambda return id(current_brightness);
  34. # In night light mode, turn off the front panel illumination, except
  35. # for the power button.
  36. - if:
  37. condition:
  38. - text_sensor.state:
  39. id: my_light_mode
  40. state: night
  41. then:
  42. - front_panel.turn_on_leds: [ POWER ]
  43. - front_panel.update_leds:
  44. # This component controls the LED lights of the lamp.
  45. light:
  46. - platform: xiaomi_bslamp2
  47. id: my_light
  48. name: ${light_name}
  49. default_transition_length: ${default_transition_length}
  50. # When the brightness changes, update the front panel illumination.
  51. on_brightness:
  52. then:
  53. - globals.set:
  54. id: current_brightness
  55. value: !lambda return x;
  56. - script.execute: update_front_panel
  57. # You can use any effects that you like. These are just examples.
  58. effects:
  59. - random:
  60. name: "Slow Random"
  61. transition_length: 30s
  62. update_interval: 30s
  63. - random:
  64. name: "Fast Random"
  65. transition_length: 3s
  66. update_interval: 3s
  67. # You can define one or more groups of presets. These presets can
  68. # be activated using various "preset.activate" action options.
  69. # The presets can for example be used to mimic the behavior of the
  70. # original firmware (tapping the color button = go to next preset,
  71. # holding the color button = switch between RGB and white light mode).
  72. # These bindings have been setup below, using the binary_sensor for
  73. # the color button.
  74. presets:
  75. rgb:
  76. red: { red: 100%, green: 0%, blue: 0% }
  77. green: { red: 0%, green: 100%, blue: 0% }
  78. blue: { red: 0%, green: 0%, blue: 100% }
  79. yellow: { red: 100%, green: 100%, blue: 0% }
  80. purple: { red: 100%, green: 0%, blue: 100% }
  81. randomize: { effect: Fast Random }
  82. white:
  83. cold: { color_temperature: 153 mireds }
  84. chilly: { color_temperature: 275 mireds }
  85. luke: { color_temperature: 400 mireds }
  86. warm: { color_temperature: 588 mireds }
  87. # This text sensor propagates the currently active light mode.
  88. # The possible light modes are: "off", "rgb", "white" and "night".
  89. text_sensor:
  90. - platform: xiaomi_bslamp2
  91. name: ${light_mode_text_sensor_name}
  92. id: my_light_mode
  93. # This float output can be used to control the front panel illumination +
  94. # level indicator LEDs. Value 0.0 turns off the illumination. Other values
  95. # (up to 1.0) turn on the illumination and set the level indicator to the
  96. # requested level.
  97. output:
  98. - platform: xiaomi_bslamp2
  99. id: my_front_panel_illumination
  100. # Binary sensors can be created for handling front panel touch / release
  101. # events. To specify what part of the front panel to look at, the "for"
  102. # parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
  103. binary_sensor:
  104. # When tapping the power button, toggle the light.
  105. # When holding the power button, turn on night light mode.
  106. - platform: xiaomi_bslamp2
  107. id: my_power_button
  108. for: POWER_BUTTON
  109. on_multi_click:
  110. - timing:
  111. - ON for at most 0.8s
  112. then:
  113. - light.toggle: my_light
  114. - timing:
  115. - ON for at least 0.8s
  116. then:
  117. - light.turn_on:
  118. id: my_light
  119. brightness: 1%
  120. # When tapping the color button, activate the next preset.
  121. # When holding the color button, activate the next preset group.
  122. - platform: xiaomi_bslamp2
  123. id: my_color_button
  124. for: COLOR_BUTTON
  125. on_multi_click:
  126. - timing:
  127. - ON for at most 0.6s
  128. then:
  129. - preset.activate:
  130. next: preset
  131. - timing:
  132. - ON for at least 0.6s
  133. then:
  134. - preset.activate:
  135. next: group
  136. # This sensor component publishes touch events for the front panel slider.
  137. # The published value represents the level at which the slider was touched.
  138. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  139. # be modified using the "range_from" and "range_to" parameters.
  140. sensor:
  141. # When the slider is touched, update the brightness.
  142. # Brightness 0.01 initiates the light night mode, which has already
  143. # been handled above (by holding the power button). Therefore, brightness
  144. # starts from 0.02 here, to not trigger night mode using the slider.
  145. - platform: xiaomi_bslamp2
  146. id: my_slider_level
  147. range_from: 0.02
  148. on_value:
  149. then:
  150. - light.turn_on:
  151. id: my_light
  152. brightness: !lambda return x;