Multi-Try Multi-Time GoToBed App Not Working


(Ēriks Goodwin) #1

Sometimes, I am up past when my “BigOff” app would run and then end up waking up in the middle of the night with the lights still on and the TV still working. SO… I tried my hand at writing an app to turn off various switches at three separate times per night. In looking at the logs, only one of the four times that are in my app seem to work. I still do not know where the “Good Morning” app is… but that’s for another post.

Here’s my relevant code… I’m sure I’m making major NOOB mistakes, so please be kind in your help. :smile:

preferences {
    section("Select on-off switches.") {
        input name: "switches", type: "capability.switch", multiple: true
    }
    section("Select off-only switches.") {
        input name: "offswitches", type: "capability.switch", multiple: true
    }
    section("Turn on Time-1") {
        input name: "startTime", title: "Turn On Time?", type: "time"
    }
    section("Turn off Time-1") {
        input name: "stopTime1", title: "Turn Off Time?", type: "time"
    }
    section("Turn off Time-2") {
        input name: "stopTime2", title: "Turn Off Time?", type: "time"
    }
    section("Turn off Time-3") {
        input name: "stopTime3", title: "Turn Off Time?", type: "time"
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"
    schedule(startTime, "startTimerCallback")
    schedule(stopTime1, "stopTimerCallback")
    schedule(stopTime2, "stopTimerCallback")
    schedule(stopTime3, "stopTimerCallback")
}

def updated(settings) {
    unschedule()
    schedule(startTime, "startTimerCallback")
    schedule(stopTime1, "stopTimerCallback")
    schedule(stopTime2, "stopTimerCallback")
    schedule(stopTime3, "stopTimerCallback")
}

def startTimerCallback() {
    log.debug "Turning on switches"
    switches.on()

}

def stopTimerCallback() {
    log.debug "Turning off switches"
    switches.off()
    offswitches.off()
}