Hello all, I hope that someone might be able to offer advice on how to solve the following use case:
I have a guest bedroom with a GE light switch hooked up to a light as well as a motion sensor. When a guest walks into the room, the GE light switch turns on the light. I then have an app that turns off the light after 5 min’s of no motion. I needed a way to override the motion sensor so if a guest was going to bed they could turn the light off at the GE light switch and motion would stop reactivating the light. I found a smart app on this board that works perfectly for this using a virtual switch, the only issue is it stops motion from turning the light on until someone manually turns the light back on at the GE switch.
What I would like to do is modify this override smartapp to include times. I only want the override to happen after dark, so I want to be able to say the override app will only function after a set time (configurable variable) and then I would want it to disable itself at another set time. So lets say a guest turned the light off manually, the smartapp would disable to motion sensor for the night…but come a set time in the morning, lets say 9AM, the app would enable motion to turn on the light again until a guest turned the light off manually again.
Any advice would be much appreciated!
Here is the code I am using currently to override motion:
definition(
name: “Override Motion Light With Button”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Override Motion Light”,
category: “SmartThings Labs”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
singleInstance: true
)
preferences {
section(“When this real switch is turned off…”) {
input “realSwitch”, “capability.switch”, title: “Guest Bedroom”, required: true
}
section(“This virtual switch helper will disable motion…”) {
input “virtual”, “capability.switch”, title: “Guest Bedroom Virtual Switch”, required: true
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
subscribe(virtual, “switch.on”, virtualOnHandler)
subscribe(virtual, “switch.off”, virtualOffHandler)
state.motionEnabled = true
}
def virtualOffHandler(evt) {
state.motionEnabled = realSwitch.currentSwitch == "on"
if(state.motionEnabled) realSwitch.off()
}
def virtualOnHandler(evt) {
if(state.motionEnabled) realSwitch.on()
}