How to display the sensor that triggers the alarm

Hi all, I have this automation:

alias: Allarme call-sms-mail
description: ''
  - platform: state
    entity_id: alarm_control_panel.casona_ea
    to: triggered
condition: []
  - service:
      message: 'ALLARME, zona violata: {{ trigger.to_state.attributes.friendly_name }}'
mode: single

So when the alarm triggers, I would like to know which sensor triggered.

But {{ trigger.to_state.attributes.friendly_name }} shows the name of the alarm control panel…

many thanks

First create group of all the sensors in question. call “group.all_sensors” . Assuming all your sensors states are either on or off. Set friendly name for each sensors, then it will output friendly names.

message: > 
   Intrusion detected, The following sensor was triggered:
   {{ states | selectattr('entity_id', 'in', state_attr('group.all_sensors,'entity_id')) | selectattr('state','in',['on']) | list | map(attribute='name') | join(', ') }}    

For future reference, if you already have a group of entities, there’s no reason to begin the template by selecting all entities (that’s what happens when you use states). Simply begin by expanding the group.

{{ expand('group.all_sensors') | selectattr('state','in',['on']) 
    | map(attribute='name') | list | join(', ') }}    

1 Like

Thank you for this (and @huu), I have several notifications using groups where this will be very useful e.g. leak alarms, temperature alarms etc.

If you know each member of the group simply reports on or off then you can replace this:


with this:


thanks for yours reply…
If I try:

{{ expand('group.sensori_casa') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}

under “developer tools->template” it works, but if I insert it in the automation I can’t save it!

Then you’re doing something wrong. Post the automation so we can review it.

Must be something in the automation UI. I dont use it, always mess up my automation and script formating.

Yes it wa in the UI.
Now it works! Thanks to all

I’m trying to do a similar automation, however it appears the template above only shows the sensor whilst it is on. If there is a delay before the alarm moves to the triggered state and the sensor turns off in that time, then the template will return an empty value I guess ?

yes, this is is also my problem. An automation triggers the alarm, but there’s the delay time where the alarm is in “pending” - the time to enter a code after opening the front door.

so in the case of:
open front door → triggers automation to trigger the alarm
alarm state changes to pending
close front door
alarm state changes to triggered
this template will not show the frontdoor as open…

is there any way to call “alarm_trigger” and send along generic data / attributes?
then I could also set something like a “triggering entity” attribute to the alarm that I could reference in the triggered state.