Home Assistant Energy Dashboard reports more energy than it should

Leaving aside the mqtt sensor for now, this:

 - name: "Power_Energy_Return_2"
        unit_of_measurement: "W"
        state: >
          {% set energy = states('sensor.Power_Meter_Return_Difference') | float(0) %}
          {% if energy < 0.0 %} {% set energy = 0 | float(0) %} {% endif %}
          {{ energy | round(2) }}
        state_class: measurement
        device_class: power

Would be better like this:

- name: "Power_Energy_Return_2"
  unit_of_measurement: "W"
  state: >
    {% set energy = states('sensor.power_meter_return_difference') | float(0) %}
    {{ 0 if energy < 0.0 else energy | round(2) }}
  state_class: measurement
  device_class: power
  availability: "{{ states('sensor.power_meter_return_difference')|is_number }}"

Entity id’s do not have capital letters. So this is wrong wherever else you have it:

sensor.Power_Meter_Return_Difference

Thanks I will change it as you describe.

Ok, the mqtt sensor. Can you explain why this is an mqtt sensor instead of a template sensor?

    - state_topic: "readings/#"
      name: "Power_Meter_Return_Difference"
      unit_of_measurement: W
      qos: 2
      last_reset_topic: "readings/#"
      last_reset_value_template: 1970-01-01T00:00:00+00:00
      value_template: "{{ (((states('sensor.power_generation_local') | float) - (states('sensor.Power_Meter_Total') | float))) | round(2) }}"
      state_class: measurement
      device_class: power
      force_update: true

You are not using anything from the mqtt broker.

Sure. Because I want this sensor to update as soon as there is a change in power wattage. For example when the wattage is change an mqtt sensor is update so if this an mqtt sensor it will update the same time the change in wattage occurs. This way I do not need to wait for template sensor to update.

A template sensor updates whenever one of the sensors inside it updates.

ok that I did not knew :). I can change to a template sensor then. Will this make difference in my problem?

Yes. Because you can add an availability template to guard against your issue.

Hints:

state: "{{ ( states('sensor.power_generation_local')|float(0) - states('sensor.power_meter_total')|float(0) )|round(2) }}"

availability: "{{ states('sensor.power_generation_local')|is_number and states('sensor.power_meter_total')|is_number }}"

so the problem I am facing is because a sensor is becoming unavailable but the utility meter see this as zero and does some calculations that are not intended?

I was only normalize values and putting zero or keeping the previous value in order to avoid unexpected behavior when a sensor became unavailable for some reason.

But if this is the case why in the scenario that I describe above will not cause problems? I mean when for a brief period of time the power consumption becomes larger than the productions and the value goes to zero for little while? Is this different when I normalize the values?

I don’t know anything about your “normalisation” but yes by making the sensor go unavailable rather than 0 when the calculation is not possible the utility meter will not record the huge jump in value.

e.g. when the utility meter sees:

3000 → 0 → 3000

it adds 3000 to the running total.

However when it sees:

3000 → unavailable → 3000

it adds nothing.

ok I see. If I want to have meaningful values (maybe when view on dashboard) I can create two sensors, one with “normalize” values (on the dashboard) and one for feeding to utility meter. Maybe this is better yes?

I don’t understand what your “normalize” is required for. Are you not feeding the energy dashboard the correct values?

by normalize I mean I am trying to keep the values of a senors to the most appropriate value if for some reason the sensor does not get the correct data.

For example lets say that because of another issue (network issue) the power generation inverter becomes unavailable. The history will not be displayed very good and it will have caps inside. I thought that by keeping the last know value (as soon as is not night and the inverter is on) it will have more ‘compatible’ values that just leave it with unavailable.

At least that was my idea :slight_smile:

What are caps?

sorry I meant gaps. type error :slight_smile:

Gaps are meaningful data. It shows you when there is an issue you need to correct.

Your power sensors will still report 0W when not producing or consuming anything. The Riemann Sum integration will stop counting when this happens and stay at the last value, as will your utility meters. That has not changed.

Your sensors will just have gaps when there is an actual issue with your sensors you need to fix. e.g. they become disconnected from the network for some reason.

The problem is that sometimes there are issues that are not possible to fix, maybe come from other sources you have no control over.

I will make the changes as you describe tom and I will let you know if the problem persists.

Thanks

Phanos

If it is not possible to fix the problem you will never have meaningful data.

Hello,

I have the same issue with my Dashboard Energy, my setup is:

  1. I collect data from Solaraman logger with a curl command:
  - platform: command_line  
    command: curl -s -u admin:admin http://10.10.0.14/status.html | grep -E "\webdata_total_e(\s|$)" | cut -d'"' -f 2
    name: solarmanlocal_power_solar_total
    unit_of_measurement: 'kWh'
    scan_interval: 60

The advantage is that I collect directly in kWh and I do not need to do any conversion

  1. For Energy Dashboard I have a template sensor :
  - name: "solarmanlocal_production_daily_new"
    state: "{{ states('sensor.solarmanlocal_power_solar_today')}}"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    unique_id:  solarmanlocal_production_daily_new

In HA all values are correct, for example now I have yield today 12.37kWh

Template sensor value is the same as the logger value:

But in the Energy Dashboard solar production is 19.2kWh

I monitor my house consumption with a Shelly 3EM , I removed those but the problem is still present.

I also tried to change the database from SQLite to Maia DB, also same problem.

I do not know what to do , and any suggestion is welcomed :slight_smile:

Hello, I have the same problem like you if I’m using today sensor, at the end of the day, there is more energy produced in energy dash than the entity itself.
But if I’m using total energy, the problem is that every morning it starts with total value (big value) and after that it gets corrected , and if I calibrate sensor in statistics to start with 0 value, than the rest of the day is good.
Did you managed to fix somehow?

Was this ever resolved? I have been battling with this issue for a long time myself.

I have two Solar Inputs in kWh and a little reader sitting on my meter that gives me the daily energy consumption. My Inverter also provides data for Battery Charge and Discharge.

The issue is…the value HA calculates for “Home Consumption” appears too high. I have no sensor dropouts or anything, it just seems that HA is calculating the energy consumption in a way that isn’t quite correct as far as I can tell…