Create a power meter

Hi to all, guys please advice how to create an power meter of used power from my inverter.
I have an inverter with 300Ah battery and SOC is not transfered to HA so I don’t understand how many is used when is used from the battery.
I have created an entity "power loss’ that indicate when the power from the grid is loss so it will be the trigger and “charge state” . I have sensor “battery power” and also have a sensor “charger power” from the inverter.
So the idea is create a power meter that is triggered by “power loss” and start to decrease from 15000W using "battery power’ until “power loss” tuns off then use “charge state” changes his state from stop to start and then use “charger power” to fill it up again up to 15000W.

I know that is seems to be strange but is the way I can see how many watts is used from the battery and how many watts are returned. Actually i’am an noob at programing so please advice how to make this :slight_smile:

P.S. sorry for my English ))