I wrote this SmartApp because I wanted a way for my house to always know which room I was in without using timed delays.
When setting up a room you can specify lights, but since it uses virtual presence sensors, you can setup complex automatons based on the room you in using other SmartApps like CoRE or Rule Machine.
This SmartApp has a lot of limitations so I doubt anyone else will find it useful, but I figured since I’ve been using it to control all my lighting for several months, I might as well post the code.
These are the main reasons why this SmartApp won’t work for most people:
It only works when there’s one person can be in the house.
A Virtual Presence Sensor needs to be manually created for each room.
Each room has to have either a Contact Sensor on the door or a Motion Sensor within it.
Using Motion Sensors to detect presence:
When a motion sensor detects motion it sets that room’s Virtual Presence Sensor to present. If other rooms are present, it waits for the motion sensor in the other room to become inactive before setting it to not present to ensure you didn’t go back into that room.
Most motion sensors require at least 15 seconds of inactivity before they’ll trigger another motion event so you have to specify that interval when creating a room. When you exit one room and enter another, both motion sensors will show motion so it uses the specified interval to determine which room is active.
Detecting room presence by motion isn’t exact so if there’s a contact sensor involved, the contact sensor will determine which room is present.
Using Contact Sensors to detect presence:
When you setup a room that has a contact sensor, you have to choose one of the 4 options for determining presence:
Open - The room is set to present while the door is open.
Closed - the room is set to present while the door is closed.
Toggle Open - When you open the door, the room is set to present and it gets set to not present the next time the door is opened.
Toggle Closed - When you close the door, the room is set to present and it gets set to not present the next time the door is closed.
Here are a couple of examples of how I’m using the presence for other things:
When I open and shut the door to go into my basement, the basement disarms and lights turn on and they stay that way until I open the door again to leave.
Different devices are used to play notifications depending on which floor I’m on.
I wasn’t aware that someone had already created a similar SmartApp with a similar name until I created this topic.