Zigbee plug's Kw/h sensor not updating often enough

Hi,

I have a bunch of Samsung Smart Things Zigbee plugs, with power monitoring paired to ZHA. I bought a whole bunch of them because they’ve been working very well for years.

Lately however they all stopped updating the Kw/h sensor regularly, they all seem to update it at random intervals, less than once a day. No data is lost, but they suddenly increase by 8 or 10 Kw/h so it looks ridiculous in the energy dashboard, some day they report nothing and the next day they report a huge spike.
The electrical measurement in watt looks fine, it updates as expected every few seconds.

What could have caused this change, they’re all affected suddenly so I imagine it must be something in ZHA ? I’m not sure when this started, maybe a month ago or so, could be more.

Thanks

I suggest that you examine the reporting configuration (min/max interval and maximum change) for these devices.

You can use zha-toolkit to read & set reporting configurations and also examine the code in zha-device-handlers to look for changes/configurations set in the code specific to your devices.

Hi,

Those smartthings plugs don’t seem to be using any quirks, they’re just using zigpy.device.Device, not sure if that was always the case or not.

Looks like the zha-toolkit function to read reporting attributes isn’t functional right now, according to the readme and my test just now.

I tried reconfiguring a couple of them just to see if it behaves better, maybe that’ll help
EDIT: a few minutes later and it’s already so much better, it’s reporting the value every minute now. Guess I just have to go through all of them and click reconfigure, yay manual actions …

Actually when zigpy was updated I adjusted the toolkit, but apparently the serialiation to generate the event is failing - I am going to handle that.

For the moment you may see the result in the log as I do:

2022-06-09 16:34:57 DEBUG (MainThread) [custom_components.zha_toolkit] Fire zha_done -> {'zha_toolkit_version': 'dev', 'zigpy_version': '0.45.1', 'zigpy_rf_version': '0.7.0', 'ieee_org': 'sensor.lixee_zlinky_tic_ea99d205_electrical_measurement', 'ieee': '00:15:8d:00:05:d2:99:ea', 'command': None, 'command_data': None, 'start_time': '2022-06-09T14:34:57.149343+00:00', 'errors': [], 'params': {'cluster_id': 1794, 'attr_id': 0, 'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'event_done': 'zha_done', 'read_before_write': True, 'read_after_write': True}, 'success': False, 'result_conf': Read_Reporting_Configuration_rsp(attribute_configs=[AttributeReportingConfigWithStatus(status=<Status.SUCCESS: 0>, config=AttributeReportingConfig(direction=0, attrid=0x0000, datatype=37, min_interval=1, max_interval=300, reportable_change=1))])}
2022-06-09 16:34:57 WARNING (Recorder) [homeassistant.components.recorder.core] Event is not JSON serializable: <Event zha_done[L]: zha_toolkit_version=dev, zigpy_version=0.45.1, zigpy_rf_version=0.7.0, ieee_org=sensor.lixee_zlinky_tic_ea99d205_electrical_measurement, ieee=00:15:8d:00:05:d2:99:ea, command=None, command_data=None, start_time=2022-06-09T14:34:57.149343+00:00, errors=[], params=cluster_id=1794, attr_id=0, dir=0, tries=1, expect_reply=True, args=[], event_done=zha_done, read_before_write=True, read_after_write=True, success=False, result_conf=Read_Reporting_Configuration_rsp(attribute_configs=[AttributeReportingConfigWithStatus(status=<Status.SUCCESS: 0>, config=AttributeReportingConfig(direction=0, attrid=0x0000, datatype=37, min_interval=1, max_interval=300, reportable_change=1))])>: Object of type AttributeReportingConfig is not JSON serializable
2022-06-09 16:34:57 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(Event: zha_done).data.result_conf(Read_Reporting_Configuration_rsp).attribute_configs[0](AttributeReportingConfigWithStatus).config=AttributeReportingConfig(direction=0, attrid=0x0000, datatype=37, min_interval=1, max_interval=300, reportable_change=1)(<class 'zigpy.zcl.foundation.AttributeReportingConfig'>

Resolve this in zha-toolkit v0.8.10 .

I could be using it wrong but even with the latest version I’m getting an exception in the logs :

  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1704, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1741, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/zha_toolkit/__init__.py", line 695, in toolkit_service
    raise handler_exception
  File "/config/custom_components/zha_toolkit/__init__.py", line 659, in toolkit_service
    await handler(
  File "/config/custom_components/zha_toolkit/__init__.py", line 744, in command_handler_default
    await default.default(
  File "/config/custom_components/zha_toolkit/default.py", line 33, in default
    await handler(app, listener, ieee, cmd, data, service, params, event_data)
  File "/config/custom_components/zha_toolkit/zcl_attr.py", line 118, in conf_report_read
    cluster = u.get_cluster_from_params(dev, params, event_data)
  File "/config/custom_components/zha_toolkit/utils.py", line 364, in get_cluster_from_params
    if cluster_id in dev.enddev.points[params[p.EP_ID]].out_clusters:
AttributeError: 'Device' object has no attribute 'enddev'

That’s using this call :

service: zha_toolkit.conf_report_read
data:
  ieee: ec:1b:bd:ff:fe:3d:c8:f8
  cluster: 1026
  attribute: 0
  endpoint: 1

Apparently you triggered a typo in the code, probably because the cluster is not on endpoint 1.

I presumably fixed that.

However there is generally no need to specify the endpoint if the cluster is present on only 1 endpoint.
The following would work:

service: zha_toolkit.conf_report_read
data:
  ieee: ec:1b:bd:ff:fe:3d:c8:f8
  cluster: 1026
  attribute: 0
  event_done: zha_done

By specifying the ‘event_done’ event you can start a listener on it in the developer tool’s event tab and see the result of the execution.

Using scan_device can help to get an idea of what your device is capable of:

service: zha_toolkit.scan_device
data:
  ieee: ec:1b:bd:ff:fe:3d:c8:f8
  event_done: zha_done

The result can be found in the directory config/scan/*_result.txt or in the event’s data.

Ah so I understand, I wasn’t using the correct cluster.
As you suggested I ran a scan on the device, and came up with this :

service: zha_toolkit.conf_report_read
data:
  cluster: 1794
  attribute: 0
  ieee: ec:1b:bd:ff:fe:3d:c8:f8
  event_done: zha_done

And this time it went through :

[...]
        "result_conf": [
            {
                "cluster": "Metering",
                "cluster_id": "0x0702",
                "attr_id": "0x0000",
                "direction": 0,
                "type": "0x25",
                "min_interval": 30,
                "max_interval": 900,
                "reportable_change": 1,
                "status": 0
            }
        ]
[...]

So it looks like right now it’s configured to report at least every 900 seconds / 15 minutes, if I understand correctly, which is great.
I should have kept one with the issue not reconfigured to compare, unfortunately I didn’t so we’ll never know what those values were before.

Anyway if it happens again at least now I know how to check that, thank you very much for your help and for this addon !

Excellent. If the reporting matches that configuration, all is well, otherwise you can check that the reporting packets are received by ZHA by setting the zigpy/zha log levels and then know if it is a zigbee issue or ZHA->HA issue/configuration/… .