State trigger - entity_id wildcard

Hello,

I’m trying to set up an automation rule that triggers whenever any entity in a group changes. For example, I want to be able to watch the “all_lights” group for any of the lamps turning on, and take action on that.

Is this possible? As far as I understand, and according to my test results, setting a state trigger with entity_id=group.all_lights means that it only fires when all lights are on or off at the same time.

I think you might have to list all of the lights explicitely.
I haven’t tested it, but it could work like this:

trigger:
  platform: state
  entity_id:
    - light.light1
    - light.light2
    - light.light3
action:
  ...

I would like to do this also, so if you found a solution I would love to hear it! My use case is that I want to watch the state of all of my door/window sensors. If one changes to “on” (which is open), then I want to be notified… That part is easy as I can use the group.my_door_and_window_sensors.

My end goal though is using the group.my_door_and_window_sensors to be notified that sensor.this_one is the “on” one. (using a data_template of {{ trigger.to_state.attributes.friendly_name }}

As @sebk-666 stated, I can list them all out but that’s not as pretty, scalable, or something that I’ll remember to update when I add more!

I haven’t tried it, but this sounds like it’s quite easily doable with appdaemon using self.listen_state(self.state_change, "sensor").
Have a look at appdaemon if you haven’t already (you’ll probably find yourself using it sooner or later anyway ;)), especially the included switch_reset.py example app.

Sebastian

I managed by making the following trigger:

trigger:
    platform: event
    event_type: call_service
    event_data:
      domain: light
1 Like

For the record, I checked out AppDaemon and it solved my use case perfectly. @sebk-666 thank you for the advice!