I’m learning to make my own scripts and I have this one script (the contents of which I will apply to other blueprints and scripts I’m currently working on), see below.
As you might see, I want the lights to turn on at 50% brightness and 3500K and gradually brighten over a span of 10 minutes to 5000K and 85%.
I also want to be able to change the brightness or color temperature manually, which will stop the script from running (not for this script necessarily, but it’s the simpelest to show my issue).
I added a condition that is supposed to check if the context of an entity was changed by something other than this automation, and if true, the scipt stops looping and keeps its brightness on the brightness/temperature that were set.
However, this condition is messing up my script and having it stuck at 50% brightness and 3500K temperature.
I read somewhere on this forum that a context condition could be added to an automation to recognize ‘manual’ state changes.
Hope someone can help me out!
Unless you’re going to do something fancier than a linear fade, why use a loop at all? Just use two light.turn_on actions after each other with a transition parameter on the second.
If you insist on doing it with a manual loop, you cannot put the break condition inside the loop as that will only skip the current iteration and jump immediately to the next. You need to put your break conditions as part of until (or while) on the loop itself.
I do something similar in my alarm clock blueprint where I am slowly increasing the volume of a media player. If the volume at the beginning of each iteration is not what I expected it to be, i.e. someone has manually adjusted the volume, I break the loop.
context and user_id are not attributes of an entity. They are properties of an automation’s trigger variable.
To see what I mean, copy-paste your template condition into Developer Tools → Template and observe the result.
In addition, the first parameter for the state_attr() function must be a string or a variable containing a string. In your example, it contains an unquotedlight.keuken so Home Assistant handles it like a variable (not a string).