Which door opened

I have an automation that will let me know if a door sensor has been triggered while my wife and I are out.

alias: ... Away Door Sensor
description: ""
trigger:
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.front_door
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.kitchen_window_l
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.kitchen_window_r
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.kitchen_door_main
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.kitchen_door_l
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.bedroom_door_left
  - platform: state
    from: "off"
    to: "on"
    entity_id: binary_sensor.bedroom_door_right
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.angelina
        state: home
      - condition: state
        entity_id: person.nicholas
        state: home
action:
  - device_id: 99e4216c96314c7297bca8f0859d6e6f
    domain: mobile_app
    type: notify
    message: Door sensor triggered
mode: single

How could I add into the automation which door was opened?
Is there a better way then to create a helper (resets after a few minutes) and if that helper is on then show that sensor?

Thanks

I use a template sensor for this.

  - platform: template
    sensors:
      door_window_check:
         friendly_name: Door/Window Check
         value_template: >-
           {% set perimeter = expand('binary_sensor.storage_door', 
                      'binary_sensor.front_door', 
                      'binary_sensor.basement_door', 
                      'binary_sensor.sliding_glass_door',
                      'binary_sensor.bathroom_window',
                      'binary_sensor.bedroom_back_window',
                      'binary_sensor.bedroom_side_window',
                      'binary_sensor.kitchen_window',
                      'binary_sensor.living_room_left_window',
                      'binary_sensor.living_room_right_window',
                      'binary_sensor.master_bedroom_front_window',
                      'binary_sensor.master_bedroom_side_window',
                      'binary_sensor.pantry_window')
                | selectattr('state', 'eq', 'on')
                | map(attribute='name') | list %}
           {% set qty = perimeter | count %}
           {% set p1 = 'are' if qty > 1 else 'is' %}

           {% if qty == 0 %} 
              All doors and windows are closed
           {% else %}
           {{' and '.join((perimeter | join(', ')).rsplit(', ', 1))}} {{p1}} open
           {% endif %}

You can definitely compact that a bit.

And don’t use a device action. There are very limited in what you can do.

try this:

alias: ... Away Door Sensor
description: ""
trigger:
  - platform: state
    from: "off"
    to: "on"
    entity_id: 
      - binary_sensor.front_door
      - binary_sensor.kitchen_window_l
      - binary_sensor.kitchen_window_r
      - binary_sensor.kitchen_door_main
      - binary_sensor.kitchen_door_l
      - binary_sensor.bedroom_door_left
      - binary_sensor.bedroom_door_right
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: person.angelina
        state: home
      - condition: state
        entity_id: person.nicholas
        state: home
action:
  - service: notify.mobile_app
    data:
      message: '{{ trigger.to_state.attributes.name }} sensor triggered'
mode: single

you can probably get rid of the β€œfrom:” as well unless your sensors go to some other state regularly (unavailable, unknown) before going to β€œon”.

1 Like

Thank you this is awesome!

I’ve created two sensors, one for external door/ window contacts and one for internal.

The external need to be shut in order for the alarm to activate. The internal are informational.

Thanks

1 Like