/**
* Turn off a switch a set number minutes after it turns on.
* If the current time is after a specifice time
*
* Author: Jason
*/
preferences {
section("When it Turns on..."){
input "switch1", "capability.switch"
}
section("For this amount of time...") {
input name: "minutes", title: "Minutes?", type: "number", multiple: false
}
section("After What time..."){
input "timeOfDay", "time", title: "When?"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe(switch1, "switch.on", switchOnHandler)
}
def updated(settings) {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe(switch1, "switch.on", switchOnHandler)
}
def switchOnHandler(evt) {
def startTime = timeToday(timeOfDay)
if(now() >= startTime.time){
log.debug "After set time waiting delay"
switch1.off(delay: minutes * 60000)
log.debug "Light tuned off"
}
if(now() <= startTime.time){
log.debug "time is before set time"
}
}