Understand this could be asked before but i couldn’t find a solutions through all the searches.
Assume I wish to set the 3 blinds each at specific position using a string such as ‘30,60,80’, how can i convert the following e fix service calls into a loop script / automation:-
Yes. I’m thinking of passing to the script either using a string variables or input_text. My intention is to have different modes defined in an input_select and when a particular input_select is selected, it will pass a particular set of blind positions to the script.
Taras, thanks for the great help. I tested on the developer service tools and it works perfectly as what i wanted… one more thing to trouble you, below is the calling automation which doesn’t seems to activate the different input select mode as required, can you spot any mistakes there ?
I suggest the script use a dictionary called blinds. The dictionary’s keys corresponds to the input_select’s options. Each key’s value is a list containing the blind positions.
So if the input_select’s value changes to ‘afternoon’, its corresponding value, [10,10,10] is assigned to the script variable blind_pos. If for some reson the input_select’s value is not found in the blinds dictionary, it will assign [50,50,50] to blind_pos (as a way for you to detect an error has occurred).
Because you can pass a list value to the script, instead of a string, the script doesn’t need to convert it to a list so we can eliminate one line of code.
Thanks so much… is been a great help from you, always.
Just curious, i tested out my old ‘if…elif…endif’ templates using list instead but still not working… I have another routine i am using this template structure and it is not working either… wonder if my syntax structure has any issue on that ?
Also, i have tried your syntax using string ( eg. ‘50,30,10’ ) instead of list, it doesn’t work either… does that means dictionary value must be list ?
Anyway, the whole procedure works perfectly using your syntax and i learn something new about dictionary and how to use ‘variables’ in the script… thanks also on highlighting the deprecated syntax.
Several versions ago, “native types” was implemented. That means a value’s type was no longer limited to string but could be list, integer, boolean, etc. This made passing a script variable more flexible because instead of the type being limited to just string it could now be another type.
Home Assistant determines a value’s type from its appearance. So 23.5 is handled as a float, 45 is int ,[23.5, 45] is a list but I believe it can also interpret 23.5, 45 as a list (or tuple), not a string, and perhaps that’s the issue that’s affecting your version of the template.
Can we put in a feature request for what kwaek suggested (service or other repeated calls within loops/conditionals). I know it’s not the “HA way of doing things” but it’s much more intuitive, shorter, readable, and self-contained.