How do I delete bad measurements from the database?

As the ZigBee integration in HA passes on invalid measurements as real numbers, I often have the need to delete these measurements manually, but I honestly don’t know how I can do that.

An example of a bad measurement is:

Summation delivered:
1099511627776,0 kWh

Instantaneous demand:
-32768000,0 W

I have found out how to edit summation delivered in HA, but this isn’t a good solution as I do not know the right value to enter.

I have found no way to edit the instantaneous demand.

I think I saw a way to remove time periods from a device, but I cannot find it again. This would be an acceptable way to fix the data manually.

Going forward, I would like to have a general filter added to the zigbee readings, the the alarm status of the devices is honored and if set (to e.g. invalid), no value is recorded or an invalid state is record. Every data type in zigbee has a reserved number indicating invalid value and it seems zha does honor this (and sets the status accordingly). All we need is to make the core HA to read the status and if there is an alarm, ignore the reading, possibly configurable.

If I could make such a general filter for all my devices without having it duplicate all my data, I would be happy. As it is now, I make a filter device, thereby duplicating data. And I have to make a filter device for each zigbee device. This is a bit much.

If you want that behavior, you’ll need to create templates for each sensor that needs filtering.

This problem affects ALL ZigBee devices in ZHA. Maybe the solution could be made differently?

You could change the source code and create a pull request.

I have never seen this behavior with ZHA, nor heard of it. So I doubt it is a ZHA problem. Usually there are other causes. Are the kWh and W values you show straight from the device? What brand of devices are they?

For this problem to be visible, the device has to report invalid values. If you haven’t seen it, you probably haven’t received invalid values. But I have seen reports from other users saying they received mysterious large values. These values could be proper invalid values used as real values by HA core.

And no, the unit of measurement is from the device definition I assume. The devices do not report units, just values. The Zigbee protocol has reserved values indicating indskud values and ZHA users this to set the status property to CHECK_METER.

The brand of device is of no concern as this is a Zigbee protocol feature.

1 Like

I have tried reporting this to ZHA a year ago, but there has been zero movement from the team.

You can find a link to the Zigbee documentation about these invalid values there.