Energy dashboard - solar electricity balance calculation


In my country we have the option to use the electricity network as a “battery”; therefore the electricity meter is read once per year and we pay the difference between the consumed and produced electricity. Naturally there are two options:

  • if your balance is positive (electricity surplus) then you will be paid for the extra energy BUT the selling price is much lower compare to the price you buy the electricity (about half the price per kWh)
  • if your balance is negative then you have to pay for the difference

Therefore the ultimate goal is to complete the charging period with an almost zero balance.

It would be useful to register the meter readings in the electricity dashboard (consumed kwh and produced kwh) and from that moment it would calculate the current balance compare to the latest registered values.

Example use case

  • meter readings on 1st of January: 2000 kwh consumed from grid and 1950 kwh produced (to grid). Therefore we pay 50 kwh in this case.
  • we need an option to register this reading in the Energy dashboard
  • all additional consumption from grid and production to grid is calculated on top of the registered value
  • home assistant would keep track of the current balance: shows difference between the two values on the fly

Benefits: users can keep track of current balance without manually reading the electricity meter and calculate. If you know the current balance then you can consciously manage your consumption. For example if you have 400 kwh surplus then you heat with your AC instead of gas heating to consume the surplus.

Note: I have all these calculations at the moment in HASS. It would be nice to have this as a feature of Energy dashboard therefore I don’t have to maintain a separate dashboard for it.


Do you use some kind of formula for calculating this balance? Is it like a flow calculation?

In my country we have also similar approach, but with difference when you have electricity surplus, then you are not eligible to get anything paid. So, during the fall and beggining of winter when the electricity demand is higher if you are using electricita for heating (f.i. with heat pump) you ought to know how your balance is.
I manily use manual calculation from my solaredge meter or official data from electricity provider, but I still didn’t implement it in HA.

Do you have any idea how to do it? Do you have any already ready solution?

Thank you in advance!

Could you please share your calculations what you mentioned?

I also have a PV system which I can track and a shelly 3EM on the incoming 3 phase wires right after the meter, before the junction of the solar and home cables.
I’d be interested in using the surplus produced energy until I can use the network as a battery.

Hi, Levente, I’d be very grateful if you could share the code please? Thanks!