Created
September 26, 2023 10:08
-
-
Save cmsj/17707a60d08bee94e2d5b05eb7c973f9 to your computer and use it in GitHub Desktop.
A Home Assistant custom script for turning on zigbee lightbulbs in a less awful way than default.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hue_nicely: | |
alias: A Hue Nicely | |
mode: queued | |
fields: | |
bulbs: | |
name: Bulbs | |
description: Turn zigbee-connected Hue bulbs on smoothly | |
required: true | |
selector: | |
entity: | |
domain: light | |
multiple: true | |
color_temp: | |
name: Color Temperature | |
description: Color Temperature | |
selector: | |
color_temp: {} | |
color_rgb: | |
name: RGB Color | |
description: RGB Color | |
selector: | |
color_rgb: {} | |
brightness: | |
name: Brightness | |
description: Brightness percentage | |
selector: | |
number: | |
min: 0 | |
max: 100 | |
transition: | |
name: Transition | |
description: Time to transition to the new state | |
selector: | |
number: | |
min: 0 | |
max: 10000 | |
variables: | |
color_temp: '{{ color_temp|default("") }}' | |
color_rgb: '{{ color_rgb|default("") }}' | |
brightness: '{{ brightness|default("") }}' | |
transition: '{{ transition|default(0) }}' | |
light_pre_options: > | |
{% macro add_string(key, value) -%} | |
"{{ key }}":"{{ value }}", | |
{%- endmacro %} {% macro add_list(key, value) -%} | |
"{{ key }}": [{{ value|join(",") }}], | |
{%- endmacro %} | |
{% set option_dict = namespace(value="") %} | |
{% if color_rgb != "" %} | |
{% set option_dict.value = option_dict.value ~ add_list("rgb_color", color_rgb) %} | |
{% elif color_temp != "" %} | |
{% set option_dict.value = option_dict.value ~ add_string("color_temp", color_temp) %} | |
{% endif %} | |
{{ option_dict.value[:-1] }} | |
light_on_options: > | |
{% macro add_string(key, value) -%} | |
"{{ key }}":"{{ value }}", | |
{%- endmacro %} {% macro add_list(key, value) -%} | |
"{{ key }}": [{{ value|join(",") }}], | |
{%- endmacro %} | |
{% set option_dict = namespace(value="") %} | |
{% if brightness != "" %} | |
{% set option_dict.value = option_dict.value ~ add_string("brightness_pct", brightness) %} | |
{% endif %} | |
{% if color_rgb != "" %} | |
{% set option_dict.value = option_dict.value ~ add_list("rgb_color", color_rgb) %} | |
{% elif color_temp != "" %} | |
{% set option_dict.value = option_dict.value ~ add_string("color_temp", color_temp) %} | |
{% set option_dict.value = option_dict.value ~ add_string("transition", transition) %} | |
{% endif %} | |
{{ option_dict.value[:-1] }} | |
sequence: | |
- repeat: | |
for_each: '{{bulbs}}' | |
sequence: | |
- if: | |
- condition: template | |
value_template: '{{ is_state(repeat.item, "off") }}' | |
then: | |
- service: light.turn_on | |
data: | |
brightness: 2 | |
transition: 0 | |
target: | |
entity_id: '{{repeat.item}}' | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 0 | |
milliseconds: 200 | |
- service: light.turn_on | |
data: '{ {{ light_pre_options }}, "transition":0 }' | |
target: | |
entity_id: '{{repeat.item}}' | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 0 | |
milliseconds: 200 | |
- service: light.turn_on | |
data: '{ {{ light_on_options }}, "transition":0.2 }' | |
target: | |
entity_id: '{{repeat.item}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save that yaml file into your Home Assistant's
config
directory and then include it intoconfiguration.yaml
like this:Because the script specifies its input fields, it works with the visual editor: