Turn off lights when multiple motion sensors have different states


(Joe) #1

is there any way to say after motion stops on a set of motion sensors, check another motion sensors in a different room. If room 2 motion sensors has motion turn off light in room 1.

So room 1 turns on with motion and will turn off with no motion after 30 minutes. Unless room 2 has motion and room 1 has NO motion on 3 different motion sensors, in which case the lights will shut off in room 1 in 10 minutes.
Then if motion is detected in room 1 before the 10 minutes is up the motion will reset the timer to 30 minutes.

The ultimate goal is to turn off the lights sooner in room 1 if another room is occupied and room 1 isn’t.

Am I over thinking this?


(Bruce) #2

Maybe, depends. First thing you might try is a much shorter time period for turning off after motion stops. Most of mine are only 2 minutes, and it rarely turns off when it shouldn’t. That would obviously reduce the need for what you’re asking about.

What you are suggesting is certainly doable, but would require a custom app to do it. Get back if that’s what you decide you need, it would be fairly simple to do.


(Jody) #3

I have been trying to figure out something similar to your idea @Keo, but I would also like to take presence into account.

If there is only one person present, then turn off all of the lights in the rooms that are not the one where motion was most recently detected. If there is more than one person default back to timers or it gets fairly complicated. I have been whiteboarding this one for a while now.


(Joe) #4

I’ve tried shorter time periods and more sensors, but I still have blind spots in my room which causes the lights to turn off while someone is in the room, So the only thing I can come up with is to set a longer off timer and then overriding it.


(Bruce) #5

Why not just add an additional motion sensor so the room is fully covered?


(Joe) #6

The two rooms are open concept. So if I place a sensor in the wrong place it registers the motion in the wrong room.


(Bruce) #7

Ahh, I understand. I have areas like that where I don’t even go there with motion sensors.

So, that leaves you with the custom app option as one approach:

You’d select Room 1 motion sensors, and Room 2 motion sensors. The conditions to test are (a) all Room 1 sensors quiet for x minutes, AND (b) motion in Room 2 active.

I can whip that up for you in little bit. You’d keep your existing automation for Room 1. This would augment it with the Room 2 turn-off.


(Bruce) #8

Here is the little app that does this:

/**
 *  Turn off after motion stops and second motion starts
 *
 *  Copyright 2015 Bruce Ravenel
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
    name: "Turn off after motion stops with second motion",
    namespace: "bravenel",
    author: "Bruce Ravenel",
    description: "Turn off some switches minutes after motion stops and there is motion in a second room",
    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 Room 1 Switches, Motions and Minutes") {
		input "switches", "capability.switch", title: "Switches", required: true, multiple: true
		input "motions", "capability.motionSensor", title: "Motions", required: true, multiple: true
		input "minutes", "number", title: "Minutes", required: false
	}
    
    section("Select Room 2 Motions") {
    	input "motions2", "capability.motionSensor", title: "Motions", required: true, multiple: true
    }
}

def installed() {
	initialize()
}

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

def initialize() {
	subscribe(motions, "motion.active", activeHandler)
	subscribe(motions, "motion.inactive", inactiveHandler)
	state.pending = false
}

def activeHandler(evt) {
	state.pending = false
}

def inactiveHandler(evt) {
	def noMotion = true
	motions.each {noMotion = noMotion && it.currentMotion == "inactive"}
	if(noMotion) {
		state.pending = true
		if(minutes) runIn(minutes*60, switchesOff) else switchesOff()
	} else state.pending = false
}

def switchesOff() {
	if(state.pending && "active" in motions2.currentMotion) switches.off()
}

(Joe) #9

Thanks! I’ll try it out tonight.


(Joe) #10

It doesn’t appear to be working. After motion ends in room 1 and motion is seen in room 2 the lights do not turn off after 5 minutes.


(Bruce) #11

Check the PM I sent you…