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.

154 lines
5.4 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. # Binary sensors can be created for handling front panel touch / release
  88. # events. To specify what part of the front panel to look at, the "for"
  89. # parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
  90. binary_sensor:
  91. # When tapping the power button, toggle the light.
  92. # When holding the power button, turn on night light mode.
  93. - platform: xiaomi_bslamp2
  94. id: my_power_button
  95. for: POWER_BUTTON
  96. on_multi_click:
  97. - timing:
  98. - ON for at most 0.8s
  99. then:
  100. - light.toggle: my_light
  101. - timing:
  102. - ON for at least 0.8s
  103. then:
  104. - light.turn_on:
  105. id: my_light
  106. brightness: 1%
  107. # When tapping the color button, activate the next preset.
  108. # When holding the color button, activate the next preset group.
  109. - platform: xiaomi_bslamp2
  110. id: my_color_button
  111. for: COLOR_BUTTON
  112. on_multi_click:
  113. - timing:
  114. - ON for at most 0.6s
  115. then:
  116. - preset.activate:
  117. next: preset
  118. - timing:
  119. - ON for at least 0.6s
  120. then:
  121. - preset.activate:
  122. next: group
  123. # This sensor component publishes touch events for the front panel slider.
  124. # The published value represents the level at which the slider was touched.
  125. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  126. # be modified using the "range_from" and "range_to" parameters.
  127. sensor:
  128. # When the slider is touched, update the brightness.
  129. # Brightness 0.01 initiates the light night mode, which has already
  130. # been handled above (by holding the power button). Therefore, brightness
  131. # starts from 0.02 here, to not trigger night mode using the slider.
  132. - platform: xiaomi_bslamp2
  133. id: my_slider_level
  134. range_from: 0.02
  135. on_value:
  136. then:
  137. - light.turn_on:
  138. id: my_light
  139. brightness: !lambda return x;
  140. # This text sensor propagates the currently active light mode.
  141. # The possible light modes are: "off", "rgb", "white" and "night".
  142. text_sensor:
  143. - platform: xiaomi_bslamp2
  144. name: ${light_mode_text_sensor_name}
  145. id: my_light_mode