I am looking for a way to send a notification if the front door has been left unlocked for more than 10 minutes. I have a version that triggers right at 8:30pm with a condition of door unlocked, but if the door later gets unlocked then it won’t re-trigger.
What I think I want is something like this:
- alias: "Front Door Left Unlocked at Night"
trigger:
- platform: state
entity_id: lock.front_door_lock_locked
state: 'unlocked'
for:
minutes: 10
action:
...
This fails with [state] is an invalid option for [automation].
I have also tried:
- alias: "Front Door Left Unlocked at Night TEST"
trigger:
- platform: template
value_template: "{{ (as_timestamp(now()) - as_timestamp(states.lock.front_door_lock_locked.last_updated)) > 60 }}"
action:
I can plug the template into the debugger and it shows True when appropriate, but doesn’t seem to fire.
[ Those last 2 would need a condition to make sure it’s unlocked, but if I can get the trigger to work then I should be able to work out the conditions. ]
Clearly I’m not thinking about it quite correctly. Has anyone done anything like this? Or can you recommend a general approach to the issue?
I’m doing something very similar to check for any door left open; The warning is announced every 20 seconds until all doors are closed. It checks often, every 20 seconds, for any doors left open for more than 30 seconds because we don’t want the dog to escape which has happened several times when the kids didn’t close the doors all the way. He hasn’t escaped since I implemented this! The alert can be disabled by turning off input_boolean.door_alert.
- alias: "Doors Left Open"
initial_state: true
trigger:
platform: time
seconds: '/20'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.door_alert
state: 'on'
- condition: state
entity_id: binary_sensor.security_zones_open
state: 'on'
for:
seconds: 30
action:
- service: script.sonos_say
data:
entity_id: media_player.portable, media_player.foyer, media_player.gym, media_player.familyroom1
message: 'Warning! Entry doors are open!'
Clearly I was waaaay over thinking it. The State trigger docs showed a from: and a to: which made me think the for: would only trigger after a transition between them.
I was considering a repeating time like that, but the action section actually includes setting a light to red, waiting until the lock is locked, then turning the light off. I figured the time trigger would happen every N minutes and the actions would end up fighting. But thanks for the example, it’s always useful to see more of those.