Energy Dashboard and Batteries

Hi

I have a sensors that will tell me

The amount of Energy Generated by my Solar Panels
The amount of Energy imported and exported to/from the Grid
The amount of Energy used by my house.

But I dont have a sensor that tells me how much energy is going in and out of my batteries.

I need to write a Template Sensor with this data to give me some values that I can add to the Battery Section of the Energy Dashboard, but I am really struggling with it.

Is anyone able to help please?

Many Thanks

Battery power is Solar - House - Grid Export + Grid Import.
But you shouldnt use energy sensors for that but power sensors.
If you dont have these, you can use utility meters which reset hourly, but then I dont know how to implement that correctly.