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.
-
Contact opening
-
Motion opening
-
Manual click on
-
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.