## 3 Energy Management System
 \tag{18}\]  
where \(P_{solar}(t)\), \(P_{wind}(t)\) and \(P_{fuel\ cell}(t)\) are power generated from each DER while \(\eta_{DC/DC}\), \(\eta_{AC/DC}\) and \(\eta_{DC/AC}\) are the efficiencies of corresponding inverters. \(P_{Load}(t)\) shows the total power consumed by the load. \(P_{selt\_grid}(t)\) and \(P_{buy\_grid}(t)\) are power sold to and bought from the main grid, which are determined based on predefined exchange rates at specific time intervals. The optimization problem for energy management needs to incorporate the maximum allowable exchanged energy, as dictated by the technical constraints of the system such as capacities of transformers, circuit breakers, and the distribution network. Therefore, it must be ensured that the exchanged energy remains within the limits set by the maximum allowable selling and buying energy in the hybrid microgrid and can be measured by (19) and (20):  
\[P_{buying}(t)\leq P_{buy\_maximum} \tag{19}\]  
\[P_{selling}(t)\leq P_{sell\_maximum} \tag{20}\]  
where \(P_{buying}\) and \(P_{selling}\) represent the buying and selling powers, respectively, and \(P_{buy\_maximum}\) and \(P_{sell\_maximum}\) denote the maximum allowable power that can be bought or sold at time t. The constraint of the hydrogen generation strategy is that each hybrid MG is limited to utilizing only its renewable energy resources for hydrogen production, and it can be measured in (21):  
\[P_{solar}(t)+P_{wind}(t)\geq P_{EL}(t) \tag{21}\]  
At this point, it is necessary to define the limits of the hydrogen storage system. During regular operating hours, hydrogen gas is generated by the electrolyzers using available power that can be measured in (22). The upper and lower limits of power consumption by the electrolyzers are detailed in (23) and (24):  
\[H_{2\_EL}=\frac{\eta_{EL}P_{EL}}{LHV_{H_{2}}} \tag{22}\]  
\[P_{EL}\leq P_{EL\_max}\times U_{EL} \tag{23}\]  
\[P_{EL}\leq P_{EL\_min}\times U_{EL} \tag{24}\]  
where \(H_{2\_EL}\) is the hydrogen produced by the electrolyzer and \(\eta_{EL}\) shows the efficiency of the electrolyzer at which the power is consumed to produce the hydrogen in off-peak hours. \(P_{EL}\) is the actual power consumed in watts W. The maximum hydrogen produced by the electrolyzer can be expressed in (25). \[H_{2\_EL}\leq H_{2\_EL\_max}\times U_{EL} \tag{25}\]  
Likewise, fuel cells utilized the produced hydrogen, and its constraints are expressed in (26). Meanwhile during the peak hours of the system, the electrical power can be expressed (27) and (28), which is produced by fuel cells:  
\[H_{2\_FC}\leq P_{FC\_max}\times U_{FC} \tag{26}\]  
\[P_{FC}\geq P_{FC\_min}\times U_{FC} \tag{27}\]  
\[P_{FC}\leq P_{FC\_max}\times U_{FC} \tag{28}\]  
where \(H_{2\_FC}\) is the hydrogen produced by the fuel cells. Other quantities of power produced by the fuel's cells are already expressed in the above section. Multiple objectives are considered in the designing of the EMS, like technical and economic aspects. Technically, the EMS should maximize the equipment life and minimize the power loss during supply to load. The second half is an economic aspect; in this part, obviously, it should be cost-effective. The proposed flow chart of the EMS is presented in \[P_{selling}(t)\leq P_{sell\_maximum} \tag{20}\]0 Expected solar and wind radiation on a daily basis are elaborated in Figures 7 and 8. Variations of these curves depend on the weather conditions. The dotted line shows the average of both solar radiation and wind speed on a daily basis. The EMS includes various constraints, such as those pertaining to hydrogen energy storage, handling excess power generated during hydrogen storage, scenarios where power is required from the utility, and time constraints, all of which are detailed in Sections 2 and 3. \[P_{selling}(t)\leq P_{sell\_maximum} \tag{20}\]1 Flow chart of the proposed energy management system (EMS). \[P_{selling}(t)\leq P_{sell\_maximum} \tag{20}\]2 Expected solar panel radiation for 24-h.