/**
* Coffee Pot
*
* Copyright 2018 Jim White
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Coffee Pot",
namespace: "jwwhite001",
author: "Jim White",
description: "Coffee Pot Control",
category: "My Apps",
iconUrl: "",
iconX2Url: "",
iconX3Url: "")
preferences {
section("Inputs Required") {
input "potControlOutlet", "capability.switch", required: true, multiple: false, title: "Outlet To Turn On Pot"
input "disableSwitch", "capability.switch", required: true, multiple: false, title: "Disable Switch"
input "timeVar", "capability.sensor", required: true, multiple: false, title: "Time To Start Variable"
input "potOnTime", "number", required: true, title: "Time To Leave Pot On Minutes"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(timeVar,"variable",startHandler)
subscribe(potControlOutlet, "switch", potTimeHandler)
unschedule()
startHandler(1)
}
def startHandler(evt){
def varDateTime = timeVar.currentValue("dateTime")
def mydateTime = toDateTime(varDateTime)
def myHours = mydateTime.format("hh")
def myMins = mydateTime.format("mm")
log.debug "Hours = ${myHours}, Mins = ${myMins}"
def cronString = "0 " + myMins + " " + myHours + " ? * *"
log.debug "cronString = ${cronString}"
schedule(cronString, potOnHandler)
}
def potOnHandler(evt) {
if (location.mode != "Away" && disableSwitch.currentswitch == "off") {
potControlOutlet.on()
}
}
def potTimeHandler(evt) {
if (evt.value == "on") {
runIn(potOnTime * 60, potOff)
}
}
def potOff(evt){
potControlOutlet.off()
}