Energy Billing Calculation

I have HA for monitoring solar PV system. I am using the Built-in energy dashboard to calculate production/feed-in/battery charge etc. All is working fine including the calculation at different rates at different times of the day.

Sometimes one of the values goes crazy, and I know how to fix the problem from statistics when this happens, but this skews the billing calculation and when the statistical value is fixed, the billing calculation remains wrong. What can I do to fix this?

There are many posts asking this question. So far I have yet to see an answer, and I do not know myself.

Which is one of the reasons I make my own cost sensors.

Is your project available publicly which I could use until maybe someone fixes this?

Thanks!

No it is not. They’re just utility meters and template sensors that multiply the energy by the price. I have two tariffs though (peak and off-peak) that complicate things slightly.