Smart Bathroom Occupancy Light Control (Hornet-in-the-Box Principle)
What is the “Hornet in the Box” Principle?
If a hornet enters a closed box – it’s trapped. If the box opens – it’s gone. Now apply that logic to your bathroom.
This blueprint automates lights in bathrooms or toilets using door and motion sensors with pinpoint accuracy.
When the door closes, and motion is detected, someone is inside. When the door opens, and no motion follows, it’s safe to say it’s empty. It uses a helper entity to track occupancy reliably.
Why Use This Blueprint?
Other occupancy blueprints do not check whether the door is opened but this does for reliability.
Doesn’t need fancy hardware – just simple binary sensors
Light turns off only when you’re sure the bathroom is empty
How It Works – Scenarios
Entering:
Door opens → Lights turn on
Motion detected → “Occupied” status activates (lights stay on until you leave)
No rain dances needed - lights won’t turn off while you’re inside!
Exiting:
Door opens → System waits for motion to clear
No motion detected → Lights turn off
Smart edge cases:
Open/close door without entering → Lights turn off immediately
Forget to close door → Lights turn off after motion clears
How It Works (A liltte bit detailed)
Door opened, and no one was previously inside
→ Light turns on, waiting to see if someone enters.
Motion detected, but helper was off (first confirmation of entry)
→ Someone entered. Mark bathroom as occupied.
Motion detected while door is closed (fully confirmed entry)
→ Occupied. Light is turned on and occupancy is set.
Door opened, helper says “occupied” → wait for motion to stop
→ After motion clears, turn off light and reset occupancy.
Motion stopped while door is open, and someone was inside
→ Turns off light and clears the occupancy state.
Door closes, but no one was inside (false open/close)
→ Light turns off instantly.
Motion Sensor Tips
Placement is key: The motion sensor should not be triggered by someone just walking past the door or standing outside. Ideally, install it on the ceiling or corner inside the room, angled away from the door.
Cooldown (clear delay): Recommended 10–15 seconds to ensure smoother transitions and avoid flickering.
Use Cases
Automate bathroom lights/fans
Smart occupancy-based nightlights
Boost energy savings in shared homes
Set up alerts if bathroom is “occupied too long” (via the helper)
I created this blueprint thinking that you would close the door after leaving the bathroom. However, if the door does not close, it turns off the light. However, I think there is a small bug. I will update it as soon as possible.
For now, turn off the automation if you want, or get into the habit of closing the door when you leave
Wow, this looks promising! I’ve also spent a lot of time designing an automation for our bathroom lights (not on HA, though, on a different system) and I know how tricky it is to include all the edge cases.
The first thing that comes to mind is that many motion sensors don’t detect motion continuously but once they detected motion, they won’t detect new motion for a certain time period, e.g. 30 seconds. In practice, this means that you can never assume that you really know the state of the room at any particular moment. You always have to wait at least 30 seconds before you can tell. For example, some opens the door, and makes a quick step. Usually, this will trigger the motion sensor, telling you that someone has entered. However, if that person leaves again after a second and closes the door and another person within 30 seconds opens the door again and enters, no motion will be detected for almost 30 seconds.
Have you considered this in your logic?
Another one of my favourite pitfalls is that here is also a light switch that some people may use. This led to the following situation: when someone turns off the light before they open the door, opening the door would turn the light back on. I think I solved this by turning the door sensor off once the light is on and turning it back on 15 seconds after the light goes off. But even that is not completel fail proof, because it does happen that someone turns off the light, leaves the room but within 15 seconds, someone enters the room again. In that case neither the door sensor will turn on the light (because it is still deactivated) nor the motion sensor (because it is probably still set to “motion detected” from the previous occupant) so that the new entry won’t be registered until up to 30 seconds later…
First of all, I set the cooldown time of the zigbee motion sensor to 10 seconds. I thought that reducing this time would make the automation check more frequently and give more stable results. Also, when I use the automation, I put the switch in detach mode.
In this blueprint, the automation predicts that the door will close within 6 seconds after motion is detected. If motion is detected after someone opens the door and the door is closed within the next 6 seconds, it means the room is occupied.
It is also important that the motion sensor does not detect the door when it is opened. Therefore, the position of the motion sensor should be such that it does not see the door.
As you said, this type of automation is complex and difficult. I am trying to decide whether there is someone inside by closing the door.
I have encountered some bugs even in this. That is why I am still in the development phase. In some cases, people in the house complain that the light does not turn on or goes off while they are inside. I think the usage after the door is left open causes problems.
This looks interesting and I’ll certainly try it with our bathrooms.
My current automation turns on the light with both door opening and motion. So if you open the door and enter, the door opening will turn on the light. However, if the door is already open and you enter, motion will turn on the light. If you then close the door, the light will stay on indefinitely (door contact sensor is used as a condition to keep the light on).
However, if you walk in and the light turns off, if you then walk out and close the door, the light will stay on indefinitely so we end up having to turn the light off manually. Our motion sensor is underneath wall cabinet and detects motion as soon as you enter, but yes, the door contact will always operate first if the door is closed. The other issue I’ve had is when you’re in the bathroom with the light off and door closed and you open the door to leave, the light will come on. Our bathrooms all have windows so I also have a light level condition that must be met before the light turns on. Is there provision in this blueprint for such a condition or is it a basic light on/light off no matter what the ambient light level is?