Dynamic Alarm Notification Message Based on Sensor?

Tags: #<Tag:0x00007f3f26e12cf8>

Hello! I created an alarm based on a group of sensors and my garage door. The alarm trigger works, but the notification is too generic. Is there a way to add which sensor changed state to the notification without making different automatons for every sensor? e.g. if the front door was opened within my ‘all sensors’ group, can it say ‘Front Door Opened’ in the message? My code is below:

- alias: Trigger Alarm
  hide_entity: true
  trigger:
    - platform: state
      entity_id: group.all_sensors
      to: 'on'

  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: Alarm Triggered
  hide_entity: true
  trigger:
    - platform: state
      entity_id: alarm_control_panel.alarm
      to: 'triggered'
  action:
    - service: switch.turn_on
      entity_id: switch.siren
    - service: notify.mobile_app_my_iphone
      data:
        title: "ALARM TRIGGERED"
        message: "**<INSERT SENSOR HERE>**"
        data:
          push:
            sound:
              name: default
              critical: 1
              volume: 1.0

I think you will have to list all your sensors as individual triggers. Then you can use something like this:

    - service: notify.mobile_app_my_iphone
      data_template:
        title: "ALARM TRIGGERED"
        message: "{{ trigger.to_state.attributes.friendly_name }} triggered the alarm."
        data:
          push:
            sound:
              name: default
              critical: 1
              volume: 1.0
1 Like

Or just add a condition to ensure it only sends when one of a few devices are triggered.

Figured it out. Code below in case this is useful to someone else!

    - service: notify.ios_my_iphone
      data_template:
        title: ALARM TRIGGERED
        message: "{% for state in states|selectattr('entity_id','in',state_attr('group.all_sensors','entity_id'))|selectattr('state','eq','on')|list -%}{{state.name+', '}}{%- endfor %}"