Wrong energy consumption calculation only after Operating System upgrades


I already had by the past wrong value coming from integrations like Envoy (solar panel), Legrand, Netatmo, etc… It was related to the sensor value, and easy to fix with MySQL queries.

But it is now the second time I have wrong values, just after upgrading the Operating System, for always exactly 4 devices, configured/calculated the same way, so I’m trying to figure out why (fixing the values should not be a problem).

Here is the screenshot from the energy dashboard:

The 4 devices are coming from the same manufacturer, directly connected through Z2M:

  • 2 Din contactor 20AX (Legrand 412171 & BTicino FC80CC)
  • 1 DIN power consumption module (Legrand 412015)
  • 1 Power socket (Legrand 067775)

Power values are configured like this:

  • sensor.xxxx_power is the MQTT sensor
- platform: integration
  source: sensor.xxxx_power
  unit_prefix: k
  unit_time: h
  method: left

I have multiple leads in mind but I don’t really know where I should start from:

  • is it related to a timezone issue? Maybe the OS updates its clock/timezone during the upgrade process? Then update HA services? Don’t know…
  • is it related to the way I’m doing the calculation? Not sure, since it works well the day after the upgrade…
  • I checked the value from the power sensor and it seems to be ok
  • if it’s related to the upgrade process and a timezone issue, is it possible to use kind of a delay and wait for the clock to be synced?

Sounds like they are simply being reset to 0. The calculation isn’t complicated, it just a sum of the values over time. The only way to get a negative value is if the value drops by a large amount. Delta T will always be positive.

Ok so if I understand well:

  • Cumulative value of power is reset to 0
  • Delta power turns negative since the new value is lesser (0) than the previous one
  • Integration “fails” cuz (Delta power) / (Delta Time) < 0

Questions are:

  • Why it’s being set to 0 only on Operating System updates and not for the Core updates?
  • How can we solve this? Avoid this? Can it be considered as a bug?

That depends on your sensor and how it’s populating the MQTT topic. And it depends on what the state class is.