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.

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