Presence Sensors are simply the superior sensor type—until they also turn your lights on at night!
The Problem
Conventional automations always turn the lights on—no matter the context—unless you add cumbersome conditions such as:
- Time/Daylight Checks: Useless for night owls or early sleepers, as the automation doesn’t sync with your actual behavior.
- Manual Toggles: Disabling automations manually gets annoying and undermines the concept of a smart home.
The Solution
A flexible override logic that detects if a light was turned off by a user or by the automation. If you manually turn off the lights to go to sleep, they stay off, even if the presence sensor detects movement. The automation only resumes control once the light has been cycled or a new “clean” presence event occurs.
Features
- Multi-Light Independence: Add multiple lights; each light is checked individually for its own last state change.
- Helper-Free: No input_boolean or counter entities required. The logic is self-contained.
- Restart-Aware: Features an optional toggle to keep lights off or force them on after a Home Assistant reboot.
The Logic
The automation relies on State Correlation Math. When presence is detected, the blueprint calculates the time delta between two specific events:
- The timestamp of the Presence Sensor last changing to off.
- The timestamp of the Light Entity last changing to off.
If the difference between these two timestamps is within your defined off_delay (plus a small processing buffer), the automation concludes that it was responsible for the last turn-off command and will turn the light back on. If the light was turned off manually minutes before the presence cleared, the timestamps won’t match, the “Handshake” fails, and the light remains off to respect your manual override.
Installation
Personal Notes
This implementation is not perfect, however it has been very stable and incredibly awesome in my personal use thusfar.
I’d love to hear any suggestions / wishes for additions ![]()