HA Energy Dashboard goes crazy with power loss - Need help

Hello everyone,

I hope you can help me out with this. I think the issue is mainly me not understanding how the Energy dashboard is working and therefore not able to understand how to solve the situation.

Some context to all of these. Lately we have been having a lot of storms around and unfortunately it came with few power loss for the whole house.

I have a dongle connected directly to the power meter that feeds data to my HA, that in turn is used for the Energy Dashboard. When the Power meter loses power, so does the dongle.
More details:

  • Dongle is this one
  • I’m using Z2M (latest version, don’t think it matters)

My HA is connected to an UPS therefore continues to work and receive data during the power loss. I think this is where the problem lies to be fair but you (attentive and hopefully more knowledgeable reader) will hopefully correct me.

This is an example of what happens if I look at the sensor:

Every time I lose power, the sensor goes to 0 momentarily then back to the original value. This obviously results in crazy values like these:
image

Can someone help me understand the logic behind the Energy Dashboard so that I can come up with an answer to my problem. I’ve been reading some similar issues that mention the solution would be Riemann sum integral sensor, but since I don’t understand the root cause, I don’t want to do things blind.

If you have reached the end of this, thank you! (even if you don’t have an answer for me)

Chris

Your sensor must report unavailable/unknown rather than 0 when power is lost. Device-Availability | Zigbee2MQTT

If your sensor goes from some total to zero then back to the total, then that total amount is added to your dashboard.

If your sensor goes from some total to unavailable/unknown then back to the total, then that total amount is not added to your dashboard.

If you can’t make this happen with the integration you are using to connect your sensor then you need to filter the values using a template sensor and feed that to the energy dashboard instead. There are many topics on doing this.

1 Like

Thank @tom_l , I suspected as much. Thank you very much for the explanation / confirmation.

Since these sensors are “lifetime” sensors, they should never be a zero, so I can template that quite easily I think.

I’ll try that out whenever I can and report back with the solution I come up if it can help someone having the same issue.

Here we go… I’m starting with this:

template:
  - sensor:
      - name: "Grid Consumption High Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-export"
        state: >
          {% set energy_gchf = states('sensor.lixee_easf02') | float(none) %}
          {% if energy_gchf is not none %}
            {{ energy_gchf }}
          {% else %}
            None
          {% endif %}
      - name: "Grid Consumption Low Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-export"
        state: >
          {% set energy_gclf = states('sensor.lixee_easf01') | float(none) %}
          {% if energy_gclf is not none %}
            {{ energy_gclf }}
          {% else %}
            None
          {% endif %}
      - name: "Return to Grid"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-import"
        state: >
          {% set energy_rtg = states('sensor.lixee_eait') | float(none) %}
          {% if energy_rtg is not none %}
            {{ energy_rtg }}
          {% else %}
            None
          {% endif %}
      - name: "Current Solar Production"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total
        icon: "mdi:solar-power-variant-outline"
        state: >
          {% set energy_csp = states('sensor.envoy_122238059516_today_s_energy_production') | float(none) %}
          {% if energy_csp >= 0 %}
            {{ energy_csp }}
          {% else %}
            None
          {% endif %}

I will test this for a couple of days see if that works out. Tomorrow when I have some data in the middle of the day I will disconnect the dongle to simulate power loss and see if that works.

If someone sees this and cares to comment let me know.

This is not going to work. You have no test for 0.

template:
  - sensor:
      - name: "Grid Consumption High Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-export"
        state: >
          {% set energy_gchf = states('sensor.lixee_easf02') | float(none) %}
          {% if energy_gchf is not none %}
            {{ energy_gchf }}
          {% else %}
            None
          {% endif %}

Try this instead:

template:
  - sensor:
      - name: "Grid Consumption High Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        icon: "mdi:transmission-tower-export"
        state: "{{ states('sensor.lixee_easf02') | float(0) }}"
        availability: "{{ states('sensor.lixee_easf02') | float(0) != 0 }}"

This tests for both zero and non numeric states and marks the sensor unknown if it occurs.

Thanks @tom_l, I will do these changes. I was about to test that my templates worked :innocent:

Quick question on my last sensor:

        icon: "mdi:solar-power-variant-outline"
        state: >
          {% set energy_csp = states('sensor.envoy_122238059516_today_s_energy_production') | float(none) %}
          {% if energy_csp >= 0 %}
            {{ energy_csp }}
          {% else %}
            None
          {% endif %}

I noticed that with this integration (different from the three other sensors), when there is a power loss, sometimes I have a negative value of -1. That is why I tested for >= 0, I take it from your previous comment it will not work either.

Can I adapt like you mention but put :

availability: "{{ states('sensor.envoy_122238059516_today_s_energy_production') | float(0) >= 0 }}"

Thanks
Chris

Yes you can but make it strictly greater than 0. Not greater than or equal to zero. remember we want to filter out zeros as well (when the float filter default is applied to non-numeric values).

Thank you very much @tom_l . It looks like everything is working like a charm now.

You will find here all the templates I created for myself in case you need them to inspire yourselves from.

template:
  - sensor:
      - name: "Grid Consumption High Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-export"
        state: "{{ states('sensor.lixee_easf02') | float(0) }}"
        availability: "{{ states('sensor.lixee_easf02') | float(0) != 0 }}"
      - name: "Grid Consumption Low Fare"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-export"
        state: "{{ states('sensor.lixee_easf01') | float(0) }}"
        availability: "{{ states('sensor.lixee_easf01') | float(0) != 0 }}"
      - name: "Return to Grid"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total
        icon: "mdi:transmission-tower-import"
        state: "{{ states('sensor.lixee_eait') | float(0) }}"
        availability: "{{ states('sensor.lixee_eait') | float(0) != 0 }}"
      - name: "Current Solar Production"
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total
        icon: "mdi:solar-power-variant-outline"
        state: "{{ states('sensor.envoy_122238059516_lifetime_energy_production') | float(0) }}"
        availability: "{{ states('sensor.envoy_122238059516_lifetime_energy_production') | float(0) > 0 }}"

Case closed!
Chris