Creating an automation to announce the door is now closed is a simple task but wouldn’t be ideal. It would notify you every time the door was closed, even if it wasn’t left open for more than 5 minutes.
We can’t simply use a ‘for 5 minutes’ in the door-closure automation because we aren’t looking for the door to be closed for 5 minutes.
We want an automation that reports door-closure but only if the door was previously left open for more than 5 minutes.
Start by creating an input_boolean:
input_boolean:
door1_left_open:
name: Door1 Left Open
Modify your existing ‘Door Open’ automation so it turns on the input_boolean when the door opens. I assume the states you are using for sensor.door1
are correct? (‘Open’ and ‘Closed’) It’s usually ‘on’ and ‘off’.
- id: door1_open
alias: 'Door 1 is open'
trigger:
platform: state
entity_id: sensor.door1
to: 'Open'
for:
minutes: 5
condition: []
action:
- service: input_boolean.turn_on
entity_id: input_boolean.door1_left_open
Create a second automation for handling door closure. It turns off the input_boolean but only if it is already on.
- id: door1_closed
alias: 'Door 1 is closed'
trigger:
platform: state
entity_id: sensor.door1
to: 'Closed'
condition:
condition: state
entity_id: input_boolean.door1_left_open
state: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.door1_left_open
Create one more automation that is triggered by the input_boolean. This automation is responsible for announcing Door1 is ‘left open’ or ‘is now closed’.
- id: door1_notifier
alias: 'Door 1 Notifier'
trigger:
platform: state
entity_id: input_boolean.door1_left_open
condition: []
action:
- service: notify.door_notify
data_template:
title: "{{ 'Door1 left open!' if trigger.to_state.state == 'on' else 'Door1 closed' }}"
message: >-
{% if trigger.to_state.state == 'on' %}
Door 1 has been open since {{states.zwave.ecolink_door_window_sensor.attributes.receivedTS}}.
{% else %}
Door1 has been closed.
{% endif %}
I haven’t tested it so it may require additional refinements. However, it should get you started down the right path. You can easily test the notification portion by manually toggling the input_boolean.
EDIT
Fixed typo. Replaced triggered.to_state
with trigger.to_state
in two places.