I’m in the process of developing a software program to sell electricity to the power utility grid from my solar battery storage system. Daily i need to calculate what part of the battery storage is safely sold and still maintain my power requirements.