Home Assistant interpreting energy meter reading as 0 due to lack of connection, screwing up all my statistics

I have an ESP32 that reads an energy meter internal kWh counter and then sends it to HA via MQTT
I disconnected the RS485 between the meter and the ESP32 for a few minutes and found that it reported 0 for that duration of time

This consequently screwed up my daily energy consumption because it saw the big jump from 0 when I connected it back

image

  1. How can I prevent this from happening
  2. How can I fix the wrong data?

I don’t have the answer, but I also want to know how to correct the data manually.

I can imagine we could do this by accessing the database directly using SQL commands, most probably.

I’ve solved 1): it was just bad coding in the esp32 from my side (it was publishing to mqtt even when receiving invalid data)

as per 2), I managed to correct the current utility meter reading using the service “calibrate”, but not changing the history