Hope someone’ll find this helpful. I finally got around to using a timer rather than scripts with delays to handle re-locking my front door. I’ve got a zwave lock on the door and use the Eanvisalink component to tell when my front door is opened. I also have an input_boolean to keep track of whether I’ve got a house guest (keeps the system from locking my inlaws out, etc). You can adapt the details to fit your situation.
- alias: Start Front Door Autolock Timer
trigger:
- platform: state
entity_id: lock.front_door_deadbolt
to: 'unlocked'
- platform: state
entity_id: binary_sensor.front_door
to: 'off'
action:
- service: timer.start
entity_id: timer.front_door_lock
data:
duration: '00:05:00'
- alias: Pause Front Door Autolock Timer
trigger:
- platform: state
entity_id: binary_sensor.front_door
to: 'on'
action:
- service: timer.pause
entity_id: timer.front_door_lock
- alias: Cancel Front Door Autolock Timer
trigger:
- platform: state
entity_id: lock.front_door_deadbolt
to: 'locked'
action:
- service: timer.cancel
entity_id: timer.front_door_lock
- alias: Auto Lock Front Door
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.front_door_lock
condition:
condition: state
entity_id: input_boolean.house_guest
state: 'off'
action:
- service: lock.lock
entity_id: lock.front_door_deadbolt