The lock you forget is the one on a night you were tired. This recipe takes the last check of the night off your list: at the time you set, it locks every smart lock you pick. Set it for when the house is normally settled, eleven at night by default, and move it to suit your household.
Locks and nothing else is all it needs. It runs on your own locks with no cloud in the loop, and it never unlocks anything, so it only ever adds security, never takes it away.
Not locking against an open door
Throwing a deadbolt while a door is still open can jam the bolt or leave it sticking out against the frame. Add your door contact sensors as the optional role and the recipe checks them first. If a door is open at lock-up time it holds off and sends you a notification rather than forcing the bolt, then locks up on its own the moment the last door is shut, any time up to the early hours.
Because it locks as soon as the doors are shut through the night, a door opened to let a pet out and closed again locks behind it. If someone is still outside when the door closes, they will need their key or code, so keep that in mind for late arrivals.
Files Selora AI's pipeline reads to install this recipe. The manifest declares roles, inputs, and integrations; the package files are Jinja-templated YAML applied to Home Assistant.
# Auto Lock at Night — lock the selected locks at a set time each night, and,
# when door sensors are picked, hold off while a door is open and lock once it
# is shut.
#
# The lock role is multi-select. Optional door sensors change the behaviour: at
# lock-up time a choose either locks (all doors shut) or notifies (a door
# open), and a second automation locks up when the last door closes during the
# night window. Without door sensors the recipe simply locks at the time.
slug: auto-lock-at-night
version: 1.0.0
title: Auto Lock at Night
tagline: Every smart lock secures itself at the time you set, holding off only while a door is still open.
description: >-
Locks the smart locks you pick at a set time each night. Add door sensors and
it holds off while any door is open, notifies you, then locks the moment the
last door is shut, any time through the night window.
author: Selora AI
released: "2026-08-28"
min_integration_version: "0.12.0"
tags: [security, locks, night]
roles:
# Locks to secure — multi-select. kind lock. min_count 1.
- id: locks
title: Smart locks
kind: lock
min_count: 1
selection: required
description: >-
The locks the recipe secures each night. They all lock together.
# Optional door sensors so the recipe does not lock against an open door.
- id: door_sensors
title: Door sensors
kind: binary_sensor
device_class: door
min_count: 0
selection: required
description: >-
Optional. Door contact sensors. When any door is open at lock-up time the
recipe holds off and notifies, then locks once every door is shut. Leave
empty to lock at the time regardless.
inputs:
# The nightly lock-up time.
- id: lock_time
type: string
label: Lock-up time
description: >-
The time every night the locks secure themselves.
default: "23:00:00"
# End of the window in which a door closing re-locks the house, used only when
# door sensors are picked. From lock_time to this time, shutting the last
# door locks up.
- id: relock_until
type: string
label: Re-lock window ends
description: >-
With door sensors picked, shutting the last door locks up any time from
lock-up time until this time.
default: "05:00:00"
package_files:
- package/automations/night_lock.yaml.j2
{# Auto Lock at Night.
Without door sensors: one automation locks every lock at lock-up time, or at
startup if that time passed while Home Assistant was down.
With door sensors: the lock-up automation uses a choose, locking only when
every door explicitly reads shut and notifying otherwise, so a sensor that is
unavailable holds the lock rather than being read as a closed door. A second automation locks up
when the last door closes anywhere in the night window (lock_time until
relock_until), which catches the door that was open at lock-up time and a
door opened and shut later in the night. #}
{% set su = slug | replace('-', '_') %}
automation:
- id: selora_recipe_{{ su }}_night_lock
alias: "Auto Lock at Night: lock up"
description: >-
At lock-up time, lock every smart lock, holding off if a door is open.
mode: single
trigger:
- platform: time
at: "{{ inputs.lock_time }}"
# A time trigger that passes while Home Assistant is down is gone, not
# replayed. Without this, a restart spanning lock-up time leaves the house
# unlocked until the following night, and with no door sensors picked
# there is no second automation to catch it. The night-window condition
# below is what makes replaying safe: it is already true at lock-up time,
# so the normal path is unchanged, and it stops a restart at noon locking
# the house mid-day.
- platform: homeassistant
event: start
condition:
- condition: time
after: "{{ inputs.lock_time }}"
before: "{{ inputs.relock_until }}"
action:
{% if roles.door_sensors %}
- choose:
# Hold off unless every sensor explicitly reads shut. An or over
# state: "on" only caught the doors it could read: a contact sensor
# sitting at unknown or unavailable, with its door standing open, fell
# through to the default branch and the deadbolt was thrown against an
# open door. For a lock-up gate an unreadable sensor has to hold.
- conditions:
- condition: not
conditions:
- condition: state
state: "off"
entity_id:
{% for door in roles.door_sensors %}
- {{ door }}
{% endfor %}
sequence:
- service: notify.notify
data:
title: "Not locked yet"
message: "It is lock-up time but a door is still open, or a door sensor is not reporting, so the locks were left. They lock once every door reads shut."
default:
- service: lock.lock
target:
entity_id:
{% for lock in roles.locks %}
- {{ lock }}
{% endfor %}
{% else %}
- service: lock.lock
target:
entity_id:
{% for lock in roles.locks %}
- {{ lock }}
{% endfor %}
{% endif %}
{% if roles.door_sensors %}
- id: selora_recipe_{{ su }}_lock_on_close
alias: "Auto Lock at Night: lock when doors shut"
description: >-
During the night window, lock up once the last door is shut.
mode: single
trigger:
{% for door in roles.door_sensors %}
- platform: state
entity_id: {{ door }}
to: "off"
{% endfor %}
condition:
- condition: state
state: "off"
entity_id:
{% for door in roles.door_sensors %}
- {{ door }}
{% endfor %}
- condition: time
after: "{{ inputs.lock_time }}"
before: "{{ inputs.relock_until }}"
action:
- service: lock.lock
target:
entity_id:
{% for lock in roles.locks %}
- {{ lock }}
{% endfor %}
{% endif %}