Trigger on a group and info of triggered entity in the group

Hi All,

There are some topics with this, but didn’t work out for me.
I want a automation on a group. Then it send a message to pushover with the info of the triggered entity within the group.

I tried everything but it still not working… Can someone assist me with this?

###########################################################################################
# NOTIFY WHEN WRT DEVICES GOES OFFLINE OR ONLINE
###########################################################################################

- alias: "Notification - WRT Devices Online/Offline"
  trigger:

    platform: state
    entity_id:
      - group.wrt
    to: "off"

  mode: restart

  action:
    service: script.pushover_engine
    data_template:
      message: >-
        {{ trigger.from_state.attributes.friendly_name }} is {{ 'online' if trigger.to_state.state == 'home' else 'offline' }}
      priority: "0"
      sound: "bike"
      title: "HA Notify Engine"

What type of entities are in the group?

device_tracker but some have many of them have mac addresses.
They all have friendly_name and state is ‘home’ or ‘not_home’

many automations I don’t use the to: “off” because then it trigger always when something change
So i will remove the to: “off” at the end for sure

A group of device_tracker entities will not be 'on' or 'off', it will be 'home' or 'not_home', so using to: "off" doesn’t make sense anyway.

So I’m not sure exactly what you’re trying to do. But whatever you use for the trigger, I’m guessing you want to find the entity in the group that changed last. If so, then maybe something like this:

  action:
    service: script.pushover_engine
    data_template:
      message: >
        {% set last = (expand('group.tracked_people')|sort(attribute='last_changed'))[-1] %}
        {{ last.name }} is {{ 'online' if last.state == 'home' else 'offline' }}
      priority: "0"
      sound: "bike"
      title: "HA Notify Engine"

Thanks new code so will learn new things again :smiley:
Will it be this in my case:

changed group.tracked_people to group.wrt. because my trigger is group.wrt

{% set last = (expand('group.wrt')|sort(attribute='last_changed'))[-1] %}
{{ last.name }} is {{ 'online' if last.state == 'home' else 'offline' }}

Oops, yes. I was testing with a group of device_trackers I have and forgot to change the name of the group to yours.

1 Like