During my energy monitor setup (using esphome) it has triggered a wrong data. I don’t know how, because now everything looks fine. Do you know how I can remove it ? This 20K kWh trigged is masking the real value when in the same view.
I’m using mariadb and tried to search for this value in the db but cannot find it…
I recently fumbled my way through this - I made a mistake pulling data from an rtlamr influx bucket. I’m using sqlite, but the principal should be similar.
You should probably practice this on a copy of your db
First lookup your sensor’s details in the statistics_meta table:
sqlite> select * from statistics_meta where statistic_id = "sensor.electric_meter_reading";
id|statistic_id|source|unit_of_measurement|has_mean|has_sum|name
53|sensor.electric_meter_reading|recorder|kWh|0|1|
Substitute the right sensor name for your installation. This tells me my electric sensor has id = 53.
Second, find the senor data in the statistics table. I’m going to filter by date - I know the original data was entered on Jan 17.
If you look at this data, you can see the jump at row id 58161 - the data before that is junk.
Be aware: these timestamps are in UTC!
Now, delete the data:
sqlite3> delete from statistics where metadata_id=53 and created <= '2022-01-17 21:00:00';
The results aren’t perfect. The statistics table keeps a running total of the usage in the sum column. So I still have a large jump at the beginning, since the new beginning (row 58161 above) already shows 24.07kWh usage. So now I just need to subtract that previously accumulated usage:
sqlite> update statistics set sum = sum - 24.07 where metadata_id = 53;
If your data includes a reset, sum might behave differently. All of my usage is in January, so the meter hasn’t reset at all. I don’t know how HA behaves in that case yet.
Hi, thanks for your help. I found the problematic data and deleted them.
Now the problem is the sum, I need to subtract 23000 only from 58418 until now, not before.
My knowledge in sql is low, I’ll backup the data base and give some trial.
You can filter, either on the id field or even by the created field:
update statistics set sum = sum - 24.07 where metadata_id = 53 and created > "2021-01-22 12:34:56"
I just realized that my fix didn’t work quite right. My energy dashboard now has a jump in the sum at the time I ran the updates above. Maybe HA has that value loaded already - I’m going to try again with HA stopped this time.
Ich pretty sure the values in the table statistics are calculated from the table statistics_short_term. So you would have to correct your values there as well.
And you might have to correct the values in table states (at least the current state) as well, as they are the origin for calculating the statistics.
Yea, you’re right - though modifying states looks hopeless since a new reading won’t be continuous with the old ones.
I might undo this by moving all of the excess back to the very first entry. It’ll still be an incorrect jump, but at least I won’t see it.
I tried a fresh start by removing the energy sensors and re-adding, but that didn’t clear out the data. As soon as I re-added, everything from the past was visible again.
Had my daily energy rollover and include all of yesterday! I found the metadata_id in phpmyAdmin and this query worked the treat. Using the date just seemed to align with my brain a little better than other queries.