Energy dashboard incorrect in case of a gap in energy data

Hi! I’ve now had two occasions where my whole house energy sensor dips to zero, messing up my energy dashboard big-time.

Here’s the sensor:

template:
  - sensor:
      - name: 'House Energy'
        unique_id: house_energy
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >-
          {{ states('sensor.shelly_3em_channel_a_energy')|float + 
             states('sensor.shelly_3em_channel_b_energy')|float + 
             states('sensor.shelly_3em_channel_c_energy')|float }}

And here’s the issue:

And here’s the outcome:

And here’s the root cause – my energy monitor (Shelly 3EM) having a gap in the data:

I understand it’s caused by the way cumulative energy is being measured and any increase is being counted towards consumption, thus the 0->43kWh is counted as actual consumption. I guess the outage might be caused by Shelly’s software update or something, although Shelly should have internal memory to avoid this if it itself is running, it still occurs sometimes. Is there any way to avoid the dip to 0 in my sensor.house_energy and thus avoid the crazy spikes in consumption or any other ways to make this work?

Yeah, this seems rather a norm than an exception:

Solved using this post: Shelly 3EM 3-phases Energy sensor - #61 by amitfin

Tne sensor now looks like this:

template:
  - sensor:
      - name: 'House Energy'
        unique_id: house_energy
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >-
          {{ states('sensor.shelly_3em_channel_a_energy')|float + 
             states('sensor.shelly_3em_channel_b_energy')|float + 
             states('sensor.shelly_3em_channel_c_energy')|float }}
        availability: >-
          {{ is_number(states('sensor.shelly_3em_channel_a_energy')) and
             is_number(states('sensor.shelly_3em_channel_b_energy')) and
             is_number(states('sensor.shelly_3em_channel_c_energy')) }}
1 Like