Template sensors this morning started calculating zero energy intermittently, causing energy usage to go haywire

Thank you again @tom_l I’m forever grateful. It appears data is now reported correctly.

As a note to anyone else finding this post in the future: Since both energy sensors are (I believe correctly) set up as state_class: "total_increasing" I had to do some clean up of bad data in the database. I found this article https://developers.home-assistant.io/docs/core/entity/sensor/#state_class_total_increasing very helpful in understanding the behavior of the total_increasing state_class and why I got the data I got (TL;DR any decrease in state/value is interpreted as a reset of the devices measurement, ie a meter is reset to 0 on the device, or perhaps exchanged for a new device). I found this post useful https://community.home-assistant.io/t/how-to-fix-statistics-data-e-g-energy-data/360966 in verifying what needed to be done (had mostly figured that out but nice to see others coming to the same conclusion)

However: That last article does not (as far as I can tell) handle the statistics_short_term database table. And from my experience you will need to do the same for this table as for the long term statistics database table. I.e adjusting all values from after the time of your error. From my experience it appears HA Puts a snapshot into statistics_short_term every 5 minutes, and into statistics every hour and crucially the creation of the hourly statistics data is based on an aggregation of statistic_short_term data. So: Live – every 5 min → statistics_short_term – every hour → statistics. I cannot find any documentation on this (though I’m sure it exists) and I might very well be wrong, in which case I gladly stand corrected. Please comment if you know.

Finally I also removed any erroneous values from the states table. Just to make sure the graphs looked good everywhere.

Again thanks for helping me out @tom_l