Smart Bathroom Lighting 4-Part Solution

Hi folks. I had previously written a single very complex rule paired with a Room Lighting app to control lighting in my bathroom. The WAF requirement for this rule was to turn on the light immediately upon opening the door and keep it on until exit. This rule checked for door opening to turn on light, then checked for door closing to flag that the next opening would turn off the light. A motion sensor would also turn on the light for those cases where the door was already open and she just walked in. The light would not turn off if the door was closed assuming someone was in there, unless we knew they exited already. The lighting levels were controlled by a Room Lighting app set to turn on lights at different levels based on modes and times of day. I triggered the room lighting app using an activator device. It worked beautifully until it didn't. One day it just stopped working. I would post it here, but in my frustration I deleted it and started over with a different approach using 4 separate Rule Machine apps that I am posting here for community amusement and sharing. I can't explain why the old one stopped working. The best I can tell is the activator device stopped working or got corrupted somehow. I triggered the activator manually a few times and it did nothing so I think my theory is valid.

Anyway, what I'm sharing here is a whole different, and I think simpler/better way of solving the problem that avoids using room activators. The goal is to turn on the lights immediately when the door opens, or if the door is already open to turn them on when motion is detected. Then to keep them on if the door is closed, and turn them off if the door is opened again upon exit. The hard part is edge cases have to be handled such as opening the door and not closing it behind you to just brush your teeth, and then walking out. Also, I have a wall switch that acts as a button that can be tapped or double tapped to manually control the lights. Finally, if no motion is detected for a long time the lights go out. I didn't handle the edge case of opening the door and then changing your mind and not going in. Maybe in a future update.

I wrote 4 different rules. 1) contact opening; 2) motion detection; 3) manual on via doubleTap; and 4) manual off via Tap or doubleTap. All four are posted below for your entertainment. I utilize a hub variable to signal that the door was closed after entry or manual doubleTap used to turn on.

  1. Contact opening

  2. Motion opening

  3. Manual click on

  4. Manual click off

Has anyone else done anything like this? How did you handle your edge cases? I'd love to see other more elegant solutions to this use case.

My bathroom automations were among the first I did and I used Simple Automation.
I think they work well...enough.

I have to close the door for the lights and fan to stay on, otherwise they shut off.
I have to keep the door open when I leave, otherwise they stay on, lol.
To me, that's not a big deal.

HOWEVER, for all my motion sensor/light combos, I have a switch nearby, preferably the switch that is being controlled, that does double duty to disable the motion sensor. The light on my GE/Jasco toggle switches goes on to indicate the status. A triple tap up usually disables motion, and triple tap down re-enables it.

I have the cycle time as short as possible, maybe 10-15 seconds, so it's pretty obvious.

So, if I want to close the door to the bathroom behind me without leaving the lights and fan on, I have to triple tap first. It gets canceled out when the door is opened in this case.

It's hard to think of every scenario, and you become trained to use the system. :slight_smile:

edit: I just looked: I do have a rule that turns off the lights/fan after an hour of no motion.
edit2: The fan can be set to run 5,10 or 15 minutes by taps on a toggle upon leaving