Maybe it’s just as simple as calling runIn() again but I can’t seem to confirm how to do this. What I’d like to do is delay the setNoMotionTemp() event by x minutes but if motion is detected again unset the runIn() set by noMotionHandler().
/**
* Motion Activated Thermostats
*
* Author: Chris LeBlanc
*/
definition(
name: "Motion Activated Thermostats",
namespace: "cl",
author: "Chris LeBlanc",
description: "Changes your thermostat settings automatically in response to motion sensing.",
category: "Green Living",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo@2x.png"
)
preferences {
page( name:"page1", title:"Choose a Thermostat and Sensor", nextPage:"page2", uninstall:true, install:false ) {
section("Choose thermostat... ") {
input "thermostat", "capability.thermostat"
}
section("When there's movement...") {
input "motion", "capability.motionSensor", title: "Where?", multiple:true
}
section("Delay no motion event...") {
input "after", "number", title: "Minutes", description: "60 minutes", required: false
}
}
page( name:"page2", title:"Motion Tempuratures", nextPage:"page3", uninstall:true, install:false ) {
section("Set air conditioning setting..."){
input "coolingSetpointMotion", "number", title: "Degrees?"
}
section("Set heat setting...") {
input "heatingSetpointMotion", "number", title: "Degrees?"
}
}
page( name:"page3", title:"No Motion Tempuratures", nextPage:"page3", uninstall:true, install:true ) {
section("Set air conditioning setting..."){
input "coolingSetpointNoMotion", "number", title: "Degrees?"
}
section("Set heat setting...") {
input "heatingSetpointNoMotion", "number", title: "Degrees?"
}
}
}
def installed()
{
subscribe(motion, "motion.active", motionHandler)
subscribe(motion, "motion.inactive", noMotionHandler)
}
def updated()
{
unsubscribe()
subscribe(motion, "motion.active", motionHandler)
subscribe(motion, "motion.inactive", noMotionHandler)
}
def motionHandler(evt)
{
log.debug "value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}"
thermostat.setCoolingSetpoint(coolingSetpointMotion)
thermostat.setHeatingSetpoint(heatingSetpointMotion)
thermostat.poll()
}
def noMotionHandler(evt)
{
def delay = (after != null && after != "") ? after * 60 : 3600
runIn(delay, setNoMotionTemp)
}
def setNoMotionTemp()
{
log.debug "value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}"
thermostat.setCoolingSetpoint(coolingSetpointNoMotion)
thermostat.setHeatingSetpoint(heatingSetpointNoMotion)
thermostat.poll()
}
// catchall log.debug "value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}"