How do I get the names of what devices triggered an alarm in an automation?
I’m just using the basic manual alarm and I’ve confirmed that everything works well for arming/disarming and triggering. I get a basic notification right now that the alarm was triggered, but I can’t figure out how to tell which device triggered the alert…
Is there a simple way to add a template to a notification for which sensor(s) tripped the alarm?
Strange, I was doing this when I was using a custom alarm panel but I got fed up with it breaking at times… I assume this method can be used with just the manual alarm?
For some reason the notification doesn’t work if I try to use the template… there’s an error happening somewhere that I can’t quite pinpoint.
I’m using a custom alarm panel. I recommend using the example from Tom above. The example I gave was simply included in the custom alarm that I used and I have actually now looked at some of my other code and found that I have multiple examples like Toms elsewhere in my config, a method which is much cleaner.
eg:
- service: tts.google_say
entity_id: media_player.googlehome3019
data_template:
message: "Hi there, the {{ trigger.to_state.attributes.friendly_name }} needs some attention, please go and check on it"
Ok, so the problem I have with this method is I just get “The House TRIGGERED the alarm!”
“House” being the name of my alarm… it doesn’t seem to tell me what actually triggered it.
EDIT: Nevermind, I see with this method I have to put it in the automation that actually has the trigger… the reason I wanted to avoid this is because I don’t care about the trigger if it gets disarmed before the trigger delay on the alarm.
I ended up using a custom input_text to keep a concatenated list of names of devices that were opened when the alarm went off. I will come post details this weekend.
Sorry about the super long delay… you may have already figured out by now what you were working on, but for the benefit of anyone looking for it… here are the details of what I’ve been doing that works.
I created an input_text like this:
#used with automation notifications to show what triggered an alarm
alarm_trigger:
name: Alarm Trigger
initial: ""
Then I have an automation set up to record the triggering sensor to the input_text:
#trigger alarm system with devices when armed
- id: a_trigger_alarm_with_sensors
initial_state: True
alias: 'Trigger alarm while armed away or armed home'
trigger:
- platform: state
#this include was just an easy way for me to keep track of possible triggering
#sensors and not have to write them out in only one place (creating a group
#as the entity id here does not work because it will record
#the group name as the triggering sensor
entity_id: !include ../groups_by_file/alarm_trigger_sensor.yaml
to: 'on'
condition:
condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.house
state: armed_away
- condition: state
entity_id: alarm_control_panel.house
state: armed_home
action:
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.house
- service: input_text.set_value
data_template:
entity_id: input_text.alarm_trigger
#note that this value template will append multiple sensors
#if any were open at the same time
value: >
{% if states.input_text.alarm_trigger.state|length == 0 %}
{{ trigger.from_state.attributes.friendly_name }}
{% elif (states.input_text.alarm_trigger.state|length + trigger.from_state.attributes.friendly_name|length) < 100 %}
{{ states.input_text.alarm_trigger.state }}, {{ trigger.from_state.attributes.friendly_name }}
{% else %}
{{ states.input_text.alarm_trigger.state }}
{% endif %}
I have a notification automation to send me the recorded sensors that triggered the alarm:
hello eric10k93
This seems to be exactly what I’m looking for.
unfortunately i’m still very new to HA and ymal, would you be able to share what you have in your alarm_trigger_sensor.yaml file, i’m guessing it a list of all your sensors and i’d like to see how you’ve created the list.
thanks
I’ve admittedly had this part of my automation disabled since I moved… I can’t confirm if it still works since I haven’t set all my sensors back up, sorry.