## 3 Real-Time Control Strategy Considering Cost per kWh of Storage Batteries  
### Mathematical Model of Control Strategy  
In the grid-connected mode of the distributed microgrid system, the current economically optimal mode is \"self-generated self-use, surplus electricity to the utility\". The internal composition of the microgrid can be divided into three categories: resource, load, storage, and distribution grid system. In addition, there are four types of unit: resource, load, storage, and the utility related to the energy flow of the microgrid. If the energy management of the microgrid does not abandon PV power or load controlling under special circumstances, the execution unit is generally the ESS. The main function of the energy storage system is to compensate the energy margin. The mathematical model of the energy margin in the PV and storage microgrid is:  
\[\Delta P(t)=P_{pv}(t)-P_{L}(t) \tag{1}\]  
For microgrid systems, this power margin can be compensated by the ESS or the utility:  
\[\Delta P(t)=P_{\textit{es}}(t)+P_{\textit{pcc}}(t) \tag{2}\]  
When choosing which form of electricity to supplement the power margin, the costs of the ESS and the distribution grid system are compared, and the one with the lower use cost is preferred. When the ESS encounters state of charge (SOC) limits or charge and discharge power limits, it is all digested by the distribution grid. The mathematical expressions of the cost per kWh of the ESS and electricity price of the utility are as follows:  
\[C_{\textit{es\_unit}}=\frac{C_{\textit{rep}}}{E_{\textit{lifecycle\_les}}} \tag{3}\]  
\[C_{\textit{g\_unit}}=V(t) \tag{4}\]  
where \(C_{\textit{es\_unit}}\) is the cost per kWh of the ESS. This is not the cost of the initial installation of the ESS, but only the cost of battery life loss, because the ESS generally does not need to be replaced except for the batteries. \(C_{\textit{rep}}\) is the total cost of replacing the batteries, \(E_{\textit{lifecycle}}\) is the total energy value that the batteries can emit throughout their life cycle, in kWh, \(\mu_{\textit{es}}\) is the charge and discharge efficiency of the ESS, and \(C_{\textit{g\_unit}}\) is the electricity price of the utility. The implementation of the energy management strategy is mainly achieved by controlling the energy storage power, and the point of common connection (PCC) power can be obtained naturally from the power flow relationship. The execution mathematical expression of the above algorithm is:  
\[P_{\textit{es}}(t)=\left\{ \begin{array}{ll}\Delta P(t)&C_{\textit{es\_unit} }<C_{\textit{g\_unit}}\\ 0&C_{\textit{es\_unit}}\geq C_{\textit{g\_unit}}\end{array} \right. \tag{5}\]  
In the period when the grid electricity price is relatively high, the ESS is used first. Before controlling the ESS, whether the power in the ESS meets the requirements must be considered. When the new energy generation in the microgrid exceeds the load power consumption, the corresponding strategies are formulated according to different situations:  
(1). The excess photovoltaic power is less than the maximum chargeable power of the ESS:  
\[\Delta P(t)\leq P_{\textit{es\_ch}}^{max} \tag{6}\]The ESS absorbs the entire power margin:  
\[P_{es}(t)=\Delta P(t) \tag{7}\]  
(2). The excess power of photovoltaic power generation is greater than the maximum charging power of the ESS, and the distribution grid can absorb excess power:  
\[P_{es\_ch}^{max}<\Delta P(t)\leq P_{es\_ch}^{max}+P_{pcc\_ab}^{max} \tag{8}\]  
At this time, the ESS is charged at full power, and the remaining power is absorbed by the distribution grid:  
\[P_{es}(t)=P_{es\_ch}^{max} \tag{9}\]  
\[P_{pcc}(t)=\Delta P(t)-P_{es\_ch}^{max} \tag{10}\]  
(3). The extra power generated by photovoltaic power generation is greater than the maximum charging power of the ESS and exceeds the dissipation capacity of the distribution grid:  
\[\Delta P(t)>P_{es\_ch}^{max}+P_{pcc\_ab}^{max} \tag{11}\]  
At this time, the ESS is charged at full power, and the distribution grid is fully loaded to send electricity.