Manual Alarm Notification Trigger Variable

I’ve got an alarm. What I want to do is when the manual alarm state is triggered send a notification and show what trigger caused it to alarm. Seems most just alarm when a trigger fires and the alarm is set to away. The difference is that doesn’t honor the delay or any future options alarm may implement.

So I tried doing something like this:

- alias: 'Trigger alarm while armed'
  trigger:
    - platform: state
      entity_id: sensor.front_door # Front Door
  condition:
    condition: or
    conditions: 
      - condition: state
        entity_id: alarm_control_panel.alarm
        state: armed_away
      - condition: state
        entity_id: alarm_control_panel.alarm
        state: armed_home
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.alarm



- alias: 'Notify when triggered'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.alarm
      to: 'triggered'
  action:
    - service: notify.notifier
      data_template:
        message: >-
          {%- for state in states.sensor if state.entity_id == trigger.entity_id -%}
            {{ state.attributes.friendly_name }} was triggered.
          {%- endfor -%}

The problem is I don’t see how i can update the notifier message to show what device caused the alarm to invoke. Curious if anyone has a solution for this.

Have you tried adding the notifier to the alarm trigger. You already know which device is triggering the alarm there.

action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.alarm
    - service: notify.notifier
      data:
        message: "Front door alarm sensor was triggered."

Yes I have. The problem is that triggers the second the door is opened. I want to honor HA’s trigger_delay as specified in the manual alarm. So I setup the first automation to trigger. Then another automation to fire on trigger.

Ok, got it. I am not familiar with the HA Manual Alarm or whether is stores the triggered item.

Another option if you cannot get the item that triggered the alarm is to create a hidden binary sensor for each opening. If the alarm is armed, set the binary sensor to ‘on’ for the associated opening. Then loop through the hidden binary sensor in your alarm panel automation. Don’t forget the ensure all the hidden binary sensors are ‘off’ when you disarm the alarm.

I’m hoping there’s a better way :persevere:

Bump.

Anyone know how this is intended to work? Looking through cookbook examples I don’t see anyone honoring the trigger time. Curious what the dev’s intended here.

Okay,

I’ve been messing around with this for a while, but it has been working for me. Running 0.51

- alias: 'Trigger alarm while armed away'
  hide_entity: True
  trigger:
    - platform: state
      entity_id: binary_sensor.re2_door
      to: 'on'
  condition:
    condition: or
    conditions:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: armed_away
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: armed_home
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.ha_alarm
    - service: script.s_alarm_trigger
      data_template:
        message: >
          {{ trigger.to_state.attributes.friendly_name }} was opened when armed
          {{now().strftime("%Y-%m-%d %H:%M:%S")}}

Script that waits if the system is disarmed (also passes the trigger data for the proper notification):

s_alarm_trigger:
  sequence:
  - delay:
      seconds: !secret alarm_trigger    ### Set to 60 seconds. Same entry for trigger_time in alarm config.
  - service: notify.walrus_text
    data_template:
      message: "{{ message }}"
    data:
      title: 'Alarm'

Automation to cancel the script when system is disarmed:

- alias: 'Trigger when alarm disarmed'
  hide_entity: True
  trigger:
    platform: state
    entity_id: alarm_control_panel.ha_alarm
    to: 'disarmed'
  action:
    - service: homeassistant.turn_off
      entity_id: script.s_alarm_trigger

That’s an interesting approach!

I’m thinking this is ultimately a flaw in the alarm design.

@walrus_parka can you explain me why you used the automation to ‘cancel the script’?

It should be executed only if alarm is armed home/away by the first automation (conditions are 'armed_home or armed_away) without the need of the second one…

@blackgear I didn’t want to get an additional notification saying what triggered the alarm as well as the system being disarmed.

although this is already an old topic, here my solution that works with HA 0.82.1:

Create an input_text for your triggered devices.
I use a separate input_text.yaml and enabled it in my configuration.yaml with the line
input_text: !include input_texts/input_text.yaml

My input_text.yaml:

alarm_trigger:
  name: Alarm Trigger
  initial: ""

My automation that triggers the alarm, alarm_triggers.yaml:

alias: 'Alarm Triggers'
trigger:
- platform: state
  entity_id: binary_sensor.motion_living
  to: 'on'
- platform: state
  entity_id: binary_sensor.motion_garage
  to: 'on'
condition:
- condition: template
  value_template: "{{ not is_state('alarm_control_panel.home_alarm', 'disarmed') }}"
action:
- service: input_text.set_value
  data_template:
    entity_id: input_text.alarm_trigger
    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 %}
- service: alarm_control_panel.alarm_trigger
  entity_id: alarm_control_panel.home_alarm

last but not least, the automation to turn on all downstairs lights and send out a notification when and where the alarm has been triggered:

alias: 'Alarm Triggered Notification'
trigger:
- platform: state
  entity_id: alarm_control_panel.home_alarm
  to: 'triggered'
action:
- service: notify.telegram
  data:
    message: "ALARM! Trigger: {{ states.input_text.alarm_trigger.state }}"
- service: scene.turn_on
  entity_id: scene.lights_downstairs_bright

finally resetting the trigger value to blank if the alarm has been disabled and if you want send a notification:

alias: 'Alarm Disarmed Notification'
trigger:
- platform: state
  entity_id: alarm_control_panel.home_alarm
  to: 'disarmed'
action:
- service: notify.telegram
  data:
    message: "Alarm disarmed (resetting trigger: {{ states.input_text.alarm_trigger.state }})"
- service: input_text.set_value
  data_template:
    entity_id: input_text.alarm_trigger
    value: ''
2 Likes

Thanks, I’ve been looking for this exact thing!

This is a good solution but sounds to me like an expensive work-around, it doesn’t cover more complex scenario like taking a snapshot when the sensors are triggered and anyway requires set/unset the variables every time we use them.
Using external variables makes things more difficult than they are, and maintenance of the code grows a lot.

Workaround:

trigger:

  • platform: state
    entity_id: alarm_control_panel.alarma

condition:

  • condition: state
    entity_id: alarm_control_panel.alarma
    state: ‘triggered’