Notification to State Which Sensor Triggered Manual Alarm

Hi All,

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?

Thanks

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.

:thinking: 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.

Apologies, I’ll try and make it a little clearer.

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.

I store the trigger entity in of all things a dummy device tracker. I cant remember where I got the original idea from.

Device tracker definition:

# Device tracker masquerading as variable storage
device_tracker:
  - platform: mqtt
    devices:
      sensor_name: 'sensor/name'

Store a value (as well as trigger the next automation):

    action:
      - service: alarm_control_panel.alarm_trigger
        entity_id: alarm_control_panel.alarm
      - service: mqtt.publish
        data_template:
          payload: "{{ trigger.entity_id }}"
          topic: sensor/name
          retain: true

And finally retrieve the value in the next automation:

      - service_template: notify.alarms
        data_template:
          message: >
            Home alarm triggered - sensor: {{ states('device_tracker.sensor_name') }}
          target:
            - '+61412345678'

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:

  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

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')}}." 

1 Like

Perfect, that’s exactly what I was looking for!
I just want sure on the way to store a value.

I’ve tested this out earlier today and it’s working perfectly!

Thanks very much.

Looks like you had the same idea as @zoogara.

Thanks ever so much for the help!

Yes, same idea (store the entity_id) but different implementation (store in input_text; no need for MQTT).