## 2 Structure and Operation of the Grid-Connected Microgrid
### Microgrid Operation in Grid-Connected Mode  
In grid-connected mode, the microgrid under study is in charge of smoothing the grid power profile through suitable control of the power injected/absorbed by the battery ESS. The EMS is based on a control strategy described in [43]. The goal of the EMS is to perform the suitable use of the energy stored in the battery ESS to cover part of the energy required by the EWH for keeping the water temperature in the thermal storage between established limits. In this regard, the control of the battery power, \(P_{BAT}\), is indirectly performed by controlling the power supplied by the battery ESS for the EWH consumption, \(P_{WH}^{B}\), and  
Figure 2: Microgrid power profiles: (**a**) Photovoltaic power, (**b**) wind turbine power, (**c**) solar thermal collector power, (**d**) domestic load demand, (**e**) electric water heater power, and (**f**) domestic hot water equivalent power. imposing the desired grid power profile, \(P_{GRID}\). In [43], the grid power profile is defined as the sum of three components, as follows:  
\[P_{GRID}(t)=P_{CTR}^{*}(t)+P_{SOC}(t)+P_{PLC}(t) \tag{1}\]  
\[P_{BAT}(t)=P_{LG}(t)-P_{GRID}(t)+P_{WH}^{B}(t) \tag{2}\]  
\[P_{LG}(t)=P_{LOAD}(t)+P_{WH,E}(t)-P_{PV}(t)-P_{WT}(t) \tag{3}\]  
where \(t\) is the current sample, \(P_{CTR}^{*}\) is the output of a central moving average (CMA) filter, which establishes the MG average power profile, \(P_{SOC}\) is the output of the battery control loop, which is used to keep the battery SOC close to the 75% of the battery rated capacity, \(P_{PLC}\) is the output of an FLC block, which is used to smooth the grid power profile according to the microgrid power forecast error and the battery SOC [40; 43], \(P_{LG}\) is the microgrid net power, \(P_{LOAD}\) is the domestic load demand, \(P_{WH,E}\) is the EWH power, \(P_{PV}\) is the photovoltaic power, and \(P_{WT}\) is the wind turbine power. The EMS block diagram comprises six blocks [43], see Figure 3, which regulates both the power delivered by the utility grid and the power injected or absorbed by the ESS. Where \(P_{GEN}\) is the renewable power generation, \(P_{LG}^{*}\) is the modified MG net power defines as \(P_{LG}^{*}(t)=P_{LG}(t)-P_{WH}^{B}(t)\), being \(P_{WH}^{B}\) the power injection to the EWH from the battery ESS, \(P_{LC,FC}^{*}\) is the forecast of the modified MG net power, \(P_{E}^{*}\) is the MG forecast error, \(P_{E}^{BM*}\) is the power forecast error of the previous 3-h, \(SOC_{AVG}\) is the average battery SOC of the previous 24-h, \(SOC_{REF}\) is the battery SOC reference value (i.e., \(SOC_{REF}=75\%\)), \(k_{e}\) is the proportional gain constant (i.e., \(k_{e}=0.05\)), and \(P_{BAT}^{MC}\) is an auxiliary variable used to compute the battery power. Note that the step-by-step design of the EMS is out of the scope of this paper. However, for complete descriptions of each block within the EMS design (see Figure 3), readers can refer to [43]. Figure 3: Energy management strategy block diagram [43]. ©2018 IEEE, Reprinted, with permission from [PERSON]. [PERSON] et al., “Fuzzy-based energy management of a residential electro-thermal microgrid based on power forecasting,” in IECON 2018—44 th Annual Conference of the IEEE Industrial Electronics Society, Washington, DC, USA, October 2018, pp. 1824–1829. In the diagram shown in Figure 3, block number six constitutes the one that is responsible for smoothing the power profile exchanged with the grid. This block consists of an FLC that assumes a Mamdani-based inference and defuzzification method of the Center of Gravity of two input, one output, and 25 rules. The inputs of the FLC are the current battery SOC and the power forecast error of the previous 3-hours, \(P_{E}^{3H*}\), which is defined as:  
\[P_{E}^{3H*}(t)=(1/M_{3}){\sum_{k=1}^{M_{3}}}P_{E}^{*}(t-k) \tag{4}\]  
where \(k\) is the sample index, \(M_{3}\) is the number of samples in 3-h, and \(P_{E}^{*}\) is computed as \(P_{E}^{*}(t)=P_{LG}^{*}(t)-P_{LG,FC}^{*}(t)\).