SQLite Web: Edit Sensor Data in Database

Hi there,
I have a Shelly Em that records consumption from the meter, but it’s been down for a few days, and I’ve got some gaps in the graphs.


So I was thinking of manually entering this missing data.
ChatGpt absolutely advised me against doing so, but I don’t believe in AI, so I’m asking you if I can do it without any repercussions.

So I was thinking of using this command:

Set the value for the December 8 record
UPDATE statistics 
SET state = 7.1, sum = sum + 7.1 
WHERE metadata_id = 15 AND start_ts = strftime('%s','2025-12-08 12:00:00');

Move forward all records after December 8th to today
UPDATE statistics 
SET sum = sum + 7.1 
WHERE metadata_id = 15 AND start_ts > strftime('%s','2025-12-08 12:00:00');

Could it work?
Thanks

If i wanted to that, i would take a datebase backup, shutdown Home Assistant to prevent concurrent access and then try it.
Restart HA and verify.
If anything goes wrong you could restore the backup.
(I did not check if your update statements are correct!)

I’ve done that a bunch of times. Just shut down core and make a backup. I feel it’s pretty safe if you are comfortable with sql – and at keeping good backups… And doin’t mind having core off for awhile.

I changed a sensor’s unit of measurement and then the new values in the new unit got written, so when I changed it back I had to go in and update all those rows in state and history tables.

There’s also this: Custom Integration to import long term statistics from a file like csv or tsv

Thanks for the suggestions, I’m just worried about what the AI ​​tells me.

  1. Home Assistant doesn’t expect time gaps
  2. risks future inconsistencies
  3. next reboot/purge/recalculation → chaos
    Can I just give it a try?

Sure. Just make a backup right before you do. If it all goes wonky then you just restore the backup.

Thanks, I backed up and fixed all the “holes” now it seems to work without problems.

Which method to insert the data did you use?