Your energy sensor is reporting 0
when it goes off-line. It needs to report unavailable
instead.
When your energy sensor comes back on-line the energy dashboard will ignore a change of state from unavailable
to the real value. However if it sees a change from 0
to the real value it will record that as the amount of energy used. This will get worse as the total in your energy sensor is always increasing.
If you are using a template sensor you need to add an availability template. If you aren’t using a template sensor you need to filter your energy sensor through one. See this topic
(the filtered sensor did work).