Great work! I modified the child app code to add tracking of my Nest thermostats when in either heating or cooling modes with just a little effort. Thank you @kampto ! Below are the few sections of the code that I modified. Had to make some minor tweaks because I wanted to track only heating or cooling at one time, and both would call the offHandler() when the thermostat goes back to idle. I use [RELEASE] Google SDM API - Nest integration to link my Nest devices.
section {
label title: "<b>1. Enter a name for this child App</b>", required: true, submitOnChange: true, width: 4
input name: "capabilitySelect", type: "enum", title: "<b>2. Select a capability you want to track.</b>", required: true, description: "Default = SWITCH On", defaultValue: "1", multiple: false, options:[["1":"SWITCH On"], ["2":"CONTACT Open"], ["3":"CONTACT Closed"], ["4":"POWER Monitor"], ["5":"THERM COOLING Monitor"], ["6":"THERM HEATING Monitor"]], width: 6, submitOnChange: true, displayDuringSetup: false
if (capabilitySelect == "1") {input "lights", "capability.switch", title: "<b>3. Select Switch Devices to Track Switch On Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else if (capabilitySelect == "2") {input "lights", "capability.contactSensor", title: "<b>3. Select Contact Devices to Track Contact Open Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else if (capabilitySelect == "3") {input "lights", "capability.contactSensor", title: "<b>3. Select Contact Devices to Track Contact Closed Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else if (capabilitySelect == "4") {input "lights", "capability.powerMeter", title: "<b>3. Select Power Meter Devices to Track On Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else if (capabilitySelect == "5") {input "lights", "capability.thermostatOperatingState", title: "<b>3. Select Thermostats to Track Cooling Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else if (capabilitySelect == "6") {input "lights", "capability.thermostatOperatingState", title: "<b>3. Select Thermostats to Track Heating Time</b>", required: true, multiple: true, submitOnChange: true, width: 6}
else {input "lights", "capability.switch", title: "<b>3. Select Switch Devices to Track Switch On Time</b>", multiple: true, submitOnChange: true, width: 6}
lights.each {dev ->
if(!state.lights["$dev.id"]) {
if (capabilitySelect == "1") {state.lights["$dev.id"] = [start: dev.currentSwitch == "on" ? now() : 0, total: 0, var: "", time: ""]}
else if (capabilitySelect == "2") {state.lights["$dev.id"] = [start: dev.currentContact == "open" ? now() : 0, total: 0, var: "", time: ""]}
else if (capabilitySelect == "3") {state.lights["$dev.id"] = [start: dev.currentContact == "closed" ? now() : 0, total: 0, var: "", time: ""]}
else if (capabilitySelect == "4") {state.lights["$dev.id"] = [start: dev.currentPower >= powerThreshold ? now() : 0, total: 0, var: "", time: ""]}
else if (capabilitySelect == "5") {state.lights["$dev.id"] = [startCool: dev.currentThermostatOperatingState == "cooling" ? now() : 0, total: 0, var: "", time: ""]}
else if (capabilitySelect == "6") {state.lights["$dev.id"] = [startHeat: dev.currentThermostatOperatingState == "heating" ? now() : 0, total: 0, var: "", time: ""]}
endif
state.lightsList += dev.id
}
}
String displayTable() {
if(state.reset) {
def dev = lights.find{"$it.id" == state.reset}
if (capabilitySelect == "1") {state.lights[state.reset].start = dev.currentSwitch == "on" ? now() : 0}
else if (capabilitySelect == "2") {state.lights[state.reset].start = dev.currentContact == "open" ? now() : 0}
else if (capabilitySelect == "3") {state.lights[state.reset].start = dev.currentContact == "closed" ? now() : 0}
else if (capabilitySelect == "4") {state.lights[state.reset].start = dev.currentPower >= powerThreshold ? now() : 0}
else if (capabilitySelect == "5") {state.lights[state.reset].startCool = dev.currentThermostatOperatingState == "cooling" ? now() : 0}
else if (capabilitySelect == "6") {state.lights[state.reset].startHeat = dev.currentThermostatOperatingState == "heating" ? now() : 0}
endif
if (capabilitySelect == "1") { str += "<td style='color:${dev.currentSwitch == "on" ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentSwitch</td>"}
else if (capabilitySelect == "2") {str += "<td style='color:${dev.currentContact == "open" ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentContact</td>" }
else if (capabilitySelect == "3") {str += "<td style='color:${dev.currentContact == "closed" ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentContact</td>"}
else if (capabilitySelect == "4") {str += "<td style='color:${dev.currentPower >= powerThreshold ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentPower</td>"}
else if (capabilitySelect == "5") {str += "<td style='color:${dev.currentThermostatOperatingState == "cooling" ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentThermostatOperatingState</td>" }
else if (capabilitySelect == "6") {str += "<td style='color:${dev.currentThermostatOperatingState == "heating" ? "green" : "red"}'>$time</td>" + "<td title='State $dev'>$dev.currentThermostatOperatingState</td>" }
endif
void initialize() {
if (capabilitySelect == "1") {
subscribe(lights, "switch.on", onHandler)
subscribe(lights, "switch.off", offHandler)
}
else if (capabilitySelect == "2") {
subscribe(lights, "contact.open", onHandler)
subscribe(lights, "contact.closed", offHandler)
}
else if (capabilitySelect == "3") {
subscribe(lights, "contact.open", offHandler)
subscribe(lights, "contact.closed", onHandler)
}
else if (capabilitySelect == "4") { //// Added ver 1.0.2
subscribe(lights, "power.< powerThreshold", offHandler)
subscribe(lights, "power.>= powerThreshold", onHandler)
}
else if (capabilitySelect == "5") {
subscribe(lights, "thermostatOperatingState.cooling", onHandler)
subscribe(lights, "thermostatOperatingState.idle", offHandler)
}
else if (capabilitySelect == "6") {
subscribe(lights, "thermostatOperatingState.heating", onHandler)
subscribe(lights, "thermostatOperatingState.idle", offHandler)
}
endif
void offHandler(evt) {
if (state.curTrack == "cool") {
if (capabilitySelect == "5") {
state.lights[evt.device.id].total += now() - state.lights[evt.device.id].startCool
}
else {
return
}
endif
}
else if (state.curTrack == "heat") {
if (capabilitySelect == "6") {
state.lights[evt.device.id].total += now() - state.lights[evt.device.id].startHeat
}
else {
return
}
endif
}
else {
state.lights[evt.device.id].total += now() - state.lights[evt.device.id].start
}
endif
void resetTimers(evt = null) {
if (logEnableBool) {log.debug "App: ${app.label} - All Timers Reset to 0 Happening ..........."}
state.lights.each{k, v ->
def dev = lights.find{"$it.id" == k}
if (capabilitySelect == "1") {state.lights[k].start = dev.currentSwitch == "on" ? now() : 0}
else if (capabilitySelect == "2") {state.lights[k].start = dev.currentContact == "open" ? now() : 0}
else if (capabilitySelect == "3") {state.lights[k].start = dev.currentContact == "closed" ? now() : 0}
else if (capabilitySelect == "4") {state.lights[k].start = dev.currentPower >= powerThreshold ? now() : 0} //// Added ver 1.0.2
else if (capabilitySelect == "5") {state.lights[k].startCool = dev.currentThermostatOperatingState == "cooling" ? now() : 0}
else if (capabilitySelect == "6") {state.lights[k].startHeat = dev.currentThermostatOperatingState == "heating" ? now() : 0}
endif
state.lights[k].time = new Date().format("MM-dd-yyyy ${location.timeFormat == "12" ? "h:mm:ss a" : "HH:mm:ss"}")
state.lights[k].total = 0
}
if(resetVar) setGlobalVar(resetVar, false)
refreshHandler() //// Added ver 1.0.3
}