🚽 Smart Bathroom Occupancy Light Control

:toilet::bulb: Smart Bathroom Occupancy Light Control (Hornet-in-the-Box Principle)


:honeybee: 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.


:wrench: 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

:white_check_mark: 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:

    1. Door opens → System waits for motion to clear
    2. 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)

  1. Door opened, and no one was previously inside
    → Light turns on, waiting to see if someone enters.
  2. Motion detected, but helper was off (first confirmation of entry)
    → Someone entered. Mark bathroom as occupied.
  3. Motion detected while door is closed (fully confirmed entry)
    → Occupied. Light is turned on and occupancy is set.
  4. Door opened, helper says “occupied” → wait for motion to stop
    → After motion clears, turn off light and reset occupancy.
  5. Motion stopped while door is open, and someone was inside
    → Turns off light and clears the occupancy state.
  6. Door closes, but no one was inside (false open/close)
    → Light turns off instantly.

:brain: 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.

:rocket: 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)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

3 Likes

UPDATE

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 :slight_smile:

UPDATED

13.04.2025

:toilet::bulb: Smart Bathroom Occupancy Light Control

A Home Assistant blueprint for intelligent bathroom lighting automation.

:honeybee: 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 principle forms the core of this automation:

  • When your bathroom door closes (the box seals), someone is definitely inside
  • When the door opens again, the space becomes vacant
  • Motion and timing parameters add extra intelligence to handle edge cases

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.


:brain: How It Works

This blueprint combines door sensors, motion detection, and timing logic to create a bulletproof bathroom lighting system that:

  1. Turns lights on when motion is detected or the door opens
  2. Keeps lights on while the bathroom is occupied
  3. Turns lights off when the person exits
  4. Prevents false triggers by cross-validating door position + motion + time delays

Main Scenarios

:man_walking: Entering the Bathroom

  • Door opens → Lights turn on immediately
  • Motion detected → Lights turn on immediately
  • If door closes after motion → Room is marked as occupied
  • If door stays open → Waits for motion to clear before turning off lights

:door: Inside the Bathroom

  • The occupancy helper tracks that someone is in the bathroom
  • Lights stay on regardless of motion detection
  • Perfect for shower situations where motion sensors might not detect movement

:walking_woman: Exiting the Bathroom

  • Door opens → System waits for the exit timeout period
  • Lights turn off after the timeout (giving you time to leave)
  • Occupancy state is reset

:gear: Configuration Options

Parameter Description Default
Door Sensor Binary sensor tracking door state Required
Motion Sensor Binary sensor detecting motion Required
Light The light or switch to control Required
Occupancy Helper Input boolean to track occupancy Required
Door Close Wait Time Seconds to wait for door to close after motion 6
Light Off After Motion Time Seconds before turning off lights when motion stops (door open) 10
Door Open Motion Clear Timeout for lights when entering and exiting with door open 10
Room Exit Timeout Seconds to leave room before lights turn off 10

:shield: Handling Edge Cases

This automation handles various edge cases:

:shower: Shower Scenarios

Since the system uses door closure as the primary occupancy indicator, it won’t turn off lights during a shower when motion might not be detected.

:arrows_counterclockwise: Quick In-and-Out

If someone briefly enters and exits without closing the door, the system will:

  1. Turn on lights when motion is detected
  2. Wait for the configured timeout after motion clears
  3. Turn off lights if no further motion is detected

:hammer_and_wrench: Installation

  1. Import this blueprint to your Home Assistant instance
  2. Create a new automation using this blueprint
  3. Configure the required entities and timing parameters
  4. Create an input_boolean helper to track occupancy state
  5. Test the automation with different scenarios

:test_tube: Why It’s Bulletproof

This automation eliminates common problems with bathroom lighting:

  • No more lights turning off while you’re in the shower
  • No more manually turning lights off when leaving
  • No more fumbling in the dark when entering
  • Handles edge cases that single-sensor solutions miss

:link: Links


Created with :heart: by Murat Çeşmecioğlu

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?

I’ll try your blueprint and see how I get on.