Create Binary Sensor for Door Sensors Recently Opened

I have a bunch of Philips Hue door sensors and I’d like to use them for automations. However, the default sensors stay in a state of open / closed. I’d like to add binary sensors that indicate whether or not the doors were recently opened or closed. Is there any way to loop through them to provide the binary sensors that turn off after a given time period?

Thanks in advance!

Apologies in advance if I have misunderstood your requirements, but I have template binary sensors created for similar, as I have doorbell cameras with notification, I wanted to disable the notifications for when the door is either open or has recently been opened to prevent it from triggering when either the door is left open OR more importantly when we are leaving and have just shut the door behind us.

I created several binary sensors as follows:

- name: front door has been open
  state: "{{ is_state('binary_sensor.front_door_contact_ias_zone', 'on') }}"
  delay_off: 00:03:00
  unique_id: 0706222
  device_class: door

These sensors will then read as open if the door is either open or has been closed in the last 3 mins.

As we have several rear door that we go through when coming and going from the house we also created a group containing all relevant rear door template sensors.

1 Like

Thanks. I tried adding this to configuration.yml but I’m seeing some errors. Am I doing something wrong?

It will need to go under templates as it’s a template binary sensor, also don’t forget to make sure you have the correct entity for your given sensor/s.

template:
  - binary_sensor:
    

It seems like the entity remains open even after the time out. Is this the correct behavior? It doesn’t seem to change to Closed after the delay.

That worked thanks. I just tried asking ChatGPT and this is what it came up with:

template:
  - binary_sensor:
      - name: "Door Opened Recently"
        state: >-
          {{ states('sensor.door_state') == 'open' and 
             (as_timestamp(now()) - as_timestamp(states.sensor.door_state.last_changed)) <= 30 }}
        availability: >-
          {{ states('sensor.door_state') not in ['unknown', 'unavailable'] }}