Hi Guys!
I would like to use a single script to toggle Ikea Tradfri bulb.
I cannot set both brightness and color in a single call, so I use this script to turn on and configure a light:
toggle_ikea_light:
sequence:
# Check whether the light is off (optional)
- condition: template
value_template: "{{ is_state(entity, 'off') }}"
- delay: '00:00:01'
# Set the brightness of the lights.
- service: light.turn_on
data_template:
entity_id: "{{ entity }}"
brightness_pct: "{{ brightness_pct }}"
transition: 1
- delay: '00:00:01'
# Set the color temperature.
- service: light.turn_on
data_template:
entity_id: "{{ entity }}"
color_temp: "{{ color_temp }}"
transition: 5
# Check whether the light is on
- condition: template
value_template: "{{ is_state(entity, 'on') }}"
- service: light.turn_off
data_template:
entity_id: "{{ entity }}"
To simplify automations, I would like to turn off the bulb if it is ON when script is being called.
When I add another condition template in the end, with condition is_state==on, it is not being executed, as script exits on first condition.
How to configure “if” "&“else” in this script?
In next step I would like to automate color & brightness calculation based on time.
In the end, it should work like this:
- if light is on - turn it off
- if light is off and brightness & color is specified - turn it on and configure given parameters
- if light is off and brightness or color not specified - calculate not specified value, turn on the light and configure brightness & color.
It is my first script, so if there is any better method or more elegant way to achieve my goal - I would appreciate any suggestions.
Kind Regards