Problem with statistics for energy dashboard

Running latest version of HASSOS here.
Using the SlimmeLezer – Marcel Zuidwijk to read my electra and gas.

Yesterday (february 6) my gas usage in the energy portal suddenly showed -1180 M3.
I’m sure I didn’t produce anything that was that massive. :laughing:

The states table in the database shows a normal flow (50 m3 between lowest and highest value of last week, and some unavailables over the days.

Also a normal graph with sensor.gas_consumed in it shows a nice line with the normal usage. It’s only the energy dashboard that shows this issue.

How can I correct this ? since it’s screwing up my month and year totals.

1 Like

Discovered a bit more. The values for consumed and produced seem to have been reversed on that hour. The same happened with my electricity for that hour. The same happened on february 11th, when I was testing if last_reset and total_increasing could be removed here (apparently not).
The total of Gas produced on february 6 in that hour, was the total amount of gas consumed since the start of the dasboard in september 2021.

Found the rootcause.
The issue is not with the states, as this is the actual status of the device.
In the statistics the difference between each status is also stored, and that had been reset to 0 when the last_reset date was reset. This meant all was being reset to 0, and therefore all production became consumption and vice-versa for that hour. After that it started all normal again.

the solution was to update the incorrect differences by adding the last correct value to them in the statistics table ,and also setting the last_reset value for all records since that moment.

When this is done, you’ll see that the problem immediately moves away from that date, but changes to the current day , by the strike of the hour. This is because these values are also kept in the statistics_short_term, which, at the end of the hour, updates the statistics table again.
There the same action must take place for the days that are left (I have a feeling only the last hour is relevant, but it’s a single sql statement, so no harm there. )

My graphs are pretty again, and I hope this can help somebody else that gets in trouble with these statistics.