I stumbled across this looking for something else and I’m not sure if I understand your issue completely but, I use the following automation to find out which of my garage doors was left open:
automation/notifications.yaml:
- alias: Garage Doors Left Open
trigger:
- platform: state
entity_id: group.garage_door_jc, group.garage_door_ac
from: 'off'
to: 'on'
for:
minutes: 10
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.automation_override
state: 'off'
action:
- service: notify.all
data_template:
data:
sound: mechanical
priority: 1
message: >
{{ trigger.from_state.attributes.friendly_name }} has been open
for > 0:10.
Did you receive any solution for this, i am also in the same situation, I want to have trigger based on one of the sensor in the group I have around 26 sensor but want message say which sensor trigged this automation flow.
The only way to do it is to include each entity in the trigger of the automation. For any other solution, you would have to custom develop something…maybe AppDaemon?
Would script work? how do I access the trigger data in the action block?
Like by the time my script executes, the door may be closed so i cant check the status of all door in the action block.
I found this post while looking for a solution to this exact same question, since I couldn’t find a solution I started throwing guesses at the dev-template tool in HA and arrived at this one solution that works well for me:
- alias: 'Notify if door/window opened for 2 minutes'
trigger:
- platform: state
entity_id: group.doors, group.windows
to: 'on'
for:
hours: 0
minutes: 2
seconds: 0
action:
- service: notify.jardi_smtp
data_template:
title: 'Door/Window Opened'
message: >-
{% for entity in trigger.to_state.attributes.entity_id %}
{% if states(entity) == 'on' %}
{{ state_attr(entity, 'friendly_name') }} has been opened for 2 minutes
{% endif %}
{% endfor %}
It’s keeping me all the time the first entity in the group. Would love to see a script that works…
Its so much nicer to have a group instead of a whole list of entities …
That’s what this template will do. It’ll tell you all the ones in the group that are on, if your message can’t handle multiple lines, then its a problem with your notification device.
See “Sensor(s)” part.
Since the group is triggering the automation, that trigger state cannot be used to show the entity that triggered the group. However when checking the group for sensors with state = on immediately after the automation was triggered, the only entity with ‘on’ state from that group is the one that triggered the whole thing.
Even if there are more sensors with state = on, the statement will show a list of entities.