Incorrent values in energy dashboard when reconnected smart plug

Hi,
I’m looking for some advise on finding a root cause and how to fix a problem I faced.

Scenario:

  1. Smart plugs with esphome and energy sensor.
  2. Disconnected the plugs for 3 weeks.
  3. In the meantime Home Assistant was restarted (power outage).
  4. When plugs were reconnected, in the Energy dashboard I see hundreds of kWh negative for sensors of these plugs.

Details:

  1. Plug models: Blitzwolf SHP6, Gosund SP111.
  2. ESPhome config of the sensor:
  - platform: total_daily_energy
    name: "${plug_name}: Dzienne zużycie energii"
    power_id: "${plug_id}_Wattage"
    filters:
        # Multiplication factor from W to kW is 0.001
        - multiply: 0.001
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
  1. Energy dashboard for the problematic day:
  2. History graph for an energy sensor of one of the plugs:
  3. Dev opts entity state:
    3

Any idea what happened?