Motion Detected in One Room to Turn Off Lights in Another Room


(Liem) #1

I’ve seen the lights follow me SmartApp but I was wondering if there’s a way to turn off a light when motion is detected? The idea is when I walk into the bedroom, I want the motion detector in the bedroom to turn the lights off in the living room and also to turn the lights on in the bedroom.


(Convinced ST will never be unbroken…) #2

Code sample:

preferences {
      section("When there's movement...") {
          	input "motion1", "capability.motionSensor", title: "Where?", multiple: true
          }
          section("Turn on a light...") {
          	input "switchesOn", "capability.switch", multiple: true
          }
          section("Turn off a light...") {
          	input "switchesOff", "capability.switch", multiple: true
          }
    }
    
    def installed()
    {
    	subscribe(motion1, "motion.active", motionActiveHandler)
    }
    
    def updated()
    {
    	unsubscribe()
    	subscribe(motion1, "motion.active", motionActiveHandler)
    }
    
    def motionActiveHandler(evt) {
    	switchesOn.on()
    	switchesOff.off()	
    }

(Edward Pope) #3

Note: As I have tried this. If you live by yourself, this works. But, if you have family or friends over at night… Well you can see the complication that this causes (SMILE)


(Liem) #4

@scottinpollock
Thanks Scott!
It works great. I have it setup to only run when I’m in “Home Alone” mode. If my wife and I are both home, or if we have guests over the motion in the master bedroom doesn’t trigger the off switch in the living room.