Dynamic Alarm Notification Message Based on Sensor?

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 %}"
3 Likes

I have adapted the solution to notify open zones during alarm arming, only it sends notification with empty text, if I have all the zones closed (rest). does anyone know how to fix?

what has been done below:

alias: Notification List of Open Zones System Armed
description: ‘’
trigger:

  • entity_id: sensor.perimeter_status
    platform: state
    to: EXIT
    condition: [ ]
    action:
    • service: notify.notify
      data_template:
      title: Excluded Zones
      message: “{% for state in states|selectattr(‘entity_id’,‘in’,state_attr(‘group.sensor_perimeter_alarm’,‘entity_id’))|selectattr(‘state’,‘eq’,‘ALARM’)|list -%}{{state.name+’, '}}{%- endfor %}”
    • service: telegram_bot.send_message
      data_template:
      title: Excluded Zones
      message: “{% for state in states|selectattr(‘entity_id’,‘in’,state_attr(‘group.sensor_perimeter_alarm’,‘entity_id’))|selectattr(‘state’,‘eq’,‘ALARM’)|list -%}{{state.name+’, '}}{%- endfor %}”

thanks

1 Like

I’m getting the same empty message. Were you ever able to fix this issue?

try like this

  • alias: Notifica Elenco Zone Aperte Impianto Inserito
    description: ‘’
    trigger:
    • entity_id: sensor.perimetrale_status
      platform: state
      to: EXIT
      condition: “{{ expand(‘group.sensori_allarme_perimetrale’) | selectattr(‘state’,‘eq’,‘ALARM’) | list | count > 0 }}”
      action:
      • service: notify.notify
        data_template:
        title: Zone Escluse
        message: “{% for state in states|selectattr(‘entity_id’,‘in’,state_attr(‘group.sensori_allarme_perimetrale’,‘entity_id’))|selectattr(‘state’,‘eq’,‘ALARM’)|list -%}{{state.name+’, '}}{%- endfor %}”
      • service: notify.famiglia
        data_template:
        title: Zone Escluse
        message: “{% for state in states|selectattr(‘entity_id’,‘in’,state_attr(‘group.sensori_allarme_perimetrale’,‘entity_id’))|selectattr(‘state’,‘eq’,‘ALARM’)|list -%}{{state.name+’, '}}{%- endfor %}”
1 Like