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.

169 lines
6.2 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. pink: { red: 59%, green: 30%, blue: 77% }
  90. lpink: { red: 96%, green: 49%, blue: 73% }
  91. purple: { red: 37%, green: 30%, blue: 67% }
  92. magenta: { red: 59%, green: 30%, blue: 77% }
  93. purple2: { red: 41%, green: 32%, blue: 52% }
  94. lpurple: { red: 58%, green: 40%, blue: 58% }
  95. randomize: { effect: Fast Random }
  96. white:
  97. cold: { color_temperature: 153 mireds }
  98. chilly: { color_temperature: 275 mireds }
  99. luke: { color_temperature: 400 mireds }
  100. warm: { color_temperature: 588 mireds }
  101. # Binary sensors can be created for handling front panel touch / release
  102. # events. To specify what part of the front panel to look at, the "for"
  103. # parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
  104. binary_sensor:
  105. # When tapping the power button, toggle the light.
  106. # When holding the power button, turn on night light mode.
  107. - platform: xiaomi_bslamp2
  108. id: my_power_button
  109. for: POWER_BUTTON
  110. on_multi_click:
  111. - timing:
  112. - ON for at most 0.8s
  113. then:
  114. - light.toggle: my_light
  115. - timing:
  116. - ON for at least 0.8s
  117. then:
  118. - light.turn_on:
  119. id: my_light
  120. brightness: 1%
  121. # When tapping the color button, activate the next preset.
  122. # When holding the color button, activate the next preset group.
  123. - platform: xiaomi_bslamp2
  124. id: my_color_button
  125. for: COLOR_BUTTON
  126. on_multi_click:
  127. - timing:
  128. - ON for at most 0.6s
  129. then:
  130. - preset.activate:
  131. next: preset
  132. - timing:
  133. - ON for at least 0.6s
  134. then:
  135. - preset.activate:
  136. next: group
  137. # This sensor component publishes touch events for the front panel slider.
  138. # The published value represents the level at which the slider was touched.
  139. # By default, values range from 0.01 to 1.00 (in 20 steps). This range can
  140. # be modified using the "range_from" and "range_to" parameters.
  141. sensor:
  142. # When the slider is touched, update the brightness.
  143. # Brightness 0.01 initiates the light night mode, which has already
  144. # been handled above (by holding the power button). Therefore, brightness
  145. # starts from 0.02 here, to not trigger night mode using the slider.
  146. - platform: xiaomi_bslamp2
  147. id: my_slider_level
  148. range_from: 0.02
  149. on_value:
  150. then:
  151. - light.turn_on:
  152. id: my_light
  153. brightness: !lambda return x;
  154. # This text sensor propagates the currently active light mode.
  155. # The possible light modes are: "off", "rgb", "white" and "night".
  156. text_sensor:
  157. - platform: xiaomi_bslamp2
  158. name: ${light_mode_text_sensor_name}
  159. id: my_light_mode