Group state on automation, how to trigger?

Hi
I am trying to write an automation to notify me if any of my binary sensors are offline (though ping integration). I created a group called online_devices and ideally I would like to have something like the following.
My problem is the trigger since even if one of the sensors goes offline the state of the group remains on.
Is there another way to trigger this? (I need the group because I intend to add some more binary sensors in the future

- id: Alert for Online Devices
  alias: Alert for Online Devices
  trigger:
    - platform: state
      entity_id: group.online_devices
      to: 'off'
      for:
        hours: 0
        minutes: 1
        seconds: 0
  
  condition: []
  
  action:

    - service: notify.mobile_app_sm_g955f
      data_template:
        message: "The {{ expand('group.online_devices') | selectattr('state', 'eq', 'off') | map(attribute='name') | list | join(', ') }} sensor is oflline."
        data:
          color: '#2DF56D'
          vibrationPattern: "1000, 500, 1000, 500, 1000, 500, 1000, 500, 1000, 500, 1000, 500, 1000, 500, 1000, 500, 1000, 500" # The pattern you wish to set for vibrations
          ledColor: "blue"
          channel: Home Assistant notify channel # name of the channel you wish to create or utilize
          importance: high
          priority: high
          ttl: 0

Maybe this could work:

- platform: template
  value_template: "{{ expand('group.online_devices') | selectattr('state', 'eq', 'off') | list | count > 0 }}"

Can’t test at the moment, but this should trigger when one or more devices are offline. The tenplate will be rendere every time any of the entities in the group changes state.

1 Like

It is not working. I ended up to add each binary sensor one by one.
Thanks for yor time and help in any case