I use the following script to cycle through some different colours on an RGB strip and a separate RGB bulb to give a nice effect as I walk into a room.
This is the script:
alias: Colour Loop Lights
variables:
colours: |-
{{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],
[0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],
[0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],
[0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],
[0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],
[0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116]] }}
startingseed: "{{range(0,(colours | count)-1) | random}}"
sequence:
- repeat:
count: "{{ counter if counter is defined else 20 }}"
sequence:
- service: light.turn_on
data_template:
xy_color: "{{ colours[((startingseed+repeat.index) % (colours | count))] }}"
transition: "{{ transition if transition is defined else 1 }}"
target:
entity_id: >-
{{ targetid if targetid is defined else
'light.kitchen_light_group' }}
- wait_template: >
{{ state_attr(targetid,'xy_color')| list ==
colours[((startingseed+repeat.index) % (colours | count))] }}
continue_on_timeout: true
timeout: "1"
mode: single
When run against the RGB bulb, it executes much faster as the bulb doesn’t seem to respect the transition value, completing every step in 2.01 seconds. Visually, it looks like the bulb is skipping some colours, rather than transitioning very quickly.
Now I run the same script targetting the RGB LED strip and it runs in 6.25 seconds, with a much nicer transition appearance.
However, given a repeat count of 10, and a transition time of 1 for each light turn on, I would expect both runs to take about 10 seconds to complete.
I tried to ‘even out’ the timings of both runs by making the entity wait to confirm the light was at its correct colour, but that didnt seem to do anything.
Any thoughts on how to make both lights execute as I would expect ? I thought about putting a 1 second delay in the loop, but that seems like a hack.