Disable lights turn off when motion stops


(Joe) #1

Hi all,

I am looking for an app that will turn a light on with motion and off when motion stops, unless the switch is turned on manually. If the switch is turned on manually, the motion off event will be disabled or increased.

I thought there was an app like that, but my search returns nothing. Does anyone else remember an app like that?


#2

I think both @bravenel and @baldeagle072 have done something similar, maybe they can chime in. :sunglasses:


(Bruce) #3

Yes, I’m sure I’ve written this or one similar a few times. Below is a small app that simply disables motion-off if the switch was turned on BEFORE there was any motion. If your use case is different than that, this won’t work. To re-enable the normal functioning of motion-off, you simply turn the switch back off again when you leave the room.

This uses a virtual switch. You need to create one in the IDE (lots of instructions around here by @JDRoberts). Then you replace your real switch in the motion-on and motion-off apps with the virtual switch; and you install this app, selecting the virtual switch and the real switch.

    /**
     *  Disable Motion Off
     *
     *  Copyright 2014 Bruce Ravenel
     *
     */
    definition(
        name: "Disable Motion Off",
        namespace: "bravenel",
        author: "Bruce Ravenel",
        description: "Use a stand-in to prevent motion off",
        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")
    
    
    preferences {
    	section("Real Dimmer...") { 
            input "realswitch", "capability.switch", 
    	    title: "Real Switch...", 
    	    required: true
    	}
        section("Virtual Stand-in...") {
            input "standin", "capability.switch",
            title: "Stand-in Virtual Switch...",
            required: true
        }
    }
    
    def installed() {
        initialize()
    }
    
    def updated() {
    	unsubscribe()
        initialize()
    }

    def initialize() {
    	subscribe(standin, "switch.on", switchOnHandler)
        subscribe(standin, "switch.off", switchOffHandler)
        state.motionEnabled = true
    }
    
    def switchOnHandler(evt) {
    	state.motionEnabled = realswitch.currentSwitch == "off"
        if(state.motionEnabled) realswitch.on()
    }
    
    def switchOffHandler(evt) {
        if(state.motionEnabled) realswitch.off()
    }

(Joe) #4

It’s really close. The room entry has the switch across the room so there’s no way to enter the room without triggering motion. So I have a motion sensor to turn on the lights when you enter the room. I’d like to be able to tap the switch again while in the room to disable the off event.


(Joe) #5

Looks like @bravenel already had a solution for this here

Motion sensors, phrases, and scheduled events

I may be able to use this suggestion with the switch changes mode option.


(Bruce) #6

In general, this is not going to work. The problem is that once the light has been turned on by motion, the switch will not throw an event from being “turned on manually”, because it is already on. It’s even dicey when the switch is outside the room in question, because of the lag in ST seeing the switch-on event from a physical switch – unless it’s an instant reporting switch (e.g. Leviton VRMX1).

You would need some other method to tell the system to disable motion-off, e.g. a Minimote button push could do it.


(Joe) #7

I’ve rethought how I am doing things. So here is my setup. My kitchen has different switches for sets of lights. I have the main kitchen, The Breakfast Bar/sink, and the dining room. I have a motion sensor that turns on the kitchen lights and turns them off after 10 minutes. What I would like to do is stop the lights from turning off when I turn the breakfast bar on.

Can this be done with your app?


Using a virtual switch to control room specific mode?
(Bruce) #8

Not that app as written, but a very similar app could be made to work. You will still need a virtual switch. When you install this app, you will select the virtual switch, the real switch (kitchen main), and the disabler switch (breakfast). Replace you kitchen main in the motion on/off apps with the virtual switch.

The only question I have is how do you want to indicate to “go back to normal”? One way would be to turn off the breakfast bar, another would be to turn off the main kitchen, and a third way would be either of the first two. I implemented the latter option below (n.b., I have not had an opportunity to test this):

/**
*  Disable Motion Off
*
*  Copyright 2015 Bruce Ravenel
*
*/
definition(
	name: "Disable Motion Off",
	namespace: "bravenel",
	author: "Bruce Ravenel",
	description: "Use a disable switch and stand-in to disable motion off",
	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")
    
    
preferences {
	section("Real Switch...") { 
		input "realSwitch", "capability.switch", title: "Real Switch...", required: true
	}
	section("Virtual Stand-in...") {
		input "standinSwitch", "capability.switch", title: "Stand-in Virtual Switch...", required: true
	}
	section("Disabler Switch...") {
		input "disableSwitch", "capability.switch", title: "Disabler Switch", required: true
	}
}
    
def installed() {
	initialize()
}
    
def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(standinSwitch, "switch.on", switchOnHandler)
	subscribe(standinSwitch, "switch.off", switchOffHandler)
	subscribe(disableSwitch, "switch.on", disableHandler)
	subscribe(disableSwitch, "switch.off"), resetHandler
	subscribe(realSwitch, "switch.off", resetHandler)
	state.motionEnabled = true
}
    
def switchOnHandler(evt) {
	realswitch.on()
}
    
def switchOffHandler(evt) {
	if(state.motionEnabled) realswitch.off()
}

def disableHandler(evt) {
	state.motionEnabled = false
}
	
def resetHandler(evt) {
	state.motionEnabled = true
}

(Joe) #9

I’ll configure this later tonight and see how it goes. Thanks!!!