Automation trigger on group state change notification template

I have several cameras that have a binary sensor “Connected/Disconnected”.
I created a helper group with all the camera ‘Connectivity’ entities and with “All entities” enabled that turns to Off if one of the cameras reports that it is disconnected. This is working well and I have an automation that sends an alert if it changes to Off.
Right now it just sends a general message but I’d like it to tell me which (one or many) are disconnected.

I thought this would work:

  message: >-
    BlueIris is reporting a connection issue with {{
    trigger.to_state.attributes.name }}

But it’s just giving me blank. The logbook of the helper group does show me what I want. I just want it in the notification.

Turned off triggered by state of Home Shop - East Connectivity was disconnected

10:28:46 PM - 3 minutes ago

Try the following:


{{ expand('binary_sensor.xyz') |selectattr('state', '==', 'off') |map(attribute='name') |join(',') }}

That works! I will have to research why though :slight_smile: Thank you

You want to access the entities within your group. Paste the following into developer tools —> template and look at the differences:


{{ expand('binary_sensor.xy') }}

{{ expand('binary_sensor.xyz') |map(attribute='name') }}

{{ expand('binary_sensor.xy') |map(attribute='name') |list }}

{{ expand('binary_sensor.xy') |map(attribute='name') |join }}

{{ expand('binary_sensor.xy') |map(attribute='name') |join(', ') }}

{{ expand('binary_sensor.xy') |map(attribute='name') |join('\n') }}

First information can be found here:
https://www.home-assistant.io/docs/configuration/templating/#working-with-groups

This is an old thread, but I wanted to write and say thanks and add to your examples.

I have an automation where I have two groups, one a group of my house doors, one a group of my barn doors. I made two groups so I could create two triggers and have two trigger IDs for different actions based on the trigger.

However, I wanted to get the name of the door that was open. Your example was perfect! However, I went a bit further and created this automation to notify all my google home devices (all in a media group, referenced by an input text helper because the group changes between day and night so I don’t send broadcasts to some bedrooms at night) to announce which door opened regardless of the group triggering the automation. Hence, my action now looks like this:

service: tts.cloud_say
data:
  entity_id: "{{ states('input_text.broadcast_device') }}"
  message: >-
    {{ expand(trigger.from_state.entity_id) | selectattr('state', '==', 'on') |
    map(attribute='name') | join(' and ') }} open
  cache: true

So what I am adding to here is in your example, you specifically referenced a particular binary sensor group binary_sensor.xy. I’ve changed that to trigger.from_state.entity_id so that your example would work with multiple groups within the triggers within the same automation. This way my automation can be more easily reused in the future.

The only downside I can see to using groups like this is that you don’t really know how long a particular entity was on, so I could not say with accuracy “the front door has been open for 5 minutes” because it may have just been opened but the back door was really the door open for 5 minutes.

Thanks again! You saved me a ton of time!