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.
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:
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?
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:
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.
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.