Energy dashboard show negative value for socket

I have added one of my ESPHome powered sockets to the energy dashboard. ESPHome v2021.11.1.

Added the ‘platform: total_daily_energy’ sensor defined in ESPHome to my energy dashboard in HA.
Everything with energy metering and energy dashboard worked as expected. Until the end of December.
On 12/26/2021 I disconnected the socket from mains. And reconnected it again on 01/12/2022.

But no I get negative readings for this energy sensor.

I have checked data in database statistics table. Last sum value stored in 2021 before disconnect from mains is for 12/26/2021 (value is around 9.96… kWh).
The next row in database statistics table is for 01/10/2022 (after connecting the socket to mains). But sum value from than on is 0.00 kWh.

And energy dashboard is starting with negative value of -9.96 kWh. And is counting towards zero with new energy readings added to the database.
So if I have a consumption of 9.96 kWh in 2022 the energy dashboard will show a total consumption of 0.0 kWh.

Why is the sum reset to zero after connecting the socket?
Is there a way to fix the energy meter without loosing all stored data?
And what could I do to prevent this?

Here is a short excerpt from the statistics database table:

719084,2021-12-26 21:00:22.245360,260,2021-12-26 20:00:00,,,,,0.0,9.96099999999984
806669,2022-01-10 18:00:20.175615,260,2022-01-10 17:00:00,,,,,0.0,0.0

the next rows with a sum value are:

810163,2022-01-11 06:00:20.926270,260,2022-01-11 05:00:00,,,,,0.001,0.001
810454,2022-01-11 07:00:21.180125,260,2022-01-11 06:00:00,,,,,0.109,0.109

I have a few other sockets with the same ESPHome firmware. They are working as expected and energy is counting up. Even if they are disconnect from mains for a few days.