Notifications for door openings like the battery alert

hi there, new to the community and extremely new to python. i’ve been playing around for a while and have a ton configured in my system (vera, push, nginx, mysensors, usb zwave)

recently i created a manual alarm control panel and works well with notifications. what i am now trying to do is port over the code from the battery template and automation to use with the alarm notification.

essentially, when the alarm panel is armed and triggered, send a push notification. OK. that was easy peasy.

where i am stuck is creating the custom sensor template like i did for battery sensors for my binary sensor door/window sensors, so i can pipe that into my push notification so i know exactly which sensor was breached vs just a generic message.

i dont really know the template formatting to get the tripped attribute. this is what i have so far, i’m sure someone here will know exactly what i’m doing wrong

########################################################################
#----------------- Door Input Status template -------------------
#---------------------------------------------------------------
#######################################################################

  - platform: template
    sensors:
      security_sensors:
      friendly_name: "Security Sensors"
      value_template: >
        {%- set domains = ['binary_sensor'] -%}
        {%- for domain in domains -%}
        {%- for item in states[domain] if (item.attributes.device_tripped is on) -%}
            {{ item.attributes.friendly_name }}{%- if not loop.last %}, {% endif -%}
        {%- endfor -%}
        {%- endfor -%}

can anyone assist?

i left the set domains part in because i may expand this to regular sensors in the short term, but for now all my door/window sensors are binary_sensors coming from vera (vera is still left in place to keep the wife happy while i tinker to get HA exactly how i need it before ‘production’ time)

i’m getting tripped up on the for test to look for the on state of the device trip.

if anyone else has another idea of how to accomplish this i’m all ears. please excuse my ignorance on the python code, and attributes, it is extremely difficult to find info on how to retrieve this attribute data and how i should have it formatted in the template

It depends on how you trigger your alarm, but if the binary sensors are listed in the trigger section of the automation then this should work.

{{ trigger.to_state.attributes.friendly_name }}

thanks @walrus_parka.

would this go in place of this?
(item.attributes.device_tripped is on)

i basically have 2 automations:
automation 1.

  • trigger alarm control panel alarm when in away mode
  • currently my individual binary sensors are the trigger (which i was thinking of switching it to use this new “security sensors” sensor template in my OP), which the action is triggering the ‘triggered’ state my manual alarm control panel

automation 2.

  • when alarm panel state changes to triggered
  • sends a notification with the message containing “{{ states(sensor.security_sensors) }}”

is this possible?

OK i got it working. probably no where near bullet proof, but pretty effective by itself.

my sensor template

- platform: template
  sensors:
    security_sensors:
      friendly_name: "Security Sensors"
      value_template: >
        {%- set domains = ['binary_sensor'] -%}
        {%- for domain in domains -%}
        {%- for item in states[domain] if ((item.state is defined and item.state == "on" )) -%}
            {{ item.attributes.friendly_name }}{%- if not loop.last %}, {% en$
        {%- endfor -%}
        {%- endfor -%}

then i just reference this sensor in the message section of my automation

  alias: 'Send notification when alarm triggered'
  trigger:
- platform: state
  entity_id: alarm_control_panel.home_alarm
  to: 'triggered'
action:
- service: notify.notify
  data:
    title: "ALARM! The alarm has been triggered"
    message: "{{ states('sensor.security_sensors') }}"

and i get a readout of all sensors active from the time of the alarm trigger :grinning: