Utility Meter does weird jumps by 40kWh

I installed a shelly 3EM last week and created a sensor for the Utility meter to see my kWh consumption of today. I configured the sensor in the configuration.yaml

  - sensor:
      - name: "Shelly3EM Energy Total"
        unique_id: shelly3em_energy_total
        device_class: energy
        state_class: total
        unit_of_measurement: "kWh"
        state: >
          {{ 
          states('sensor.shelly_3em_channel_a_energy')| float(0) + 
          states('sensor.shelly_3em_channel_b_energy')| float(0) +
          states('sensor.shelly_3em_channel_c_energy')| float(0) 
          }}

The utility meter is configured as follows:

state_class: total_increasing
source: sensor.shelly3em_energy_total
status: collecting
last_period: '7.77'
meter_period: daily
cron pattern: 0 0 * * *
last_reset: '2023-01-22T23:00:00.008096+00:00'
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: Energieverbrauch Heute (kWh)

Today the meter did a weird jumps and I don’t understand why.

I deleted similar utility sensors twice and face the same issue again after 2 - 3 days.

Anyone any ideas?

Your sensor is reporting 0 to the utility meter when it goes off-line. When it returns on-line the utility meter adds the full total of this jump from zero to the total.

To prevent this your sensor should report unavailable when it is off-line. This can be accomplished like so:

  - sensor:
      - name: "Shelly3EM Energy Total"
        unique_id: shelly3em_energy_total
        device_class: energy
        state_class: total
        unit_of_measurement: "kWh"
        state: >
          {{ 
          states('sensor.shelly_3em_channel_a_energy')| float(0) + 
          states('sensor.shelly_3em_channel_b_energy')| float(0) +
          states('sensor.shelly_3em_channel_c_energy')| float(0) 
          }}
        availability: >
          {{ 
          states('sensor.shelly_3em_channel_a_energy')| is_number and
          states('sensor.shelly_3em_channel_b_energy')| is_number and
          states('sensor.shelly_3em_channel_c_energy')| is_number
          }}

Thanks much Tom!

Offline in this case means that the Shelly does not have a network connection?

Yeah network dropouts for whatever reason. Also if the template sensor integration loads before the Shelly integration after a Home Assistant restart.