I have an app that monitors the state of my A/C via a Honeywell Zigbee Thermostat.
My code worked for a number of days, Then I made a few small changes in the logging and now it doesn't work. What is confusing is the old code doesn't work now either !
- I made the changes in a text editor
- Loaded the new App into the Apps code page.
- I uninstalled the old app version
- I installed the new apps version.
Now neither work
it appears the code setting the "prevStop" is not working and I can't see why.
if(evt.value == "idle"){ // if idle we must be stopped.
state.prevcoolStop = state.coolStop
long coolStop = now()
state.coolStop = coolStop
I realize the 1st time through the code state.coolStop will be "null" but after that is should / did work.
Thanks
John
I changed the app name in the "definition name:".
Errors:
Note PrevStop, Start, Stop added after 16:17:15 readings
APP Status page:
CODE:
// Percent ON Time App v004e
definition(
name: "Percent ON Time Calculator v4",
namespace: "hubitat",
author: "JohnRob",
description: "Percent ON Time Calculator",
category: "Convenience",
iconUrl: "",
iconX2Url: "")
preferences {
page(name: "mainPage")
}
def mainPage() {
dynamicPage(name: "mainPage", title: " ", install: true, uninstall: true) {
section {
input "thisName", "text", title: "Name this Percent ON Time Calculator", submitOnChange: true
if(thisName) app.updateLabel("$thisName")
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: false
input "thermostatCtrl", "capability.thermostat", title: "Select Thermostat to Monitor", submitOnChange: true, required: true, multiple: false
input "OutsideTemp", "capability.temperatureMeasurement", title: "Select Temperature to Log", submitOnChange: true, required: true, multiple: false
input "SunBrightness", "capability.illuminanceMeasurement", title: "Select Illumination to Log", submitOnChange: true, required: true, multiple: false
} // section
} // dymanicPage
} // mainPage
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
if (logEnable) log.debug (updated)
}
def initialize() {
subscribe(thermostatCtrl,"thermostatOperatingState", handlerAC)
subscribe(OutsideTemp,"temperature", handlerTmp)
subscribe(SunBrightness,"illuminance", handlerIll)
}
def handlerTmp(evt) {
state.Temperature = evt.value
}
def handlerIll(evt) {
state.Illumination = evt.value
}
def handlerAC(evt) {
if(evt.value == "cooling"){
long coolStart = now()
state.coolStart = coolStart
} // end if cooling
else{
if(evt.value == "idle"){ // if idle we must be stopped.
state.prevcoolStop = state.coolStop
long coolStop = now()
state.coolStop = coolStop
// next line is line 96
def onTime = Math.round((Long.valueOf(state.coolStop) - Long.valueOf(state.coolStart))/1000)
def period = Math.round((Long.valueOf(state.coolStop) - Long.valueOf(state.prevcoolStop))/1000)
if (logEnable) log.debug ",Period=,${period}"
if (logEnable) log.debug " _G_ prevcoolStart ,${state.prev_coolStart}"
def percentON = Math.round(onTime/period*100)
if (logEnable) log.debug ",PercentOn=,${percentON}"
if (logEnable) log.debug ",Temperature=,${state.Temperature}"
if (logEnable) log.debug ",Illumination=,${state.Illumination}"
if (!logEnable) log.info "v004e ,${state.Illumination}, ${state.Temperature}, ${period}, ${percentON},${state.prevcoolStop},${state.coolStart},${state.coolStop}"
} //if idle
} //else
} // handlerAC
// --- eof ---