Looking for some help on how to send a notification which states which sensor tripped the manual alarm component, with the added complication of it being in a separate automation to the alarm trigger automation.
I want to keep the two separate so the notification is only sent when the alarm reaches the alarm triggered state, rather than the pending state.
My current code (simplified down to make it easier to read)
# ARMED AWAY TRIGGER
- id: alarm_trigger_away
alias: Trigger Alarm While Armed Away
trigger:
- platform: state
entity_id: binary_sensor.door_window_sensor_158d0001fd637f #Side Door
to: 'on'
condition:
- condition: state
entity_id: 'alarm_control_panel.home_alarm'
state: armed_away
- condition: state
entity_id: 'input_boolean.bed_mode'
state: 'off'
action:
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.home_alarm
# ARMED AWAY TRIGGER NOTIFICATION
- id: alarm_away_trigger_notification
alias: Send notification when alarm away triggered
trigger:
- platform: state
entity_id: alarm_control_panel.home_alarm
to: 'triggered'
action:
- service: notify.notify
data_template:
title: "ALARM!"
message: "The alarm has been triggered by the {{ trigger.to_state.attributes.friendly_name }} at {{now().strftime('%H:%M %d-%m-%Y')}}."
Putting the {{ trigger.to_state.attributes.friendly_name }} in the original alarm automation will send the correct sensor (in this case the side door sensor), but moving it to the secondary automation the trigger is the home alarm itself.
Is there a way to have the sensor from the primary automation carry through?
By ‘carry through’ you mean the trigger object of one automation referenced by another automation, the answer is no.
Why not just move the second automation’s action (notify.notify) to the first automation’s action? Then it will have access to the desired trigger object.
Yeah, that’s what I meant by carry through.
I wanted to keep them separate as if they’re in the same automation I end up with notifications each time the alarm is triggered, regardless of if it goes to full trigger or the pending state.
You lost me there. Your first automation calls alarm_control_panel.alarm_trigger which triggers the second automation whose only task is to call notify.notify. That’s why I suggested you move notify.notify from the 2nd automation to the 1st one.
When the first automation calls alarm_control_panel.alarm_trigger this is using the Manual Alarm Control Panel platform.
When set at armed_away there is a pending time of 30 seconds before moving to the triggered state.
The first automation I posted is a slimmed down version of the full trigger automation I have which works off multiple door & motion sensors. If the notify.notify service is called in this automation, it ignores the pending time in the Manual Alarm Control Panel platform, and fires during the pending time.
Splitting this out in to the second automation allows the notify.notify service to only be called once the alarm passes through the pending state, to the triggered state.
The second automation has also been slimmed down to only show the notify.notify function, as it also calls a number of other services to flash lights, sound an alarm etc.
Thanks for taking the time to explain the details; I understand the challenge now.
The solution is to store the friendly_name of whatever triggers the first automation, then retrieve it in the second automation.
You can do that using chris_avfc’s zoogara’s suggestion using MQTT and a device_tracker. Alternately, you can store the friendly_name in an input_text.
Define the input-text entity:
input_text:
trigger_source:
name: Trigger Source
In the first automation, save the friendly_name of whatever triggered the automation to input_text.trigger_source:
In the second automation, simply retrieve the value of input_text.trigger_source:
action:
- service: notify.notify
data_template:
title: "ALARM!"
message: "The alarm has been triggered by the {{ states('input_text.trigger_source') }} at {{now().strftime('%H:%M %d-%m-%Y')}}."
I’ve just tried implementing this but my sensor is shown as “unknown” in the notification… I’ve checked and all my sensors have friendly names setup… any ideas?
I am also getting unknown, not sure what I have done wrong
Full source automation code
- id: 'triggersourceauto'
alias: Trigger Source Info
trigger:
- platform: state
entity_id: binary_sensor.garage_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.gate_garage_side_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.gate_bedroom_side_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.front_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.back_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.garage_sliding_internal_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.sliding_door_sensor_contact
to: 'on'
from: 'off'
condition:
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_home
action:
- service: input_text.set_value
data_template:
entity_id: input_text.trigger_source
value: "{{ trigger.to_state.attributes.friendly_name }}"
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.home_alarm
Full notify automation code
- id: 'triggersourcenotify'
alias: Trigger Source Notification
trigger:
- platform: state
entity_id: binary_sensor.garage_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.gate_garage_side_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.gate_bedroom_side_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.front_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.back_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.garage_sliding_internal_door_contact
to: 'on'
from: 'off'
- platform: state
entity_id: binary_sensor.sliding_door_sensor_contact
to: 'on'
from: 'off'
condition:
- condition: state
entity_id: alarm_control_panel.home_alarm
state: armed_home
action:
- service: notify.notify
data_template:
title: "ALARM!"
message: "The alarm has been triggered by the {{ states('input_text.trigger_source') }} at {{now().strftime('%H:%M %d-%m-%Y')}}."
A little late, but I had the same problem when setting up just now and maybe you didn’t solved this yet.
When I replaced input_text.trigger_source by input_text.text3 it worked.
It was text3 because this is the number of the input_text in my configuration.yaml file
Hello. I tried implenting your code and it works great except I have a “Unkown” message instead of my entity name. Where do you write this code :
input_text:
trigger_source:
name: Trigger Source
on Configuration.yaml?
Thank you