domoticz-zigbee2mqtt-plugin: Kwh meter for power switch not working properly.

Issue 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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 40 (19 by maintainers)

Commits related to this issue

Most upvoted comments

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.

i have just found some differences in the MQTT traffic. The plugs which are displaying properly do NOT report “power_outage_memory”.

afbeelding

For me it doesn’t work unfortunately. I removed all devices related to the two TS0121_plug devices, stopped Domoticz, update the plugin with git pull in the plugin folder, and started Domoticz again. The newly created kWh devices still don’t show the current usage (in Watts). In the Devices screen, they show “1, 10” under Data, this never seems to change: Naamloos In the Zigbee2mqtt logs, the MQTT messages seem ok: Naamloos 2

After playing around alot yesterday with deleting devices, pairing etc. I ended up with similar device for power. The power objects seems to be incorrectly included somehow and did not show up in Meter in database. the power device object seems to be included with a different type of general /kWh type.

The only way to recover was to delete zigbee2mqtt plugin folder, do a new git clone, delete domoticz database, and install the hardware device again. Not shure if its the zigbee2mqtt plugin or if its domoticz itselves that did this.

I’ll see if I manage to recreate this later today/evening.

Hi all, I have not been able to recreate this problem when running latest beta version of domoticz. So if you still experience issues you should update domoticz. The issues with kwh meters has been solved now in latest beta version (13117)

br lwalbert

Yes, I have the same TS0121_plug device and it works just fine, so the issue is most likely in the environment setup. Are you using the latest Domoticz beta version?