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.

168 lines
6.1 KiB

  1. # ------------------------------------------------------------------------
  2. # Behavior: default
  3. #
  4. # * Presets that resemble the original Xiaomi firmware
  5. # (one group of RGB colors, one group of white light colors)
  6. # * Tapping the power button, toggles the light
  7. # * Holding the power button, turns on night light mode
  8. # * Tapping the color button, activates the next preset
  9. # * Holding the color button, activates the next preset group
  10. # * Touching the slider sets the brightness level and turns on the lamp
  11. # * When the light is on, the front panel illumination is on
  12. # * When the night light is on, only the power button is illuminated
  13. # ------------------------------------------------------------------------
  14. # A global variable to keep track of the brightness level. This one is
  15. # used by the update_front_panel script to represent the brightness level
  16. # using the front panel illumination.
  17. #
  18. # This variable is used instead of querying the light component directly,
  19. # because that brightness level may vary during a light transition. The
  20. # behavior that I want: when you touch the front panel slider at 75%, then
  21. # the illumination rises directly to that level, while the light might do
  22. # a smooth transition.
  23. globals:
  24. - id: current_brightness
  25. type: float
  26. initial_value: "0.0"
  27. # This script updates the front panel illumination.
  28. script:
  29. - id: update_front_panel
  30. mode: restart
  31. then:
  32. - front_panel.turn_off_leds: ALL
  33. # In rgb or white light mode, turn on the front panel illumination,
  34. # and show the current brightness level.
  35. - if:
  36. condition:
  37. or:
  38. - text_sensor.state:
  39. id: my_light_mode
  40. state: rgb
  41. - text_sensor.state:
  42. id: my_light_mode
  43. state: white
  44. then:
  45. - front_panel.turn_on_leds: [ POWER, COLOR ]
  46. - front_panel.set_level: !lambda return id(current_brightness);
  47. # In night light mode, turn off the front panel illumination, except
  48. # for the power button.
  49. - if:
  50. condition:
  51. - text_sensor.state:
  52. id: my_light_mode
  53. state: night
  54. then:
  55. - front_panel.turn_on_leds: [ POWER ]
  56. - front_panel.update_leds:
  57. # This component controls the LED lights of the lamp.
  58. light:
  59. - platform: xiaomi_bslamp2
  60. id: my_light
  61. name: ${light_name}
  62. default_transition_length: ${default_transition_length}
  63. # When the brightness changes, update the front panel illumination.
  64. on_brightness:
  65. then:
  66. - globals.set:
  67. id: current_brightness
  68. value: !lambda return x;
  69. - script.execute: update_front_panel
  70. # You can use any effects that you like. These are just examples.
  71. effects:
  72. - random:
  73. name: "Slow Random"
  74. transition_length: 30s
  75. update_interval: 30s
  76. - random:
  77. name: "Fast Random"
  78. transition_length: 3s
  79. update_interval: 3s
  80. # You can define one or more groups of presets. These presets can
  81. # be activated using various "preset.activate" action options.
  82. # The presets can for example be used to mimic the behavior of the
  83. # original firmware (tapping the color button = go to next preset,
  84. # holding the color button = switch between RGB and white light mode).
  85. # These bindings have been setup below, using the binary_sensor for
  86. # the color button.
  87. # presets:
  88. # rgb:
  89. # red: { red: 100%, green: 0%, blue: 0% }
  90. # green: { red: 0%, green: 100%, blue: 0% }
  91. # blue: { red: 0%, green: 0%, blue: 100% }
  92. # yellow: { red: 100%, green: 100%, blue: 0% }
  93. # purple: { red: 100%, green: 0%, blue: 100% }
  94. # randomize: { effect: Fast Random }
  95. # white:
  96. # cold: { color_temperature: 153 mireds }
  97. # chilly: { color_temperature: 275 mireds }
  98. # luke: { color_temperature: 400 mireds }
  99. # warm: { color_temperature: 588 mireds }
  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;
  153. # This text sensor propagates the currently active light mode.
  154. # The possible light modes are: "off", "rgb", "white" and "night".
  155. text_sensor:
  156. - platform: xiaomi_bslamp2
  157. name: ${light_mode_text_sensor_name}
  158. id: my_light_mode