Automation: Grouped Sensors - notify with sensor name

Hi,

I have automations like this:

   alias: Wassersensoren ausgelöst - notify
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.wassersensor_kuche
    to: 'on'
  - platform: state
    entity_id: binary_sensor.wassersensor_waschkueche
    to: 'on'
  - platform: state
    entity_id: binary_sensor.wassersensor_wohnzimmer
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_phone
    data:
      message: '{{ trigger.to_state.name }} ausgelöst'
      title: Wassersensor
  mode: single

Everything is ok - I will be notified like " Wassersensor bathroom ausgelöst".
But now I want to group the sensors:

  alias: Wassersensoren ausgelöst - notify
  description: ''
  trigger:
  - platform: state
    entity_id: group.wassersensoren
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_app_phone
    data:
      message: '{{ trigger.to_state.name }} ausgelöst'
      title: Wassersensor
  mode: single

And now I will be notified like this: “Group Wassersensoren ausgelöst”.
Is it possible to specify the sensor exactly like above?

Try this:

message: "{{ expand('group.wassersensoren') | selectattr('state', 'eq', 'on') | map(attribute='friendly_name') | list | join(',') }} ausgelöst"
1 Like

Thank you for your post.
I get then a error message

error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/automations.yaml", line 218, column 7
expected <block end>, but found '<scalar>'
  in "/config/automations.yaml", line 218, column 28

Replace the sinqle quotes around the message with double quotes, I corrected my post.

Now I get the message without a name. Only “ausgelöst”

The second automation will trigger when the group’s state changes to on. That means all the binary_sensors within the group were off and then one of them changed to on.

If a second binary_sensor in the group now changes to on, the automation will not be triggered again. Why not? Because the group’s was already on and simply remains on. There’s no state-change so there’s no trigger. In other words, there are situations where it will not send a notification.

You’re better served by the first automation that monitors each binary_sensor individually.

- alias: Wassersensoren ausgelöst - notify
  description: ''
  trigger:
  - platform: state
    entity_id: 
    - binary_sensor.wassersensor_kuche
    - binary_sensor.wassersensor_waschkueche
    - binary_sensor.wassersensor_wohnzimmer
    to: 'on'
  condition: []
  action:
  - service: notify.mobile_phone
    data:
      message: '{{ trigger.to_state.name }} ausgelöst'
      title: Wassersensor
  mode: single
1 Like

Ok, then I use the first automation.
Thank you for your post.