Hello there,
I wrote my first automation+script recently. I want to turn some lights on at sunset and make them switch to random colors every seven seconds until I turn them off. The idea behind it is to take advantage of some ambience lights I have.
To achieve this I have this automation :
- id: 'XXX'
alias: Turn on the lights when the sun is set
description: ''
trigger:
- platform: sun
event: sunset
condition: []
action:
- service: script.turn_on
entity_id: script.light_colorful
data:
variables:
light_id: light.light1
- service: script.turn_on
entity_id: script.light_colorful
data:
variables:
light_id: light.light2
mode: single
The script called is this :
light_colorful:
alias: light_colorful
description: Set a light to colorful.
fields:
light_id:
description: The id of the light to set to colorful.
example: light.light1
variables:
light: '{{ entity_id }}'
sequence:
- repeat:
until:
- condition: template
value_template: "{{ is_state(light, 'off') }}"
sequence:
- service: light.turn_on
data_template:
entity_id: '{{ light_id }}'
rgb_color:
- '{{ (range(0, 255)|random) }}'
- '{{ (range(0, 255)|random) }}'
- '{{ (range(0, 255)|random) }}'
brightness_pct: 100
transition: 1
- delay: '7'
mode: parallel
max: 10
The problem I have is the “until” condition template that doesn’t trigger. Whenever I turn off one of these lights using the dashboard, it gets turned on again a few seconds after.
I observed the {{ is_state(light, 'off') }}
in the developer tools and I can see it return “true” before the light turns on again.
Any help to get that exit condition working would be greatly appreciated