I have an app that I use to control my coffer pot. (Very important..). I use a variable to select the start time. I haven't changed that time in probably a year. I went in this morning to change the time, via variable, but my subscription didn't work. It had worked before but as I said it had been a year or more since I changed it. Here is the code.
This is the input for the variable which I can set from a dashboard:
input "timeVar", "capability.sensor", required: true, multiple: false, title: "Time To Start Variable"
This is my subscription:
subscribe(timeVar,"variable",startHandler)
When I change the variable the startHandler is not getting called like it used to be.
Feels like you need to both mention the exact App you are using the variable in (guessing RM, but may also be Community App...) and show both the version and some settings for the App.
It's my own app. As I said it always worked before that when I changed the variable it called the handler just fine. I can paste the whole app if you want. It's not that long.
/**
* 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()
}
Well, that worked. I guess something changed over the last year or so in the way to subscribe to a variable. I know it worked before, but as I said it had been over a year since I made any changes in the time.