Inform when door is left open and nobody is home

Got this working. Have two automation’s (this the one for me).
If I leave the zone and my partner is not home I get an message on the iphone telling there is still a door open. Works beautiful. The other automation is vice versa.

What I now would like is that message not only tells me that one of the doors is open, but also tells me witch door has been left open. I think it’s basic, but I can’t do it. Learning but still a noob.

alias: Door still open inform xxx1
description: ''
trigger:
  - platform: zone
    entity_id: person.xxx1
    zone: zone.home_adress
    event: leave
    id: device_tracker.iphone_2
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: person.xxx2
        state: not_home
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.openclose_28
            state: 'on'
          - condition: state
            entity_id: binary_sensor.openclose_45
            state: 'on'
          - condition: state
            entity_id: binary_sensor.openclose_46
            state: 'on'
          - condition: state
            entity_id: binary_sensor.openclose_47
            state: 'on'
          - condition: state
            entity_id: binary_sensor.openclose_48
            state: 'on'
action:
  - device_id: xxx1
    domain: mobile_app
    type: notify
    message: There is a door still open
    title: ''
    data:
      push:
        sound: Alert_Voicemail_Haptic.caf
mode: single

Create a group of your doors called group.all_doors.

Then change your automations to this:

alias: Door still open inform xxx1
description: ''
trigger:
  - platform: zone
    entity_id: person.xxx1
    zone: zone.home_adress
    event: leave
    id: device_tracker.iphone_2
condition:
  - condition: state
    entity_id: person.xxx2
    state: not_home
  - condition: state
    entity_id: group.all_doors
    state: 'on'
action:
  - device_id: xxx1
    domain: mobile_app
    type: notify
    message: "Attention! The following doors are open: {{ expand('group.all_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}"
    title: ''
    data:
      push:
        sound: Alert_Voicemail_Haptic.caf
mode: single

If you want to get really fancy you can change “doors” for “door” and “are” for “is” if there is only one door open.

    message: >
      {% if expand('group.all_doors') | selectattr('state','eq','on') | list | count == 1 %}
         Attention! The following door is open: {{ expand('group.all_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}"
      {% else %}
         Attention! The following doors are open: {{ expand('group.all_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}"
      {% endif %}

Put this in my Group.yaml

  all_doors:
    name: All Doors
    icon: mdi:motion-sensor
    entities:
    - binary_sensor.openclose_28
    - binary_sensor.openclose_45
    - binary_sensor.openclose_46
    - binary_sensor.openclose_47
    - binary_sensor.openclose_48

But got errors when I try it.

I cant help if you don’t post the error(s), but all_doors seems a long way from the margin. It should be hard against it.

Okay, it was a spacing error. But the fancy does not stick.

2021-09-29 14:29:09 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] while scanning for the next token
found character '%' that cannot start any token
in "/config/automations.yaml", line 892, column 15

Sorry, I left some quotes in when copying from the single line template. Try this:

    message: >
      {% if expand('group.all_doors') | selectattr('state','eq','on') | list | count == 1 %}
        Attention! The following door is open: {{ expand('group.all_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}
      {% else %}
        Attention! The following doors are open: {{ expand('group.all_doors') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}
      {% endif %}

Working. Muchas Gracias

1 Like