Subscribe To Variable

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.

1 Like

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.

Can't say I will read it all (at least tonight / this morning), but others may find it useful to talk to how to solve your predicament...

/**
 *  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()
}
2 Likes

subscribe(location, "$varName", "methodName")

4 Likes

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.

Thanks.

2 Likes

I expect a change in the variable is more likely. unless others would also need to change their drivers..... Hopefully you have now worked this out.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.