Abode - Announce Open Doors/Windows

I just set up an Abode alarm system and wanted more feedback on what is open when arming it and the state that is being set.

General Setup:

This sensor template build a comma delimited list of open windows and doors

- sensor:
  - name: "Open Windows and Doors"
    unique_id: open_windows_and_doors
    state: >-
        {% set daw = namespace(all=[], open=[]) %}
        {% set daw.all = integration_entities('HSGW-B0C5CA3FE3D8') |
            select("match", "^binary_sensor\..*") |
            reject("match", ".*motion") |
            reject("match", ".*monitor") |
            reject("match", ".*glass_break") |
            list | sort %}
        {% for entity_id in daw.all -%}
          {% if is_state(entity_id, 'on') -%}
            {% set daw.open = daw.open + [device_attr(entity_id, 'name')] %}
          {%- endif %}
        {%- endfor %}
        {{ daw.open | join(',') }}

I then have this automation, which on any sort of arming event does a few things:

  • Sets the volume of the Google Home nearest the keypad to 50%
  • Has Google describe what is open
  • Says the alarm mode
  • Locks any door that is closed
alias: Abode - Lock Doors on Arming
description: ''
trigger:
  - platform: device
    device_id: 40927ec285a941deaead64c5c64abae9
    domain: alarm_control_panel
    entity_id: alarm_control_panel.abode_gateway
    type: armed_home
  - platform: device
    device_id: 40927ec285a941deaead64c5c64abae9
    domain: alarm_control_panel
    entity_id: alarm_control_panel.abode_gateway
    type: armed_away
  - platform: device
    device_id: 40927ec285a941deaead64c5c64abae9
    domain: alarm_control_panel
    entity_id: alarm_control_panel.abode_gateway
    type: armed_night
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.5
    target:
      device_id: 70922a60f3e549ca96b682f424f8ba2f
  - service: tts.google_cloud_say
    data:
      entity_id: media_player.living_room_home
      message: >-
        {% if (states('sensor.open_windows_and_doors')|length) > 0 -%}
          The {% for entity_name in
          states('sensor.open_windows_and_doors').split(',') -%}{{ ', and ' if
          loop.last else ('' if loop.first else ', ') }}{{ entity_name }}{%-
          endfor %} are open.
        {%- endif %} {% set alarm_state =
        states('alarm_control_panel.abode_gateway') %} The Alarm is {{  
          'Home and Guarding' if alarm_state == 'armed_home' else (
          'Armed Away' if alarm_state == 'armed_away' else alarm_state)
        }}
  - if:
      - type: is_not_open
        condition: device
        device_id: 0d44093aed3f39474d68ca8bd253492b
        entity_id: binary_sensor.front_door
        domain: binary_sensor
    then:
      - device_id: b12ce00482c3ef986b4b411e1d600a34
        domain: lock
        entity_id: lock.front_door_lock
        type: lock
  - if:
      - type: is_not_open
        condition: device
        device_id: 06e382ce129111eba4656115d8e580c6
        entity_id: binary_sensor.garage_entry_door_contact
        domain: binary_sensor
    then:
      - device_id: caee159d5280bae85cf5cfc371c14bce
        domain: lock
        entity_id: lock.garage_door_lock
        type: lock
    else: []
  - if:
      - type: is_not_open
        condition: device
        device_id: 2566a2006c6b575fa6cdfbc97f23ebd3
        entity_id: binary_sensor.basement_door
        domain: binary_sensor
    then:
      - device_id: 16128b7cfb5914857524a8f1aa6afdb4
        domain: lock
        entity_id: lock.basement_patio_door_lock
        type: lock
    else: []
mode: single

I also have a MarkDown template card that shows what is currently open:

- type: markdown
        title: Open Windows and Doors
        content: >-
          *  {{ states('sensor.open_windows_and_doors').split(',') | join('\n*  ')}}

I’d love any feedback on the template sensor code as I’m not super familiar with jinja and it feels like manually rebuilding a list to do the is_state and device_attr checks is not the best way to go about it.

2 Likes