## 5 Simulation Results and Discussion of the Developed Model
The battery in this case is not charging or discharging. As shown in Figure 9, the output result from the EMS algorithm shows that all the loads are supplied without any interruption because the power produced meets the demand of the loads. In this case, the battery bank and the damp load are 0, which means that they are disconnected. Figure 8: Transition state from the Stateflow chart for the first scenario. Figure 7: Power and voltage generation. **Case 2:** Here, the power generation becomes higher compared to the load requirements, as shown in Figure 10. Thus, the EMS checks if the battery is fully charged or not. If the SOC is less than 100%, as shown in Figure 11, the loads are supplied by the power produced, and at the same time, the battery is connected to be charged by the excess of production until it reaches its charge limit, which is 100%. Figure 10: Power generation. Figure 9: EMS control output results for the first scenario. Figure 11 presents the battery graph in which it shows the battery charging. When the battery reaches its maximum charge value (100%), it is disconnected from the system to wait for the discharge phase. Figure 12 shows that the loads and battery outputs are \(1\), while the damp load output is 0. This means that the loads are supplied, and at the same time, the battery is also charging. Figure 13 shows the transition from the Stateflow chart. Power supplied from the RESs is 298 kW, and the demand of the loads is 280 kW. Thus, the excess of production (18 kW) is stored in the battery, as shown in Figure 13.  
Figure 11: Charging mode of the battery. Figure 12: EMS control output results for the second scenario. When the battery is fully charged (100%), the surplus of production is transferred to the auxiliary load, as shown in Figure 14, until the power generation meets the demand of the loads or the condition changes. **Case 3:** The power generation becomes lower than the load requirements, as shown in Figure 6:0 Based on the EMS control, the loads are supplied by the help of the battery. Firstly, the SOC of the battery is measured. If the it is more than 20%, then the battery is connected to be discharged. The condition is that, when the SOC becomes equal to or less than 20%, automatically, the battery must be disconnected from the system. Figure 6:1 EMS control output results for the second scenario: battery fully charged. Figure 6:2 Transition state from Stateflow chart for the second scenario. In Figure 16, the battery is charging. When the minimum value of the SOC is reached, then the battery stops discharging to avoid deep discharge. Figure 17 presents the results from the Stateflow chart, where the battery is connected to be discharged. Figure 6:3 Discharging mode of the battery. Figure 6:4 Power generation. Once the SOC of the battery becomes 20%, the battery is disconnected. The EMS control allows power to be supplied to the priority load, which is the industrial load (Load 1). Before that, the EMS measures the power generation to check if it is able to provide power to the priority load and charge the battery at the same time; if the condition is approved, then the battery is charged as well. Figure 18 presents the simulation results, showing that the priority load is supplied by the power generation, and Figure 19 illustrates the transition state. Figure 6:5 Transition state from Stateflow chart for the third scenario. Figure 6:6 EMS control output results. When the power generation is not able to simultaneously supply the priority load and charge the battery, the EMS control checks if the power generation can handle the priority load. If the condition is met, then the priority load is supplied by the available power produced, as presented in Figure 6:7  
When the power generation becomes lower than the priority load, the EMS control checks if the power generated is able to supply the residential load (Load 2) or both supply the residential load and charge the battery at the same time.