SmartThings Community

Turn On Switch When Only One Particular Presence is Detected and No one Else is Home


(Patrick Musselman) #1

I am hoping that someone can once again point me in the right direction. I am looking for an app that will activate switches based on if only one particular presence is detected. I have a set of Lorex cameras that don’t integrated with SmartThings nor much else really. I have set those cameras up with a smart switch outlet to come on when no one is present. Works great as I don’t have to keep them on all the time and will not receive Lorex motion and image notifications when the house is occupied. However, as an extra security/monitoring measure I would like those switches to be active if a particular person is present. My first thought was to do it with modes but I already have a complex set of modes and I don’t want to complicate it further. If there is an Smart App out that can do this can someone please tell which one. I have searched and have not had much success. Thanks!


(Andy Rawson) #2

If you don’t have it already add the “Lights and Switches” Dashboard and then add that switch to the dashboard and one of the actions for it will be “Turn on when people arrive” then pick the person and that should work for what you want I think.


(Patrick Musselman) #3

Thanks. I will give that a try. I was under the impression that it would turn on the switches even if that particular person was home and other people were as well. So for example, Person A is the one particular person I want to monitor only when no other presence is detected. If Person A arrives with Person B will the switches turn on? I would guess yes but I might be wrong. In my scenario, I don’t want the switches on when Person A, B and C are presence. Only when Person A is presence and Person B and Person C are not present. That might be a better way to explain it.


(Bruce) #4

You’re right about Lights & Switches, and how it works. You will need a small SmartApp to do what you want. The way it could work is with a virtual switch. Have ST turn on that switch when Person A arrives. The virtual switch fires the app, which examines the presence of Person B and C, and turns on the light if they are not present, but not otherwise.


(Bruce) #5

Here is a small app that turns on a light when only one person arrives, who must be there alone. It does not use a virtual switch, just the presence sensors.

/**
 *  One Person Light
 *
 */
definition(
    name: "One Person Light",
    namespace: "public",
    author: "B Ravenel",
    description: "Turn on a light when only one person is home",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")


preferences {
    section("Select the switch to turn on") {
    	input "switches", "capability.switch", title: "Which switch(es)?", required: true, multiple: true
    }
    section("Select the single presence for On"){
    	input "person", "capability.presenceSensor", title: "Which presence?", required: true
    }
    section("Select the other presences") {
    	input "others", "capability.presenceSensor", title: "Which presences?", required: true, multiple: true
    }
}

def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(person, "presence", personHandler)
}

def personHandler(evt) {
	if(evt.value == "present") {
    	    def alone = true
            others.each {alone = alone && it.currentPresence == "not present"}
            if(alone) switches.on()
        }
}

(Patrick Musselman) #6

Thanks, I will give this a try!


(Darin) #7

Sounds like someone has a teenager. Just a guess though :smile:
Been there…


(Patrick Musselman) #8

Yup. Person B and C = Mom and Dad and Person A = Teenage Son. He is a great kid and we have a lot of trust in him. We are blessed to be so lucky. But I know how I was as a teenager… :open_mouth:


(Patrick Musselman) #9

I found a simpler way of doing for the not so coding inclined type like myself. :sunglasses:

I had to create two rules.

The first rules is to activate the switches when Person A or Person B leave while Person C is Present:
if any of these happen:
Person A Leaves
Person B Leaves

while ALL of these things are true:
Person A Is Not Present
Person B Is Not Present
Person C Is Present

then do these:
turn on x
turn on y
turn on z

Second rule is toe deactivate the switches on arrival of either Person A or Person B:
if any of these happen:
Person A arrives
Person B arrives

while ALL of these things are true:
blank

then do these:
turn off x
turn off y
turn off z

Pretty neat. Tested this afternoon with success!


(SFBayArea) #10

I was looking for similar thing. However, I am super new to the ST and the forum. I still can’t figure out what to do with this code? How do you enter this app/code into ST?


(Bruce) #11

Steps:

Login to IDE at https://graph.api.smartthings.com
Click on My SmartApps
Click on New SmartApp, then From Code tab
Copy and paste the code from above, then click on Create
Click on Publish / For Me

At that point the app will be available on your mobile device. Go to the far right lower icon, then click on SmartApps. Scroll to the bottom to My Apps, then scroll to the app. Then you can install it, selecting the presences and switches.


(Patrick Musselman) #12

In the SmartRules iOS app use the rules I created above. If you have not installed SmartRules I think there are instructions to connect with ST.


#13

This might help: