After reading @MartinG's post, jay (support) wrote:The code in the plugin that populates usage data is commented out. I can't remember exactly why, but I believe it's because the library used as the basis for the plugin didn't handle it correctly (but I could be misremembering).
The source is available in case someone wants to try it out - uncomment lines 126-128, 140-142, and 317-320 in the plugin.py file. I think you'd need to recreate any devices to have the changes picked up.
It might work, but it also might not.
after which, I wrote:...Well, I guess it could work. I uncommented the lines you noted and do not see the usage data. But, with debugging turned on, I see that the plugin is getting the data. So, the question is why it doesn't display. BTW, the plugin also does not update on changes in brightness either. I'll look into it later this week. Thanks for the pointer...
I have found the source of the problem noted above. It was in processUpdate where
- keyValueList.append was used
- keyValueList.append({'key':'energyCurLevel', 'value':int(deviceInfo["watts"])})
- dev.updateStateOnServer("curEnergyLevel", value=deviceInfo["watts"])
I will look a little deeper into this and then, eventually, merge it back to GitHub. If you just want the changes to get usage data working, here is the revised code for processUpdate (note the old code is just commented out for now):
- Code: Select all
########################################
def processUpdate(self, updateDict):
self.debugLog("processUpdate called")
updateType = updateDict["updateType"]
if updateType == "updateDevice":
#update the states
deviceInfo = updateDict["device"]
devAddress = deviceInfo.get("id", -1)
devId = self.deviceDict.get(str(devAddress), 0)
dev = indigo.devices.get(devId, None)
keyValueList = []
if dev and dev.enabled:
self.debugLog("processUpdate: found device (%s) updating: %s" % (dev.name, deviceInfo))
# This first set of if/elif will take care of dimmers, locks, and relays.
if "level" in deviceInfo:
dev.updateStateOnServer("brightnessLevel", value=deviceInfo["level"])
# keyValueList.append({'key':'brightnessLevel', 'value':int(deviceInfo["level"])})
elif "locked" in deviceInfo:
keyValueList.append({'key':'onOffState', 'value':bool(int(deviceInfo["locked"]))})
elif "status" in deviceInfo and dev.deviceTypeId != "veraThermostat": #some versions of the API send an erroneous status for thermostats which have no on/off state
keyValueList.append({'key':'onOffState', 'value':bool(int(deviceInfo["status"]))})
# Next, we deal with thermostat and other values
if u'mode' in deviceInfo:
keyValueList.append({'key':'hvacOperationMode', 'value':kThermostatModeLookup[deviceInfo["mode"]]})
if "heatsp" in deviceInfo:
keyValueList.append({'key':'setpointHeat', 'value':int(deviceInfo["heatsp"])})
if "coolsp" in deviceInfo:
keyValueList.append({'key':'setpointCool', 'value':int(deviceInfo["coolsp"])})
if "temperature" in deviceInfo:
keyValueList.append({'key':'temperatureInput1', 'value':int(deviceInfo["temperature"])})
if "fanmode" in deviceInfo:
keyValueList.append({'key':'hvacFanMode', 'value':kThermostatFanLookup[deviceInfo["fanmode"]]})
if "batterylevel" in deviceInfo:
uiString = "%s%%" % deviceInfo["batterylevel"]
keyValueList.append({'key':'batteryLevel', 'value':int(deviceInfo["batterylevel"]), 'uiValue':uiString})
if "watts" in deviceInfo:
dev.updateStateOnServer("curEnergyLevel", value=deviceInfo["watts"])
# keyValueList.append({'key':'energyCurLevel', 'value':int(deviceInfo["watts"])})
if "kwh" in deviceInfo:
dev.updateStateOnServer("accumEnergyTotal", value=deviceInfo["kwh"])
#keyValueList.append({'key':'accumEnergyTotal', 'value':int(deviceInfo["kwh"])})
if len(keyValueList) > 0:
dev.updateStatesOnServer(keyValueList)
if "state" in deviceInfo:
if deviceInfo["state"] in veralib.kErrorStates:
dev.setErrorStateOnServer("device error")
else:
if dev:
self.debugLog("processUpdate: device with Vera ID %i found (%s) but is disabled, skipping update" % (devAddress, dev.name))
else:
self.debugLog("processUpdate: no device with Vera ID %i found, skipping update" % devAddress)
elif updateType == "deleteDevice":
self.debugLog("\n\nDELETING DEVICE\n\n")
# the device disappeared from the vera so we'll want to deal with it
devAddress = updateDict.get("device", -1)
self.debugLog("deleting device id: %s" % str(devAddress))
devId = self.deviceDict.get(str(devAddress), 0)
dev = indigo.devices.get(devId, None)
if dev:
dev.setErrorStateOnServer("device deleted")
self.errorLog('Device "%s" (id: %s) deleted on the Vera' % (dev.name, devAddress))