Get group member info on group state change

I have a binary sensor group helper, and its members are other binary sensors. Its set to all entities, which means its only on in the event all members are also on.

These binary sensors represent the status of wifi connected devices around the house.
I currently have a notification sent out when the helper goes from on to off, but id like to be able to extract what device triggered that ?

The logbook contains that info – is there any way to extract that and use it as part of the notification ?

example, only in this case it went from off to on

TLDR; rather than saying hey sometihng is wrong when a helper sensor changes state, can i get more specific as to what triggered that state change and send it as part of the notification?

Try this:

{{ expand('binary_sensor.your_group_sensor') | selectattr('state', 'eq', 'off') | map(attribute='entity_id') | list }}

This is nit showing the entity triggering the change on your group binary sensor, but will list all the entities in that group that are currently off.

thats a good idea – close enough to what im trying to do and will give more or less the same outcome.

Thanks!

1 Like

Well, you can improve that to show in the reverse order it last changed:

{{ expand('light.home_all_lights') 
| selectattr('state', 'eq', 'off') 
| sort(attribute='last_changed', reverse = True)
| map(attribute='entity_id') | list }}

And then you can select only the first element from the list, which is the last one changed to off:

{{ (expand('light.home_all_lights') 
| selectattr('state', 'eq', 'off') 
| sort(attribute='last_changed', reverse = True)
| map(attribute='entity_id') | list)[0]}}
  • Please replace my all lights group to your binary_sensor group.

This is not the same as the one triggering the change if state of your group but probably will reach your goal. If not, please share your goal… :wink:

1 Like

Yep.
Its a different goal / way to get the same information.

Ultimately i want to get alerted that when something in that group goes offline, with the specific device thats offline. This does exactly that.