Consider the house secure based on many sensors

Hi All,

I am now moving my HA experience from just adding devices and and a good switch and status dashboard to automations. Currently I only have one automation that turns some lights on 30 mins before sunset for instance. LOL.

I have a number of doors in my house, all have Zigbee sensors on them. It is easy to look down the list and see if a door is open but it would be better if I had a master status which would be on if all sensors are closed and off if any sensor is open.

Purpose would be to easily see that status before bed to see if we have left a door open.

Can anyone point me to an example or direction on how to start going about doing this?

Thanks in advance.

Template binary sensor.
Something like this:

template:
  - binary_sensor:
      - name: Doors closed
        state: >
          {{ is_state('binary_sensor.door_1', 'on')
             and is_state('binary_sensor.door_2', 'on')
             and is_state('binary_sensor.door_3', 'on')
             and is_state('binary_sensor.door_4', 'on') }}

I this example binary_sensor.door_closed would be on if all the door sensors are on, and off if one or more are off.

edit: or as suggested use group. I have never noticed the all configuration variable before, that one is very handy!

Use Group as mentioned by tom_l and then use an automation to notify you if some doors/windows are left open. Group state will be ON if at least one of the entities inside the group are OPEN.

(1) Create a group consisting of all the doors and windows that you want to check-

group:
  security_breach:
    name: Security Breach
    entities:
      - binary_sensor.abc
      - binary_sensor.def
      - binary_sensor.ghi

(2) Create an automation to notify you. As an example, routine check will be performed at 22:00. This will also notify you if the group is opened between 22:00 to 05:00 (burglar forced open).

trigger:
  - platform: state
    entity_id: group.security_breach
    to: 'on'
  - platform: time
    at: '22:01'
condition:
  - condition: time
    after: '22:00'
    before: '05:00'
action:
  - repeat:
      until:
        - condition: state
          entity_id: group.security_breach
          state: 'off'
      sequence:
        - service: notify.mobile_app_your_name
          data:
            message: >-
              {% set wd = expand('group.security_breach') | selectattr('state', 'eq', 'on') | map(attribute='name') | list | join(", ") %}
              {% set x = ', and ' if wd.split(', ') | count > 2 else ' and ' %}
              Alert! {{x.join(wd.rsplit(', ', 1))}} {{'are' if wd.split(', ') | count > 1 else 'is' }} opened in the house.
        - delay: '00:00:30'
1 Like

Oops. I ignored the inverted state that the group would give (it will be on if any doors are open).

The only thing I would add to to Skeletorjus’s template would be a device class. https://www.home-assistant.io/integrations/binary_sensor/#device-class

There’s a picture with all the binary sensor device class options here: https://community.home-assistant.io/t/binary-sensor-device-classes/243493

The problem or door device classes would seem to be suitable.

I actually think a group could work by setting all: true, but I have never tried it myself. That one was new to me.

Another thing I missed from my template that I would consider best practice is to define a unique_id as this makes the sensor editable from the UI.

This is amazing feedback! Thank guys! I’ll play and report back!!

I’ve got through step one thanks to the great advice.

I setup a group and that works well.

# group config to determine if the house is secure or not

house_is_secure:
    name: House is Secure
    entities:
    # Alfresco Back Door
    - binary_sensor.ewelink_ds01_XXXX_ias_zone
    # Alfresco Sliding Door
    - binary_sensor.ewelink_ds01_XXXX_ias_zone
    # Back Sliding Door
    - binary_sensor.ewelink_ds01_XXXX_ias_zone
    # Front Door
    - binary_sensor.ewelink_ds01_XXXX_ias_zone
    # Garage Side Door
    - binary_sensor.ewelink_ds01_XXXX_ias_zone
    # Garage Door
    - sensor.garage_door_is_open

I didn’t like the on / off output and wanted it to be a more readable status for Love Lace so I setup a sensor to monitor the group and output text I like.

# config to monitor the status of the house_is_secure group and set a sensor to friendly values
        
      house_is_secure:
        unique_id: house_is_secure
        friendly_name: House is Secure
        value_template: "{% if is_state('group.house_is_secure','off')%}Secure{% elif is_state('group.house_is_secure','on')%}Not Secure{% endif %}"

Would have been perhaps easier to be able to add a device class to the group but after reading the docs it didn’t seem that was an option.

Now to progress and do the notifications and automation bits as exampled above.

I ran into a bit of an aesthetic problem.

I added the above house_is_secure sensor to Love Lace.

Unlike other information on Love Lace this is the only item I have that doesn’t change colour (to yellow) as the status changes. I assume this is because it can’t differentiate between my manual values as to which should be yellow or not.

Is there a way to set the icon colour manually based on the value?

Set up a binary template sensor, instead of a sensor. Only binary entities (switch, input_boolean, binary_sensor) change colour. Add a device class to have the state labels change in the front end.