Anyone know how to correct one record (from an individual equipment) in the energy dashboard?

My problem: I am following the daily consumption of individual equipments into my energy dashboard… Unfortunately, one day, one of my equipments (and only one while I am following the consumption of more than 20 devices) is reporting a way to hight value in the energy consumed: 21865 kWh for normally around 7 really consumed, this is of course generating wrong reports for weekly, monthly and yearly energy consumed by the equipment…
Anyone know how to correct that value to have my energy dashboard back on track ?

Thanks

The value of that entity will be in two places that you will likely need to fix. The first is in the database. In MariaDB, for example, it’s homeassistant > statistics_meta. Now, you can remove that one entry from the meta and it will purge out all logs for that item and re-add it the next time you start HA, or you can dig into the actual recorded data to try to fix it but that could be problematic, it’s probably easier to wipe it entirely and then use the next step to make sure it comes back as an adjusted amount.

Next you will want to make sure the saved state of the entity is corrected, to do this you need to shut down HA (ha core stop from an SSH) then edit the config/.storage/core.restore_state file and find the entities that you need to modify and change their values to match what you change the database to, then start HA back up (ha core start).

Thank you for the steps… The problem is that value was false on April 17 so a “long time” ago… And it seems that core.restore_state is only storing the value of that entity since the last reset so mainly for the current day as my value is a daily energy consumption … So not sure if I can apply your steps as is…

You can probably fix the history if you track down the recorder entry that’s a problem in the database and then adjust the core file accordingly - i.e., you fix it by 2000kWh in the DB then adjust the total of the entity in the core file by 2000kWh, but it will throw off current energy readings. I think you will have to do some serious digging in the DB to fix the entries you want to fix. It shouldn’t be too terribly difficult because the related ID in the database should match the meta ID of the device, so maybe you can track down the culprit and fix it.

1 Like

Thank you for your feedback, this helped me to find the record(s) generating the issue…
Now how to correct that ? Should I just update the column “state” with the right value for the day of April 17 and therefore update 10 lines… but what about the “sum” columns ? Is it calculated or should I correct that column too … between that date of April 17 and now as it seems to be the sum of the energy consumed since the beginning of this year…

Here is the extract from the database (table: statistics) where the problem occurred for the metadata_id “146” on April 17, 2022 (I am using “phpMyAdmin”):

Before I touch that table/database and potentially corrupt it, it is probably good to have some feedback before any action… Thank you for your help…

Backup. Then, when it’s done, back it up again. Copy the file off your HA machine for safe keeping.

As for your question, yes you can fix the values for that device for that day. You have to keep in mind, though, that the entities you are using should be set with the attribute state_class: total_increasing, meaning you need to adjust the totals on any of those devices that are impacted for each day since the change or you are just moving the incorrect kWh value to another day. Those total_increasing sensors keep a running total each day, if you don’t adjust them all then you’ll just run in circles.

Since you are using phpMyAdmin, you could do a lot of this with some simple update queries (i.e., UPDATE tablename SET columnname = columnname - valuetoreduce WHERE othercolumn = valuetofilteron - replace these with the actual table name, column name, etc). You will still probably need to edit the core file as well so that it doesn’t update the current values to be too high.