Home assistant energy - negative values

Hello,

i have the problem that home assistant energy is showing wrong values.
For example if my photovoltaic produced 2.4kWh, import/bought 1.24kWh and exported nothing it shows wrong values like in the screenshot. The data is coming over mqtt.

there is the customize.yaml file:


sensor.pv_energy_today:
  last_reset: '1970-01-01T00:00:02+00:00'
  device_class: energy
  state_class: measurement

sensor.energy_import:
  last_reset: '1970-01-01T00:00:02+00:00'
  device_class: energy
  state_class: measurement

sensor.energy_export:
  last_reset: '1970-01-01T00:00:02+00:00'
  device_class: energy
  state_class: measurement

I didn’t found a solution so far.
How can i fix it?

10k-resistor

The problem is that your solar consumption energy sensor is resetting to 0 rather than continuously increasing.

You are using the daily PV yield sensor instead of the total PV yield sensor.

1 Like

I have the same problem. But I set the last_reset value each day to the correct date time value. That has no influence.

I have the same problem of negative data without solar device, how can I solve it?

1 Like

As I said:

You need to use the total yield sensor. Not the daily yield sensor.

1 Like

There have been some changes to the attributes that should allow you to use a daily sensor like that once they have been merged:

I’m currently using pvoutput to get my solar energy generation. Since that only returns a daily running total I have knocked up an automation and some sensors to track the running total Is there a better way than this?

template:
  - sensor:
      - name: "Power Generation"
        unit_of_measurement: "W"
        state_class: "measurement"
        device_class: "power"
        unique_id: pvoutput_power_generation
        state: '{% if is_state_attr("sensor.pvoutput", "power_generation", "NaN") %}0{% else %}{{ states.sensor.pvoutput.attributes.power_generation }}{% endif %}'

  - sensor:
      - name: "Solar Energy Running Total"
        unit_of_measurement: "kWh"
        state_class: "measurement"
        device_class: "energy"
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"
        unique_id: solar_energy_running_total
        state: 0

input_number:
  solar_generation_daily_last_update:
    step: .001
    unit_of_measurement: kWh
    min: 0
    max: 30

automation:
  - alias: calculate_running_solar_generation
    id: calculate_running_solar_generation
    trigger:
      - platform: state
        entity_id: sensor.energy_generation
    action:
      - service: python_script.set_state
        data_template:
          entity_id: sensor.solar_energy_running_total
          state: "{{ (states('sensor.solar_energy_running_total') | float) + (states('sensor.energy_generation') | float) - (states('input_number.solar_generation_daily_last_update') | float) }}"
      - service: input_number.set_value
        target:
          entity_id: input_number.solar_generation_daily_last_update
        data:
          value: "{{ states('sensor.energy_generation') }}"

Python script from here How to manually set state/value of sensor? - #3 by rodpayne

There are three main inputs - solar, grid usage (or ‘in from the grid’) and energy export (or ‘out to the grid’). Should any of these be negative? Right now I have all of mine set to result as positive (I use IotaWatt and can modify if the result shows negative or positive).

I’m using a sensor.boiler_energy (from “Meross LAN” integration):

state_class: measurement
last_reset: '1970-01-01T00:00:00+00:00'
unit_of_measurement: Wh
friendly_name: Boiler - energy
device_class: energy

Here the abnormal data in Energy tab: https://www.webg.it/images/articoli/2021-08/Screenshot_22.png

This is the graph of this sensor: https://www.webg.it/images/articoli/2021-08/Screenshot_21.png

You need to use the total yield sensor

Ok, how can I collect data in a new sensor compatible with Energy? Can you give me an example please?

Thanks
Marco

Wait for the next release of Home Assistant. This should fix the last_reset issues.

The next release will prevent resetting data every day?

No, but it will deal with those resets better.

I created this topic today, I think I know a little bit about the origin of the negative values

I’ve the same problem but its very weird. In the “Year” view I see the negative consumption in may. If I go to May in the Month view I cant see negative values but there is very low consumption for 1-4 May and for 5. there is always 0 if I check via developer → statistics → total_in entity.

Year View

Month View

If I look at the consumption for May I got very high values.

I can edit the values for the 5. May but they will not be accepted (stay 0).