Hi! I need to trigger my automation whenever a light group has a light added or removed, and also whenever one of those lights turns on.
If I create the automation from a blueprint with an group input, and a state trigger for that entity, then the automation gets triggered whenever the light is added or removed, so far so good.
I can get the automation to also trigger whenever a light is turned on by using a multiple input entity of domain “light”, but doing it this way means having to maintain the lights in the group, but also in the automation’s input list, not ideal.
I don’t think I can expand the group and create a trigger for each light in script (triggers seem static).
I don’t think it’s possible to have the automation trigger on any light at all turning on, and then use a condition to check if the light belongs in the group (I think the trigger requires an entity_id). Except if I manually list all the lights in a multiple light input and check for group membership in condition, this should probably work but then I need to remember to add any new lights to this automation’s input
If you want the automation to trigger when a specific light changes state, you have to explicitly specify the light’s entity_id in a State Trigger.
You can use an Event Trigger to detect state_changed events then, in condition, inspect the event’s data to see if the entity whose state changed is a member of the light group.
However, this approach is not recommended because the Event Trigger will trigger for every state-change that occurs for every entity in your system. In other words, it casts a very wide net to catch one little fish.
Got it working, thanks! I used a trigger on the group to get notified on new lights added to the group, and then on all state_changed events and filtering in a condition to only trigger on turn-on events for lights in the group.
It seemed like it might be possible to specify a filter for the state_changed events in the trigger using event_data, but the event data is like { "entity_id": ..., "new_state": { "state": "on", ... } }, and while event_data can filter by entity_id and other root members, it can’t drill into new_state since it only matches the complete { "state": "on", ... }, including all the extra members, so looks like not possible to filter by "new_state.state": "on". But condition works
If you’re building a blueprint that you intend to share with others, I recommend you warn them about how often the automation will trigger (namely when any entity in their system changes state). Good thing that an automation’s traces are limited to 10 by default because this automation will produce many traces.
I also trigger on state_changed and only filter in a condition, not ideal for sure I just learned about “domain.all”, maybe that’s a way to get triggered by any light in the system turning on (without listing them all explicitly), I’ll try it out next.