Alarm Panel Card - How to be notified of the sensors name that triggered the alarm?

Greetings,

I am very new to Home Assistant and just started my journey with it.
After configuring some z-wave sensors (Abus) and Shutters (Technisat), I wanted to give the Alarm Panel a try.

I got the Alarm Panel card to work with the two modes (states?) that I choose:

  • armed_away
  • armed_night

I was wondering if it is possible to be notified with the sensors name that triggered the Alarm?
Currently I receive a notification with a static text that I configured.

Motion sensors group

# Bewegungsmelder Gruppen
binary_sensor:
  - platform: group
    name: Bewegungsmelder_EG
    entities:
      # Treppe
      - binary_sensor.pir_multisensor_home_security_motion_detection
      # Flur
      - binary_sensor.pir_multisensor_home_security_motion_detection_3
      # Wohnzimmer
      - binary_sensor.pir_multisensor_home_security_motion_detection_2

Alarm Panel Card configuration

# Alarmanlage
alarm_control_panel:
  - platform: manual
    name: Alarmanlage
    code: "1234"
    code_arm_required: false
    arming_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_night:
      arming_time: 0
      delay_time: 0

Automation and notification

# Armed Away
- alias: 'Trigger alarm while armed away'
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegungsmelder_eg
      to: "on"
  condition:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
  action:
    service: alarm_control_panel.alarm_trigger
    target:
      entity_id: alarm_control_panel.alarmanlage

# Armed Night
- alias: 'Trigger alarm while armed night'
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegungsmelder_eg
      to: "on"
  condition:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
  action:
    service: alarm_control_panel.alarm_trigger
    target:
      entity_id: alarm_control_panel.alarmanlage

# Alarmierung
- alias: 'Send notification when alarm triggered'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.alarmanlage
      to: "triggered"
  action:
    # Notify Phone 1
    - service: notify.mobile_app_iphone_von_1
      data:
        title: "ALARM!"
        message: "ALARM! Bewegung EG"
    # Notify Phone 2
    - service: notify.mobile_app_iphone_von_2
      data:
        title: "ALARM!"
        message: "ALARM! Bewegung EG"

I found in this manual Manual - Home Assistant an example where it seems to call some sensor name with date and time. I never got it to work. I just receive my static text with “UNKNOWN”

message: >
          ALARM! The alarm is armed in Home mode {{ states('sensor.date_time') }}

I would appreciate any pointers how to get the sensor name in the title or message part.

Thank you

Welcome to the HA forums!

Have you created a sensor.date_time? If so, please post the code for it.

This is a working message example:


        message: >
          [Alarm] Alarm scharfgestellt ({{ now().strftime('%d.%m.%Y, %T') }})


I just created one by following Time & Date - Home Assistant

# Time & Date
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

I then included

({{ now().strftime('%d.%m.%Y, %T') }})

And I get the Date and Time. How do I get the sensor name? Is that even possible?


        message: |
          [Alarm] Alarm ausgelöst! 
          {{ trigger.to_state.attributes.friendly_name }}
          ({{ now().strftime('%d.%m.%Y, %T') }})

Your trigger entity triggers if it changes its state to ‘on’ = trigger.to_state.
One of the attributes of the entity is its given name = attributes.friendly_name . All together it’s trigger.to_state.attributes.friendly_name .

Sorry for the late reply, I could just test this now.
I have implemented your example:

  action:
    # Notify Mobile
    - service: notify.mobile_app_iphone_von_1
      data:
        title: "ALARM!"
        message: |
          [Alarm] Alarm ausgelöst! 
          {{ trigger.to_state.attributes.friendly_name }}
          ({{ now().strftime('%d.%m.%Y, %T') }})

What I get now is:

[Alarm] Alarm ausgelöst! 
Alarmanlage
(07.02.22, 16:30:...)

I am assuming it is reporting the name from my configurations.yaml for the Alarm Panel but not the sensors name that got triggered.

# Alarmanlage
alarm_control_panel:
  - platform: manual
    name: Alarmanlage
    code: "1234"
    code_arm_required: false
    arming_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_night:
      arming_time: 0
      delay_time: 0

Yes, because I’m a Weichbirne and had only a look at your binary_sensor trigger.

Expand your trigger group as part of the notification:


        message: |
          [Alarm] Alarm ausgelöst! 
            {{ expand('group.alarmsensor')
            |selectattr('state', 'eq', 'on')
            |map(attribute='name')
            |join(', ') }} ({{ now().strftime('%d.%m.%Y, %T') }})

Output: (as persistant notification for demo purposes)

1 Like

Somehow the “expand” part does not work in my configuration.

What I have tested:

  1. My sensor group configuration name: Bewegungsmelder_EG
    Sensor_group_config

  2. Armed night configuration with sensor group config
    Armed_night_with_group

  3. Notification configuration with sensor group name
    Notification_config_with_group

  4. The notification that I get
    Notification_with_sensor_group

Did I define my group wrong?
Should I configure the sensor group name differently in this part?

{{ expand('group.alarmsensor')

Or any other configuration that I should change?
I am open to not work with sensor groups if that would make things easier.

Ah, ok, it’s a Binary Sensor Group, I’ve missed that. You have to go this way:


{{ expand(state_attr('binary_sensor.bewegungsmelder_eg', 'entity_id')) 
  |selectattr('state','eq','on')
  |map(attribute='name')
  |join(', ') }}

1 Like

That did the trick
Notification_with_sensor_name

Thank you for the help. Much appreciated .

1 Like