Hi,
I would like to implement a script that would be called it in my automations for any of my media player entities and:
Pass each time affected entity to my script - what was easy, so I have already manged it.
In the script I would like to test the state of the passed entity and act corresponding to the result. I have found no way yet how to test the sate of an entity I passed to my script, in the script. There is a field selection “state”, but it needs necessarily a concrete entity ID and I do not know how to deal with this challenge.
I hope someone can help me with a solution for my point 2.
This reads like you are creating the script via the UI. Might be easier with YAML, or at least in YAML mode in the UI. I suspect you’ll end up with some template fields.
Give an example of what you’ve tried so far with the passed-in entity (presumably an ID?), pasted as properly-formatted YAML that should look like this:
We are now watching Wimbledon (tennis), so I can test repeated calls of my example script later. Do you mean a second call immediately after the first one or after a while?
BTW: The “Fields” declaration provides a flag called “multiple”, I assume with this flag it would be possible to implement a script, lets call it “stopEntities”, in order to manage multiple entities in a loop, e.g.: “while”, “until”, entity[index] != “null” … or something similar.
In this context I tried by myself to find answers to some questions , but was not really successful. Would you have any tips/suggestion/ideas in questions:
1, If the multiple variables (passed to a script) are provided in “script” in form of an indexed table? E.g. entity[max_index+1] while index range is from 0 to max_index - is the range actually correct?
2. If “script” provides an internal variable/parameter like number of passed variables? I mean one that could be used e.g. in a repeat/while loop. Introducing of an additional “fields” variable, lets call it “numberOfEntifies”, would be an alternative.
3. Or if the condition “entity[any index] != null” would be a proper criteria for reaching the last variable, passed to “script”.