zigpy / zha-device-handlers

ZHA device handlers bridge the functionality gap created when manufacturers deviate from the ZCL specification, handling deviations and exceptions by parsing custom messages to and from Zigbee devices.
Apache License 2.0
749 stars 687 forks source link

[Device Support Request] SmartEnergy Metering cluster entities are missing the unit of measurement #1081

Closed glcos closed 2 years ago

glcos commented 3 years ago

Is your feature request related to a problem? Please describe. I'm building a quirk for a PZEM004T based device which is actually working fine, but the entities related to the Metering SmartEnergy cluster are missing the unit of measurement. Instantaneous demand should be in Watt of Kilowatt while Energy should be in W/h or Kw/h. Tests done on a system running Home Assistant 2021.11.0.dev0

Describe the solution you'd like Show the unit of measurement or better choose it from the quirk

Device signature - this can be acquired by removing the device from ZHA and pairing it again from the add devices screen. Be sure to add the entire content of the log panel after pairing the device to a code block below this line. Not needed here

Additional context

Entities red

Quirk is here https://github.com/glcos/PTVOquirk/blob/main/pzem004t.py

Adminiuga commented 3 years ago

You may need to define _CONSTANT_ATTRIBUTES dict in your quirk for smart energy cluster with attr_id of unit of measurement attribute Id, so zha knows what uom to use

glcos commented 3 years ago

@Adminiuga thanks for your help, but I don't quite understand, this is my cluster class:

class SmartEnergyCluster(LocalDataCluster, Metering):

    cluster_id = Metering.cluster_id
    CURRENT_SUMM_DELIVERED_VALUE_ID = 0x0000
    INSTANTANEOUS_DEMAND_VALUE_ID = 0x0400
    UNIT_OF_MEASURE_VALUE_ID = 0x0300

    POWER_WATT = 0x0000
    ENERGY_KILO_WATT_HOUR = 0x0000

    _CONSTANT_ATTRIBUTES = {0x0300: POWER_WATT}

    def __init__(self, *args, **kwargs):
        """Init."""
        super().__init__(*args, **kwargs)
        self.endpoint.device.energy_bus.add_listener(self)

    def energy_reported(self, value):
        """Energy reported."""
        self._update_attribute(self.CURRENT_SUMM_DELIVERED_VALUE_ID, value)

    def instantaneous_demand(self, value):
        """Instantaneous power demand reported."""
        self._update_attribute(self.INSTANTANEOUS_DEMAND_VALUE_ID, value)

Setting _CONSTANT_ATTRIBUTES the way I did, doesn't seem to work.

Adminiuga commented 3 years ago

looks good. What happens when you try to read the 0x0300 attr from zha device panel?

glcos commented 3 years ago

Don't know how to read it from zha device panel, but the uom is still missing and I get this in the logs:

WARNING (Recorder) [homeassistant.components.sensor.recorder] sensor.ptvo_info_pzem004t_92e9da14_smartenergy_metering has unknown unit None
2021-10-20 14:15:10 WARNING (Recorder) [homeassistant.components.sensor.recorder] sensor.ptvo_info_pzem004t_92e9da14_smartenergy_metering_summation_delivered has unknown unit None

In addition, since the cluster has two entities defined in sensor.py (SmartEnergyMetering and SmartEnergySummation) there should be a way to set uom for each on them, because in some cases they might be different.

Adminiuga commented 3 years ago

to read the attribute go to Configuration -> Devices -> Your device -> Manage Clusters -> Pick the Metering 0x0702 cluster -> pick 0x0300 attribute unit of measurement -> click on Get Zigbee Attribute

glcos commented 3 years ago

This is what I get

Cattura
Adminiuga commented 3 years ago

Works as expected. If you restart HA, does it still shows the UOM as None Can you post the state changes for this entity during the restart?

If still doesn't work, could you remove the device from ZHA and re-pair it? -- this is to clear the cached values, like unsupported attributes which still might be lingering on if the device was added before there was any quirk present.

glcos commented 3 years ago

Just restarting HA one more time did the trick! Thanks again @Adminiuga

Cattura

Now it is also appearing in the energy dashboard

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.