Solar production numbers in energy seems strange

I have solar panels and use integration pvoutput to get the production information to HA. My sensors are created like this:

      power_generation:
        value_template: '{% if is_state_attr("sensor.pvoutput", "power_generation", "NaN") %}0{% else %}{{ state_attr("sensor.pvoutput", "power_generation") }}{% endif %}'
        friendly_name: 'Generating'
        device_class: "power"
        unit_of_measurement: 'W'
      energy_generation:
        value_template: '{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(state_attr("sensor.pvoutput", "energy_generation")|float/1000) }}{% endif %}'
        friendly_name: 'Generated'
        device_class: "energy"
        unit_of_measurement: 'kWh'

and they are customized like this:

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

as a workaround due to a problem in pvoutput.

For some time I have used graphs based on the sensors which looks like this to day:

Now I have started to configure the new Energy component in HA with my sensors. The energy page looks like this:

The negative production at 6:00 is a bit strange for me to understand. Earlier this day the Generated under the Source section was negative.

I’m using the sensor sensor.energy_generation in the solar panel configuration for Energy.

I realize that I\m doing something wrong but I do not understand what.
Any ideas?

Your generated graph shows the accumulated total energy resetting at about 6am. This is causing your negative value issue.

The last_reset attribute needs to be set to this time (and date) for the sensor to be able to be used.

You also need to wait for an update to allow the use of accumulated energy sensors that reset periodically. At the moment the energy monitor can only work with always increasing energy totals. I believe this is coming soon.

1 Like

Thanks for the answer! I do not fully understand what I should do yet.
The last_reset is at 00:00 now in my config if I understand that attribute correct. Should I set to
last_reset: '1970-01-01T06:00:00+00:00'
instead?

I also found another thread that discussed the energy config:

I will look into that as well.

You need to set it to the last time and date it reset. And do that every time it resets.

I have to admit that I feel a bit stupid now. I don’t undrstand what you mean with

You need to set it to the last time and date it reset. And do that every time it resets.

What do you refer to when you write “it reset”?

If I look at the data for the last three days the Generated sensor has been reset at 06:08, 06:33 and 06:22.
My interpretation is that I should try to change the reset time to before 00:00 for the sensor. I guess that the Energy graphs assume reset at 00:00 to handle one day at a time.
Am I thinking right here?

No.

i.e. these times (and dates):

This is the proof that I’m stupid. :slight_smile:

I don’t realize WHAT I should right WHERE.
For the sensor I can set last_reset to e.g.

last_reset: '2021-08-22T06:22:20+00:00'

since that was the last reset.
But you wrote

I assume I should not update thge config every day… I’m not that stupid. :wink:

Yes you should. Well not the config, the value.

That’s what this means:

A triggered template sensor, or automation to set the last_reset time would be the way.

Ok, I really need more of the documentation to understand what you mean. I have no doubt that you are right.
I’m using the proposed template sensor for pvoutput: PVOutput - Home Assistant
I now found ongithub that more persons have the same problem as I see. There is a proposed workaround in PVOutput integration Expected data source not listed · Issue #54506 · home-assistant/core · GitHub that I will look at.

With the release of 2021.9.2 it looks like the prerequisites have changed. If I understand it correct the last_reset attribute is not there anymore. My understanding after reading about sensor state class total_increasing I now think that the sensor for my energy measurement should be like this:

      energy_generation:
        value_template: '{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(state_attr("sensor.pvoutput", "energy_generation")|float/1000) }}{% endif %}'
        friendly_name: "Generated"
        state_class: total_increasing
        unit_of_measurement: "kWh"

Have I understood it correct now?

Yes you have.

1 Like

Now it will be interesting how the graph looks tomorrow. :slight_smile:

i have the same issue with pvoutput, it should by as an energy sensor available but i cannot choose it in the energy dashboard to select is. When making a custom template sensor, it is working, but sensor data seems to be off.

Define your sensor as follows:

  - platform: template
    sensors:
      energy_generation:
        value_template: '{% if is_state_attr("sensor.pvoutput", "energy_generation", "NaN") %}0{% else %}{{ "%0.2f"|format(state_attr("sensor.pvoutput", "energy_generation")|float/1000) }}{% endif %}'
        friendly_name: "Generated"
        unit_of_measurement: "kWh"

Add this to customize.yaml:

sensor.energy_generation:
  state_class: total_increasing

Restart your HA.
Now you should be able to chose the sensor in the energy production.

1 Like

I understand the way this is possible, but should’n this working without manual sensor state definition?
See release notes:

Pvoutput is included.

1 Like

Why was it hard to explain with work example. There are many out there who are not experts and need help instead of guessing game

I’m of the opinion that people learn more by working through a problem themselves with just a bit of a push in the right direction rather than blindly copy and pasting.

In the end the Devs simplified the process and Niklas worked it out for himself and just asked for confirmation of this.

So an example was neither required nor requested.

1 Like