Some hardware links on this page are affiliate links. As an Amazon Associate I earn from qualifying purchases. We may earn a commission if you buy through them, at no extra cost to you. See the affiliate disclosure.
Presence lighting that turns the light straight back on after you switched it off is why people uninstall the automation. This one still turns the light on when the room becomes occupied, and off after it has been clear. If you turn that same light off by hand while the room is occupied, it stays off until the room has been clear for a set time and someone comes back. Nothing is written to a helper. The decision uses the light entity’s last change and whether an automation caused it.
Use one light, or one light group. A group of unrelated bulbs makes last_changed mean “any of them,” and the lock gets muddy.
A lux-gated occupancy light that does not remember a manual off is occupancy lighting. Holding the room occupied until the door opens is wasp-in-a-box occupancy. Presence that only counts after the door, with no manual-off rule, is door-gated presence.
What problem it solves
You want the room light to follow presence, and you want the wall switch to win when you turn it off on purpose.
How it works
- Occupied. The presence binary sensor turns
on. The light turns on at the day or night brightness, unless the lux gate says the room is already bright, or the manual-off lock is set. - The lock. It applies only when presence just came from
off(a return, not a sensor that was already on). The light must be off. That off must have happened at or before presence went off, so it happened while the room was still occupied. The light’s context must have no parent id, which is what a wall switch or a dashboard toggle looks like. Another automation sets a parent id, and that off does not lock. The clear gap must also be shorter than Forget a manual off after (default 10 minutes). A longer absence forgets it and the next entry turns the light on. - Why this automation’s own off is not a lock. The clear path turns the light off only after presence has already been
offfor the clear timeout. That off is newer than the moment presence went off, so the timestamp test does not treat it as a hand-off. It also has a parent id. - Clear. Presence
offfor N minutes (default 5) turns the light off. - Lux. Optional. If you pick an illuminance sensor and it is a number above the threshold, the light does not turn on.
unknownandunavailabledo not block. Leave the sensor empty to skip the gate. - Night.
sunuses the sun entity.clockuses the two times, and a start later than the end wraps past midnight.
The automation is queued and does not wait around, so a clear timeout is not stuck behind a long delay.
Snippet
The lock is a template on the occupied trigger. light_entity is the light input.
{% set st = states[light_entity] %}
{% set parent = st.context.parent_id %}
{% set gap = as_timestamp(trigger.to_state.last_changed) - as_timestamp(trigger.from_state.last_changed) %}
{{ st.state == 'off'
and st.last_changed <= trigger.from_state.last_changed
and parent in [none, '']
and gap < (manual_clear | int * 60) }}
Setup outline
- Copy
blueprints/automation/presence_light_manual_off.yamlintoconfig/blueprints/automation/edotdev/and reload blueprints. - Create the automation. Pick the presence sensor and one light (or one light group).
- Set the clear timeout to how long the room can be empty before the light should die. Set the manual-off memory to how long a hand-off should keep winning after you leave.
- Leave lux empty unless you have an illuminance sensor. Set night to
sunor to a clock window, and set the two brightnesses. - Walk in. The light should turn on. Turn it off at the switch or in the dashboard while you are still in the room. It should stay off. Step out, wait out the clear timeout, step back in after a short gap. It should still stay off if that gap was under the manual-off memory. Stay out longer than that memory, then come back. It should turn on.
Troubleshooting
- A manual off turns the light straight back on. The off did not land on the same entity this blueprint watches, or another automation turned it off (that one has a parent id, so it is not treated as manual). Point the blueprint at the entity you actually switch.
- The light never comes back. The manual-off memory is longer than the time you were gone, and the light was off before presence cleared. Wait out Forget a manual off after, or shorten it.
- Dashboard off does not lock, but the wall switch does. Some dashboards run through a script, and that script’s context has a parent id. Toggle the light entity itself. A script in the middle looks like an automation.
- It turns on in daylight. Lux is empty, the sensor is
unavailable, or the threshold is above the room. An unreadable lux value does not block, on purpose. - Night brightness is on in the afternoon. Same sun and clock rules as a schedule. Check
sun.sun, or the two clock times. - Two bulbs disagree. You selected one of them, and the other is a different entity. Use a light group as the single entity, and switch that group.
Credits
Making presence lighting leave a manual off alone is covered in Making presence lighting actually smart.