Kwh meter for power switch not working properly.
See original GitHub issueIssue description Due to recent changes in Domoticz the sValue now requires two values separated by “;” eg. sValue = power;energy I made a workaround in devices/sensor/kwh.py by adding the missing value to the return string when only one value in array. Also found that the value_key array doesn’t work, or not holding the correct variable/string for getting power and energy reading, or it might be the for loop that doesn’t work correctly. Any way, after several tries modifying for loop etc, I still couldn’t get it to work, so made a workaround to get power and energy from device. My device is Develco SPLZB-131 power plug.
Attached code is the modified code that works for power and energy return in sValue.
import Domoticz
from devices.device import Device
class KwhSensor(Device):
def __init__(self, devices, alias, value_key, device_name_suffix=''):
super().__init__(devices, alias, ';'.join(value_key), device_name_suffix)
self.value_keys = ['power', 'energy'] #value_key Added static keys for array
self.energy_multiplier = 1000
def create_device(self, unit, device_id, device_name):
options = {}
options['EnergyMeterMode'] = '1'
return Domoticz.Device(Unit=unit, DeviceID=device_id, Name=device_name, TypeName="kWh", Options=options).Create()
def get_message_value(self, message):
value = {} #[] #added
for item in self.value_keys:
if item in message.raw: # removed item [not]
#return None
value[item] = message.raw[item] #added
#value.append(message.raw[item])
return value if len(value) > 0 else None
def get_numeric_value(self, value, device):
return 0
def get_string_value(self, value, device):
if 'energy' in value: #len(value) == 2: added static comparison due to changes in for loop
return str(value['power']) + ";" + str(value['energy'] * self.energy_multiplier)
#return str(value[0]) + ";" + str(value[1] * self.energy_multiplier)
else:
return str(value['power']) + ";" + str(0) #Added required 2´nd value to domoticz
#return str(value[0])
Additional information Zigbee2MQTT version: v.1.18.1 (ConBee2/RaspBee2 0x264a0700) Python version: 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0] Domoticz version: V2020.2 build 13091 Plugin version: 3.0 (latest)
Could you please check and fix 😃 thanks
br lwalbert
Issue Analytics
- State:
- Created 3 years ago
- Comments:40 (19 by maintainers)
I have been experimenting a bit more, and like @awalsum suggested, the problem is probably related to the “power_outage_memory” field in the MQTT messages! After re-pairing my plugs these fields are not present in the messages anymore, whereas these were previously there (see my earlier screenshot of the log).
I actually need this setting, one of the plugs is monitoring the energy use of my aquarium, so this plug should always go on after a power outage. Therefore I set this memory setting to “On” again via the Zigbee2MQTT web configuration, but immediately afterwards the power readings stopped again in Domoticz!
Can it be that the plugin checks for the MQTT field with the word “power” in the title, but then accidentally finds the “power_outage_memory” field? That would explain why I got weird values like “1, 10”.
Reconfiguring “Kelder ventilatie” through the frontend solved the problems with this plug. All values are updated now and I am able to switch it on and off. Not so much luck with the other plugs however.
I’m not at home at the moment so can’t physically reach the plugs. I’m going to try and delete the plug that don’t work completely from Domoticz and re-pair them, probably tomorrow or Monday. See if that fixes them.