This is just for testing, I was expecting that my lights will start from red, then in each second a hue change happens, and after 10 steps I’d get back to red (in the real script this would be much slower and the increment would be much smaller).
My issue is that the hue variable seemingly gets incremented once, in the 1st iteration and even this hue change is not showing on my lightbulb; it stays red.
You have a hue variable defined before the repeat. The hue variable defined within the repeat, is not changing the value of the hue variable outside of the repeat. It’s effectively a separate variable.
Solved it. It is a bit disgusting, because I’m not familiar with variables and loops in HA, so the only way I could create an ‘infinite’ loop is by providing an absurdly big number (given the set delay) in the repeat count. I’m open to hear more elegant solutions.
Refer to the link I posted above for an explanation of variable scope. It applies not only to a variable used in a repeat but also to choose, if, etc.
index is one of the properties of the repeat loop variable present in every repeat loop style. Meaning it isn’t limited to just repeat count but is also available in others such as repeat until.
In other words, you can check the value of repeat.index in until (or while) and have it stop iterating when a certain value is reached (rather than using count with a large number).
For future reference, if you use float and the supplied value is non-numeric it will result in an error message. That’s unlikely to happen in this case because the result of the calculation will always be a number.
For cases where there’s a possibility that the result can be non-numeric, supply float with a default value. For example, float(0) will use 0.
Thank you for your answer! I’ll try these. Right now I’m trying to determine the threshold for the maximum hue increment which I do not perceive as an instantaneous color change, so I can set extended delays while keeping duration of a full cycle constant.
Does it have any added value to have fewer, longer delays rather than many short ones (I’m thinking about CPU utilization, etc.)? I’m not familiar with the underlying behaviour of HA. When a script is running and a delay is in place, the thread is put to sleep, right? So a running script won’t block HA from ‘listening to’ other triggers, or running other scripts, right?
Correct; a running script/automation doesn’t block anything else from running concurrently.
What you should be aware of is that any script/automation that is busy executing its actions (like waiting for a delay to expire or for something to happen in a wait_template or wait_for_trigger) is terminated when Home Assistant is restarted and doesn’t resume on startup from where it left off.
You may wish to consider creating a native Hue scene that cycles through all colors. In Home Assistant you would simply turn on the native scene and the bulb takes care of the rest. More efficient than sending a stream of discrete commands to change color.