Looking for a way to dynamically expand the service calls in a script sequence based on entities in a group. Simple example:
Assume a script named script1 exists which accepts one parameter named “entity”.
Assume a group named group1 exists which contains switch.s1, switch.s2, switch.s3.
Within an automation or a script, I’d like to be able to have the sequence of service calls be generated by a template so that there exists one service call to the script per member of the group. So, based on the description above, the template output would look like:
- service: script.script1
data:
entity: switch.s1
- service: script.script1
data:
entity: switch.s2
- service: script.script1
data:
entity: switch.s3
The goal is to be able to include / exclude items from the workflow just by adding or removing them from a group.
I’ve managed to put together jinja that will generate the above text using something like:
{% for e in states.group.group1 | expand -%}
but there doesn’t seem to be a valid way to embed this into an automation or script.
Any way to do this? (Asked on Discord and didn’t get any responses.)