zha-device-handlers: [BUG] Smartenergy cluster: Instantaneous demand and Summation delivered error in log

Describe the bug Home Assistant core 2023.2.1 - Python 3.10.9 Using a DIY device based on PTVO firmware with a custom quirk I get the following error in the log:

2023-02-03 22:02:51.579 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.csrlabs_pzem004t_instantaneous_demand (<class 'homeassistant.components.zha.sensor.SmartEnergyMetering'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('power') it is using; expected one of ['W', 'kW']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+zha%22
2023-02-03 22:02:51.587 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.csrlabs_pzem004t_summation_delivered (<class 'homeassistant.components.zha.sensor.SmartEnergySummation'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('energy') it is using; expected one of ['MJ', 'GJ', 'kWh', 'MWh', 'Wh']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+zha%22

And the correspondent entities are missing the unit of measurement

quirk

This is the relevant code in the quirk

class SmartEnergyCluster(LocalDataCluster, Metering):

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

    POWER_WATT = 0x0000
    
    """Setting unit of measurement."""
    _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)

The device was working fine before the upgrade.

Any idea on how to fix this or adjust the quirk code is welcome

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20

Most upvoted comments

Can you add back 0x0303: 0b0_0100_011, # summation_formatting, then restart HA after you’ve changed the quirk, remove the device and wait a minute or so before adding it back (re-pairing alone is not enough). Then send the logs here if it still errors out (and a new diagnostic file). Also, try to read that summation_formatting attribute through the UI. It’s under the three dots -> Manage Zigbee device -> Clusters. Then post a screenshot of what it returns (and try to restart HA again after having read the attribute (which caches it)).


Also, make sure you check the type of attributers you’re setting in the LocalDataCluster. For example, rms_voltage needs to be an integer. So you need to round() it first. See https://github.com/zigpy/zha-device-handlers/pull/2041 for reference.


Btw., I don’t think you need to use Bus anymore. You should be able to just do something like this:

self.endpoint.smartenergy_metering.update_attribute(Metering.attributes_by_name["current_summ_delivered"], value)

(You’d still need the LocalDataClusters, but nothing with bus stuff)

You can find all names here: https://github.com/zigpy/zigpy/blob/dev/zigpy/zcl/clusters/measurement.py, https://github.com/zigpy/zigpy/blob/dev/zigpy/zcl/clusters/smartenergy.py, https://github.com/zigpy/zigpy/blob/dev/zigpy/zcl/clusters/homeautomation.py (and maybe in other files in the clusters folder)