some known equilibrium operation points are used. For instance, the photocurrent $I_{ph}$ is
defined by:

$$
I_{ph} = [I_{sc} + K_i (T_{op} - T_{ref})] \cdot \frac{G}{G_{ref}}, \qquad (3.5)
$$

where, $I_{sc}$ is the short circuit current, $K_i$ is the short circuit temperature coefficient at $I_{sc-ref}$ ($T_{ref} = 25 + 273 \text{ K}$, $G_{ref} = 1000 \text{ w/cm}^2$), $G$ and $T_{op}$ present respectively the operational irradiance and temperature. According to the equation (3.1), the PV cell current at the standard test conditions is obtained by equation (3.5.a). In fact, by considering that the PV cell is short-circuited ($V=0$), we have: $I_{sc,ref} = I_{ph,ref}$ and the photocurrent depends on the input parameters of weather condition (Temperature, Irradiance).

$$
I = I_{ph,ref} - I_{o,ref} \cdot \left[ \exp \left( \frac{V}{N_s \cdot \text{n.} \cdot V_{t,ref}} \right) - 1 \right] \quad (3.5.a)
$$

For the reverse saturation current $I_o$, it is proportional to the cube of the PV cell
temperature and it is presented by equation (3.5.b) as follows:

$$
I_o = I_{rs} \cdot \left( \frac{T_{op}}{T_{ref}} \right)^3 \cdot \exp\left[ N_s \cdot \left( \frac{1}{T_{ref}} - \frac{1}{T_{op}} \right) \cdot \frac{E_g \cdot q}{K \cdot n} \right] \quad (3.5.b)
$$

where $E_g$ is the band gap energy of the semiconductor and $I_{rs}$ is formulated by equation (3.5.c).

$$
I_{rs} = I_{sc} \cdot \left[ \exp \left( \frac{V_{oc} \cdot q}{K \cdot n \cdot T_{ref} \cdot N_s} \right) - 1 \right] \quad (3.5.c)
$$

Since the value of $E_g$ is not provided by the datasheet of the PV cell manufacturer, in or
study $I_o$ is calculated using the equation presented in (Villalva et al., 2009) as follows:

$$
I_o = \frac{I_{ph,ref} + K_i (T_{op} - T_{ref})}{\exp\left(\frac{q \cdot (V_{oc,ref} + K_u (T_{op} - T_{ref}))}{K \cdot n \cdot T_{op} \cdot N_s}\right)}, \quad (3.6)
$$

In this equation, the different parameters can be calculated using the known values
provided by the manufacturer. The $K_i$ and $K_u$ are respectively the short circuit current
temperature coefficient and the open-circuit voltage temperature coefficient for the PV, which
we have used in this practical application. Regarding the series and the shunt resistances determination, they can be approximated from the slopes of the I-V curve at $V_{oc}$ and $I_{sc}$, respectively. The resistance at $V_{oc}$ is best proportional to the series resistance $R_s$, but it is larger than the parallel resistance. $R_p$ is represented by the slope at $I_{sc}$. Typically, the resistances at $I_{sc}$ and at $V_{oc}$ will be measured and noted by the manufacturer.

## 3.2. Wind energy production

The WT is a source of energy that depends principally on the wind speed. It is considered as one of the most significant clean energy sources. The transformation of this energy into electricity is ensured through WTs, which can cover a wide range of power depending on the needs and the type of generation chosen. For example, offshore WTs can have several tens of meters in height in order to generate several megawatts of electricity, which makes them interesting solutions to generate electricity for a national network. Other WTs, not exceeding ten meters and they are more suitable for domestic usage, producing a few hundred or thousands of watts. They must be installed in open spaces to improve their production, especially for safety reasons. They are therefore perfectly adequate for an isolated structure, such as a farm, where space is available.

Several WT structures exist, which can be chosen according to the generated power, the range of wind speeds, and the desired dimensions. Two types of architecture are to be distinguished, Horizontal Axis-WT and Vertical Axis WT. Mainly, various research works on vertical axis WT were carried. Actually, more research works focus on horizontal axis WT, which is more efficient at large scales. In fact, the horizontal axis WT is highly developed and used in all current large-scale wind farms. In this section, the horizontal axis WT, which was deployed in our MG system is modeled and characterized for seamless integration into buildings.

### 3.2.1. Wind turbine modeling

An aerodynamic generator study is important to simulate correctly the implemented WT. In fact, due to the velocities of the air behind the WT, the power recovered from a WT is less than the power of the wind. It then defines what is called a power coefficient $C_p$ as being the ratio of the mechanical power produced by the aerodynamic system of the wind $P_t$ divided by the kinetic power of the wind $P_v$. The mechanical power produced by the turbine is given as follows:
$$P_t = C_p \cdot P_v = \frac{1}{2} C_p \cdot \rho \cdot S \cdot v^3 = \frac{1}{2} C_p \cdot \rho \cdot \pi \cdot R^2 \cdot v^3, \qquad (3.7)$$

where S is the area swept by the turbine, v is the wind speed, R is the radius of the blades, ρ is the density of the air (ρ = 1.225 kg/m3) in standard test conditions. It is important to note that the ratio between the turbine speed and the wind speed is expressed by equation (3.7.a) as follows:

$$\lambda = \frac{\Omega_t \cdot R}{v} \qquad (3.7.a)$$

where Ω_t represents the turbine rotation speed. Moreover, the power coefficient C_p depends on the pitch angle and the number of blades constituted the aerodynamic generator. It can be estimated by equation (3.7.b):

$$C_p = 0.5716 \left( \frac{116}{\lambda_i} - 0.4\beta - 5 \right) e^{\frac{-21}{\lambda_i}} + 0.0068 \lambda \qquad (3.7.b)$$

The expression of λ_i is presented by equation (3.7.c) as follows:

$$\lambda_i = \frac{1}{\lambda + 0.002\beta} - \frac{0.003}{\beta^3 + 1} \qquad (3.7.c)$$

According to the BETZ theory, only 59% can be recovered from the wind power as mentioned in Figure 3.4.

The mechanical torque C_t obtained from the mechanical power can be formulated as follows (equation (3.7.d)):

$$C_t = \frac{P_t}{\Omega_t} \qquad (3.7.d)$$

Furthermore, a multiplier is required for the mechanical transmission between the turbine and the electrical generator. This multiplier transforms the slow speed generated by the rotor of the WT into high-speed power and low torque used by the electrical generator. This multiplier transmission can be molded by:
$$ \left\{ \begin{array}{l} J = J_{\text{turbine}} + J_g + J_{\text{tree}} \\ J \frac{d\Omega_g}{dt} = C_t - C_{em} - f \cdot \Omega_g \end{array} \right. \qquad (3.8) $$

where $C_{em}$ presents the electromagnetic torque produced by the generator, $\Omega_g$ is the speed of the generator, $\Omega_t$ is the speed of the turbine, $f$ is the coefficient of viscous friction of the generator, $J$ presents the total inertia of the wind energy conversion system, $J_{turbine}$ is the inertia of the turbine, $J_g$ is the inertia of the generator, and $J_{tree}$ presents the moment inertia of the tree.

On another hand, the productivity of the WT depends on the number of the blade that influences directly on the turbine speed. For a horizontal axis WT, the variability of $\lambda$ is presented, which corresponds to the ratio of the tangential speed at the blade divided by the wind speed. As shown in Figure 3.4, the three-blade rotor is the only WT, which is able to recover the extreme possible power. For the two-blade and one-blade rotor, they rotate faster and $\lambda$ move towards high values but with a low $C_p$.

<figure><img src="image_35.png" /><figcaption>Figure 3.4. The power coefficient $C_p$ average for different types of WT (Ebrahimpour et al., 2019)</figcaption></figure>

### 3.2.2. Permanent magnet synchronous generator

The MG system we have deployed in our study contains, as mentioned above, a horizontal axis WT with three-blade rotor, which can be characterized using the PMSG. For the small scale of power production, PMSG is the generator the most popular due to its simplicity of employment and control. The model of PMSG can be expressed by equation (3.9) (Singh et al., 2013; Rabeh et al., 2018).
$$
\left\{
\begin{aligned}
V_d &= -R_s i_d - L_d \frac{di_d}{dt} + p \omega_r L_q i_q \\
V_q &= -R_s i_q - L_q \frac{di_q}{dt} + p \omega_r (-L_d i_d + \psi_f), \\
\psi_d &= L_d i_d + \psi_f \\
\psi_q &= L_q i_q
\end{aligned}
\right.
\qquad (3.9)
$$

where $\psi_f$ represents the flux of the permanent magnet, $i_d$ (resp $i_q$) is the current in the axis $d$ (resp. $q$) of the stator, $V_d$ (resp. $V_q$) is the voltage of the axis $d$ (resp. $q$) of the stator, $L_d$ (resp. $L_q$) is the inductance of the axis $d$ (resp. $q$) of the stator.

We also adopt a smooth-pole PMSG in which $L_d = L_q = L_s$. Therefore, the electromagnetic torque is characterized by equation (3.10).

$$C_{em} = \frac{3}{2} p(\psi_d i_q - \psi_q i_d) = \frac{3}{2} p(\psi_d i_q + (L_d - L_q) \cdot i_d \cdot i_q = \frac{3}{2} p \psi_f i_q, \quad (3.10)$$

However, balancing the production and demand of energy in MG systems is based on the measurement of the wind power generation, which is not controllable and cannot be predicted perfectly. For that, this modeling of the WT is an essential step to simulate properly the whole hybrid system. Simulation and experimental results are compared in order to validate the usefulness of the model using the same weather conditions and the same WT parameters provided by the manufacturer.

## 3.3. Energy storage

Generally, energy storage is categorized as thermal, mechanical, magnetic, kinetic, electrical, chemical, and electrochemical technologies. For electrochemical technologies, according to the different requirements, various kinds of storage technologies are used (e.g., batteries, electrolyzer-fuel cells system) with specific characteristics, such as the maximum current, the minimum voltage, the rated voltage and current, the capacity of electrical energy and power, and also the weight and volume. For MG systems, different constraints (e.g., the volume, the safety, the cost) should be considered to select the more profitable storage technologies with easier usage of the deployment.

### 3.3.1. Batteries as electrochemical energy storage

The battery is one of the oldest forms of electrical energy storage. It is an electrochemical generator, which stores electricity in the form of chemical energy. Generally, the function of
electrochemical energy storage is to transform the energy released by electrochemical
reactions into electrical energy. This energy conversion process is ensured by one or more
electrochemical cells, which consist of a compilation of two electrodes with active materials:
a positive electrode (anode) and a negative electrode (cathode), liquid electrolyte, cell
connectors, separators, and usually containers. Through the electrochemical reactions at the
two electrodes, the electrochemical generators produce a flow of electrons during the
discharging phase using an external circuit (Figure 3.5). These reactions can be reversible,
allowing the generator to be charged by applying an external voltage through the two
electrodes. Depending on the reversibility of the process, electrochemical generators can be
classified into two categories: irreversible electrochemical reaction (Primary battery) in which
the generator is discharged only once and permanently, and the reversible electrochemical
reaction (Secondary batteries or accumulators) in which the generator can be recharged
applying an external source of energy to return the electrodes into their initial state.

<figure><img src="image_36.png" /><figcaption>Figure 3.5. The deployed battery modeling</figcaption></figure>

However, different rechargeable batteries technologies are deployed for RESs energy
storage in the MG system. They are commonly the most used and the most suitable for
electrical energy storage in the domestic sector and in small RES plants, due to the easer
installation and the less cycling when compared to other technologies. In fact, several types of
batteries energy storage are available on the market including Lead-Acid, Nickel-Cadmium,
Lithium-Ion, Nickel-Metal hydride, Sodium-Sulfur, and Zinc-Bromine. These batteries have a
large storage capacity for long discharge times (up to several hours) with a rate of 70 to 90%
(Bridier et al., 2016). On another hand, the major challenges of these technologies are the cost
and the lifetime cycle, limited by the chemical degradations of the reactions. For that, several
research works are focused on electrochemical batteries, in particular Lithium-Ion. The
electrolyte materials are the main key for researchers to develop other batteries that are less
expensive and have a high lifetime cycle. For example, researchers in the French Network on
Electrochemical Energy Storage have developed a Sodium-Ion battery with high
characteristics comparable to Li-ion (density of 90 Wh/kg and a lifetime of more than 2000
cycles). The advantage of sodium is that it is more abundant (2.6% compared to 0.06% for
lithium) and therefore less expensive to produce (National Center for Scientific Research,
2020). Other researchers aim to improve the C/D batteries process and new technology is
developed based Silicon-Oxide electrodes, which increase by 20% the performance of Li-Ion
batteries (Park et al., 2015).

Nowadays, Li-Ion batteries are widely the most expensive and they are used generally for
portable usage, which requires a low capacity. For that, other rechargeable batteries are used
for large scale energy storage systems. Mainly, Lead-Acid batteries are used for domestic
usage due to its low cost compared to other solutions. In fact, the Lead-Acid batteries are the
oldest and the most commonly used type of rechargeable battery. Although, they have the
lowest energy/volume ratio after the Nickel-Iron batteries and they have a low energy/weight
ratio. This technology has the ability to generate a high flow of current due to the construction
of cells that maintain a large power/weight ration. Basically, the Lead-Acid is consisted by
connecting a series of cells, which contain a positive electrode (lead oxide) and a negative
electrode (lead), immersed in an electrolyte solution (sulfuric acid) and separated by a cell
divider. Besides, Lead-Acid battery has a low expected lifetime (5-15 years), a low C/D cycle
and a negative influence on the environment by generating toxic remnants (Chen et al., 2009).
For these reasons, the management of the C/D cycle of the battery is a worrying subject
because it is important to control its usage in order to maximize its lifetime.

Due to the abovementioned reasons, this energy storage system is considered in our study
and a description of their modeling is described in the following section. Furthermore, Lead-
Acid battery is used actually, for a large scale of RES applications, especially the gel battery,
because of their low cost and because the industry today is very established to recycle the
Lead.

**3.3.2. Battery modeling**

Lead-Acid batteries are used to store exceed of energy generated by the RESs during the
low peak demand periods. In order to use more efficiently this type of battery, the
characterization and the determination of the SoC is a very important task before their
integration within MG systems. Typically, the battery modeling and characterization is a required step to identify battery's parameters and study their behavior and performance for seamless integration in MG systems. It is important that the model must characterize more precisely its response to various operating conditions. In our deployed MG system, the SoC of the batteries is used as an input parameter to the deployed control strategies. However, the dynamic behavior of battery modeling is a complex process due to the different phenomenon that can influence its electrical and electrochemical characteristics. For example, the SoC of the Lead-Acid battery could be determined by measuring the concentration of the electrolyte through the specific gravity method, which is almost impossible experimentally. Typically, several battery models are studied in order to develop a specific model, which can be used to follow the evolution of the battery parameters during its operation (Tremblay et al., 2009; Boulmrharj et al., 2018). There are mainly three types of models used to represent the temporal behavior of the battery: electrochemical models, equivalent electrical circuit models, and black-box models. In this section, a battery dynamic model is presented, which is easy to use and to extract the dynamic model parameters from the battery datasheet. The model takes into account the OCV as a function of SoC, which is the more interesting parameters for the control. Generally, the Lead-Acid battery voltage is presented as a function of the capacity by the curve presented in Figure 3.6, which is obtained using the Matlab-Simulink model for a given Lead-Acid battery (12V, 100Ah).

<figure><img src="image_37.png" /><figcaption>Figure 3.6. Lead-Acid battery discharge characteristic</figcaption></figure>

As is shown in Figure 3.6, the nominal zone of a Lead-Acid battery presents a high part of the curve. For that, to increase the lifetime of the battery, it is obligatory to consider the parameters mentioned by the battery datasheet (e.g., fully charged voltage, minimum SoC). Moreover, a procedure for characterizing the parameters of a battery model comprises two stages: carrying out tests on the battery and identifying the value of each parameter from experimental data. For the proposed model, the term concerning the polarization resistance is
integrated and the polarization voltage term is added to represent the OCV behavior more precisely (i.e., the non-linearity relationship between the OCV and the SoC) as already validated in (Boulmrharj et al., 2018). The battery voltage variability is expressed by equation (3.11) and equation (3.12) respectively in both discharge and charge processes.

$$V_{batt} = E_0 - Ri - K \cdot \frac{Q}{Q-it} (it + i^*) + \exp(t), \quad (3.11)$$

$$V_{batt} = E_0 - Ri - K \cdot \frac{Q}{it - 0.1 \cdot Q} \cdot i^* - K \cdot \frac{Q}{Q-it} \cdot it + \exp(t) \quad (3.12)$$

where $V_{batt}$ is the battery voltage, $E_0$ is the battery constant voltage, $R$ is the internal battery resistance, $i$ is the battery current, it is the actual battery charge, $i^*$ is the filtered current, $K$ is the polarization constant, $Q$ is the battery capacity, and $\exp(t)$ is an expression that represents the exponential zone voltage.

A controlled voltage source is used to model the OCV of the battery and it is connected in series with a constant resistance as mentioned in Figure 3.5. In fact, the accuracy of this battery model is the use of a filtered current $i^*$ flowing through the polarization resistance presented by equation (3.12.a).

$$P_{Resistance} = K \cdot \frac{Q}{Q-it} \quad (3.12.a)$$

In addition, during the exponential zone, the OCV varies non-linearly with the SoC and this hysteresis phenomenon between the charge and the discharge can be represented by the non-linear dynamic system expressed by equation (3.13), where $B$ is the exponential zonetime constant inverse and $A$ is the exponential zone amplitude. The exponential voltage ($\exp(t)$) depends on the initial value ($\exp(t_0)$) and the C/D mode ($u(t) = 1$ for charge mode, and $u(t) = 0$ for discharge mode) that depends on the battery current mode (discharge ($i>0$) and charge ($i<0$)). The C/D processes is implemented using the model depicted in Figure 3.5.

$$\exp(t) = B|i(t)| \cdot (-\exp(t) + Au(t)) \quad (3.13)$$

It is worth noting that our aim is to integrate this battery model in our simulated MG system using the same real battery parameters. This allowed comparing both simulations and
experimentations results. This model is also used to estimate the essential parameter for our study (SoC), which is required to develop context-driven approaches for EM management and control for multi-energy source installations.

### 3.3.3. Wide range of energy storage systems

Depending on the type and the scale of the deployed MG system, various solutions of energy storage can be deployed. Mainly, pumped hydro-electricity storage was generally implemented for large-scale and long-term energy storage. The system consisted generally of two interconnected reservoirs located at different elevations, a turbine to generate electricity when the water returning to the low elevation, and a device that is used to pump water to the high elevation. In fact, during off-peak demand periods, large quantities of water are pumped into the high elevation storage using the surplus of electricity, which is converted to hydraulic potential energy. Afterward, during peak demand, a turbine is used to generate electricity by converting the potential energy to electricity. This system needs usually a large landmass to store the water. For large-scale production, this technique can use rivers, ocean, or also massive lakes as the lower reservoir. It can be used for long-term energy storage in large plants of RESs.

Electrical energy storage is another family, which includes different technologies like capacitors and super-capacitors. Mainly, without chemical reaction, this technology stores directly electrical energy into electric current using an inductor (coil) made from a superconducting material. The super-capacitors offer very high capacitance in a small array, which can be released very quickly. They are suitable for short term and high-power demand applications. In particular, this technology has a high cycle life and it is more suitable for applications requiring a constant and continuous mode of operation. It is used to solve voltage and frequency stability and power quality problems for the electrical network and for the large industrial customers.

Chemical energy storage is a more used technology, which is realized through accumulators by alternating the C/D phases and by a double function of gaze storage and electricity generation. The accumulators are fabricated from several methods (e.g., nickel-cadmium, lead-acid, nickel-iron, sodium-sulfur, lithium-ion, and lithium-polymer). These systems are used generally for short-term energy storage and the minimum discharge period of the electrochemical accumulators rarely reaches below a few minutes. They are more useful for portable systems, and they are used to ensure the power security for permanent
applications (e.g., renewable energy in isolated areas, emergency network backup) (Ibrahim et al., 2008).

It is worth noting that one of the main emerging technologies for chemical energy storage in MG systems is the fuel-cells hydrogen storage, which is realized by a fuel-cell system. It is a means of restoring electrical energy to produce hydrogen through the water electrolyzer. The system uses separate processes for hydrogen production, storage, and use and it includes three main components: i) the electrolyzer, used to produce hydrogen and oxygen from water by consuming an electric current during the off-peak demand, ii) the fuel-cells, which uses the stored hydrogen and oxygen from the air to release energy peak demand periods, iii) the hydrogen tank, which is used to store the hydrogen generated by the electrolyzer.

Hydrogen fuel-cell storage systems are receiving increasing attention for the actual researches, especially for their integration with RES. In particular, the stochastic nature and the variable production of RES produce fast power fluctuations that can cause incomplete separation of the gases from the electrolyte, and consequently, the H₂ and O₂ are mixed in the electrolyte. Therefore, the integration of the fuel-cells system into MGs should be coupled to other storage devices systems like batteries in order to maximize the efficiency and to avoid the damage of this expensive solution of storage. It is worth noting that this type of energy storage is not considered in this work, it was investigated in other works under the project MIGRID. We focus mainly on batteries, their modeling, and integration within our MG system.

# 4. Experimental platform of MG systems: EEBLab

Approaches developed in the frame of this dissertation are deployed and tested in real-sitting scenarios in our MG systems.

## 4.1. Data sensing and communication

The building's transition to smart the MG system requires the distribution of the communication as well as a distribution management system. For instance, the IEEE Standards Association approved the OpenFog Reference Architecture, developed by the OpenFog Consortium, including Intel, Cisco Systems, Microsoft, Dell, ARM Holdings, and Princeton University, as an official standard, under the name of IEEE 1934 (Chiang et al., 2016), for IoT communication in MG systems. The standard classifies the interaction of interconnected units for streaming and real applications into three classes: i) Machine-to-
Machine, in which any component can send/receive data or command to/from any other one using the capabilities of IoT, ii) People-to-Machine, the users can control each machine, which can be adapted depending on the occupants' comfort, and iii) People-to-People, in which users can exchange data through a cooperation mechanism. In the MG system, communication among all devices is required aiming to improve the effectiveness and reliability of the system's operations. In our studies, sensors are used to collect contextual data, which are submitted to our remote platform for storage or further analytics. Mainly, current and voltage sensors are installed to gather data from RESs, storage devices, and load consumption. Actuators are deployed for operating actions that are generated by the energy flow controller. It is worth noting that sensors are devices or integrated circuits used to detect specific physical parameters by converting sensed values to electrical signals, which are readable by microcontrollers. Mainly, three types of sensors outputs can be specified, current loop output, voltage output, and digital output. The sensors based on current loop output are calibrated over a specified range against various engineering units to convert the real value, such as the temperature, pressure, and current, to an equivalent current value measured by the deployed microcontroller. The output of the individual calibration certificate is compared to a mathematical manipulation made to obtain the absolute value. The loop's operation is straightforward in which the sensor's output signal is first converted to a proportional current, with the less current (generally on mA) presents the sensor's zero-level output and the high current represents the sensor's full-scale output. For example, the 4-20mA current loop is a very robust sensor-signaling standard, while, the current loops are ideal for data transmission because of their characteristic insensitivity to electrical noise. Therefore, the voltage output sensors can have various voltage outputs (5V, 10V, from -5V to +5V and more) that are calibrated over this range against various units. The output is compared to the individual calibration certificate for the specified measurement range for which the sensor is selected. Generally, there are two types of voltage output signals, differential and single-ended measurements. The differential voltage signal is "floating", meaning that has no reference to the ground. The measurement is taken as the voltage difference between the two wires. The benefit of this method is noise elimination because the noise is added to both wires and can then be filtered out by the common-mode rejection of the data acquisition system. For single-ended measurement, it considers as the voltage difference between a wire and the ground. The noise is only on the positive wire and as a result, it is still measured along the output voltage of the sensor. Mainly, transmitting the sensor's output as a voltage over a long distance has several drawbacks. The transmission for long distances produces corresponding lower
voltages at the end receiver due to the wiring and the interconnecting resistance. Also, the voltage devices are sensitive to the noise pickup for which the shielded wires are used to minimize this noise.

However, many sensors use a digital signal rather than analog signals of voltage and current. Face to the noises and the measurement perturbs, it is more robust. The two most common digital communications are RS-232 and RS-485. The RS-485 is more used because it only specifies the electrical characteristics of the generator and the receiver. It does not specify or recommend any communications protocol, only the physical layer. Modbus, Profibus, Canbus, and SDI 12 are all examples of communication protocols employing the RS-485 style signal. Therefore, the major advantage of the RS-485 system is that sensors can be transported; meaning that each sensor has its own individual address and many can be all attached to one cable. This means that multiple sensors only use up one port on the data logger saving considerably on cable and data logging costs. Long distances are achievable but the distance is a function of the cable and supply voltage. The longer the cable the greater the signal attenuation will be and so the length is not infinite. Signal attenuation also increases with the frequency of data transfer and the achievable distance diminishes with the data rate.

Therefore, the deployed MG is equipped with a component for measuring power consumption and production. In fact, a set of current and voltage sensors have been installed for power measurement as shown in Figure 3.7. The system contains a switch controlled by an Arduino, which allows collecting the data from different sensors. Furthermore, the system contains a micro-computer (Raspberry pi) for collecting data from different sensors. In fact, sensors transmit analog signals to the microcontroller, which converts them into numerical data. For example, a voltage sensor is used to measure the output PV voltage with an accurate range that considers the maximum voltage of the PV installation. For that, a tension divider bridge is used to convert the values from zero to 5V, which is the Arduino accurate range. In fact, the Arduino program converts obtained values to tension data. Moreover, the Arduino transmits these data to the Raspberry for activating the right action according to the deployed control algorithm. Data are then transmitted to the IoT/Big-data platform for visualization and storage. As shown in Figure 3.7, these data could be used for further analysis (e.g. power forecasting).
<figure><img src="image_38.png" /><figcaption>Figure 3.7. Monitoring platform architecture</figcaption></figure>

Next section introduces our MG system’s architecture. In particular, we highlighted the necessity of integrating recent IoT/Big-Data technologies for gathering external and internal data, which have been used to generate predictive actions (e.g., regulating the room temperature by forecasting building’s occupancy, ventilation speed variation according to the forecasted CO2, intelligent and predictive control of energy flows management using forecasted power production, consumption, and battery SoC).

## 4.2. IoT/Big-data platform for data collection

The aim was to develop a research testsite integrating the different components of an MG system, which is used to test and integrate control strategies for predicting, estimating, and controlling the interaction between power production, storage, and building’s demands. As shown in Figure 3.7, the system integrates PV panels, WT, batteries, and the TEG connected together in order to supply electricity to the building’s services according to actual contexts. The system is monitored by an IoT/Big-Data platform, which is used to collect, analyze, and store the data for EM and control strategies development. Moreover, several scenarios are deployed in order to develop a research platform that considers the concept of MG systems with the different components of the different layers.

Real-time and context awareness information could be exploited for developing predictive and adaptive context-driven control approaches using recent IoT and Big-data technologies together with real-time and ML algorithms (Elkhoukhi et al., 2019; Hadri et al.,
2019). A platform that uses context-driven technologies, as well as complex-event processing technologies, is deployed for data monitoring and processing in order to develop intelligent and predictive control strategies for EM in MG systems. The platform is composed of four main layers, sensors/actuators layer, data acquisition, data processing, and data visualization/storage together with further services and applications for context-driven control (Figure 3.8).

<figure><img src="image_39.png" /><figcaption>Figure 3.8. IoT/Big-Data platform architecture</figcaption></figure>

The MG is mainly equipped with a component for measuring the different necessary parameters (e.g., current, voltage, temperature, wind speed), for interacting with the passive and the active equipment, for regulating the comfort for the occupancy, and for managing the power production and consumption. In fact, a set of sensors is installed depending on the desired scenarios. In addition, the first layer includes the actuators that are used to receive and to execute different commands, which are generated by the control strategies for EM or for equipment and services control. Regarding the data acquisition layer, a Kaa application is developed (i.e., IoT technique) (Kaa, IoT technique, 2020) which is used to receive data from deployed sensors. We have also used MQTT, which is a publish-subscribe-based protocol for IoT applications. For data processing and storage, Storm services are used (Storm, Apache Storm, 2020). Mainly a topology composed of Spouts and Bolts was designed and developed to allow receiving and processing streaming data from sensors. The spouts receive the data from the Kaa application, and then transmit it to the Bolts for processing and storage into the database (e.g., MongoDB) for further in-depth analysis. The services layer includes real-time visualization and storage together with the control of active equipment and RESs power production and consumption monitoring and management. The platform was used for data gathering and processing of internal and external building's context. For instance, it was used to build occupant information (e.g., number, presence, behavior, activities), since it is a major
input for control approaches in energy-efficient buildings (e.g., active systems control) (Elkhoukhi et al., 2018b). In fact, comprehensive fine-grained occupancy information could be integrated to improve the performance of occupancy-driven control of HVAC, lighting, and ventilation systems. A platform for real-time detection of occupants' is deployed. The platform was adopted by including real-time ML component with the main aim is to analyze, explore, and predict the occupancy information in buildings. However, these predicted values are then used for efficient control of active equipment and for predicting the electricity consumption behavior, which is used for EM.

### 4.3. Weather station

Regarding the external context, we have deployed a weather station. In fact, for several scenarios, we need to gather internal and external context data. We have built a weather station near the WT and PVs in order to have as precisely as possible the data concerning wind speed, direction, irradiation, temperature, and humidity. The weather station was deployed and used to collect the data for real-time visualization and processing for further usage by other building's services and applications. All these data are gathered and processed in real-time using our IoT and Big-data platform, as depicted in Figure 3.9.

<figure><img src="image_40.png" /><figcaption>Figure 3.9. a) Internal/external temperature b) weather monitoring</figcaption></figure>

Weather data are collected in order to validate the results obtained from simulations and experimentations by using the same input parameters. For example, radiance and temperature are measured together with the PV power during the same day. Radiance and temperature are used as input parameters to the mathematical PV model, which is developed for conducting simulations and validate experimentations' results using similar contextual data.
## 4.4. Building envelope

This part concerns the passive layer, which allows reducing energy consumption by developing less-energy-consuming equipment and materials in buildings. Emerging devices, which use natural forces without using electricity, such as natural lighting, room relocation, natural ventilation, could be used to increase insulation. In fact, the architecture design, buildings envelope, and orientations can influence energy reduction. Therefore, the passive design must be considered in the phase of construction in order to reduce the final energy use of the building.

As part of our studies, a work is realized by focusing on the thermo-mechanical characterization of our EEBLab, which mainly consists of galvanized steel, of which expanded polyurethane is injected into the walls and the roof. As well as two types of internal insulation are adapted, namely chipboard for the floor and polyurethane for the roof. The main aim is to thermally study the behavior of the EEBLab, in order to propose good material for the insulation and consequently minimizing the use of the HVAC system for heating and cooling.

## 4.5. Active/Passive equipment control

This part concerns the MG system active layer that allows the deployment of context-driven control approaches in order to improve energy consumption. In this layer, the electrical energy can be minimized by optimizing the operation times of the active equipment (e.g., HVAC, ventilation systems) while maintaining occupants' comfort within good air quality and suitable thermal comfort (Berouine et al., 2019a). In fact, the ventilation systems are normally installed in buildings to improve the air quality by injecting fresher air from outside into inside buildings. These systems automatically act on behalf of occupants by ensuring good indoor air quality, especially in cold or hot periods, or when there are no windows. In fact, the ventilation controller performs this task by adjusting fresh air as much as needed based on actual indoor CO₂ concentration. The aim is to improve the optimal balance between energy efficiency and indoor air quality. For that, a ventilation control system was deployed, which maintains the indoor CO₂ concentration at the comfort set-point with an efficient and minimal ventilation rate and energy consumption (Lachhab et al., 2018a).

Another study puts more emphasis on developing efficient control approaches in order to deliver acceptable occupants' comfort while maintaining optimal energy consumption.
Control approaches are investigated for controlling the deployed HVAC system in our EEBLab (Lachhab et al., 2017b). A control card is deployed in order to interface between all HVAC components and the control device. It allows the regulation of temperature and ON/OFF control of the HVAC system by adjusting the inside ventilator and the compressor based on the desired schedules (heating, conditioning, or only ventilation). The deployed IoT/Big-Data platform is used to measure the hourly electricity consumption of the HVAC system, which is used in our study as a load to test the EM control strategies.

Generally, the HVAC is the most used system for thermal comfort regulation in buildings and is considered as the highest electricity consumer. For that, renewable sources of thermal energy are required to minimize the electricity mainly used for heating, cooling, and air conditioning. In this perspective, we have deployed a geothermal platform (Kharbouch et al., 2018), an earth-to-air heat exchanger system that could be used for building cooling and heating. In fact, this clean and sustainable source can be deployed and used to minimize the usage of HVAC systems. The system is installed to extract heat from the ground for either cooling or heating purposes. It is basically a buried pipe, deployed at a certain depth in the ground, where air exchanges heat with soil. This system is deployed in the side area of our EEBLab and the pipelines are installed inside a trench of 5m in length, 2m width, and 1.5 depth. Different sensors are installed as well in order to measure and control the temperature exchange in order to investigate the performance and the effectiveness of the system in terms of power consumption and comfort.

It is worth noting that, under MIGRID project, the platform was used in different scenarios, especially those related to building envelope and active/passive systems layers. For instance, in the second layer, the electrical energy can be minimized by optimizing the operation times of the active equipment (e.g., HVAC, ventilation systems), while maintaining occupants' comfort within a good air quality and suitable thermal comfort.

## 4.6. RESs integration

Despite the importance of the modeling and simulations, the deployment of real a MG system for conducting experiments is required in order to study and assess the accuracy of these models. The system contains mainly energy sources (PV and WT), storage devices (batteries) and loads, which are coupled together in our deployed MG system using our developed control card (Figure 3.10).
<figure><img src="image_41.png" /><figcaption>Figure 3.10. The hybrid system of RESs installed in our EEBLab</figcaption></figure>

However, for the RESs installation, the installed PV panels are over-dimensioned in order to consider in the future works the possibility to interconnect multiple MG systems for the energy exchange. The main components are presented in Table 3.1. However, the system is performed by adding more sources and technologies in order to create multiple interconnected MG systems. In addition, the possibility to inject the electricity, into the utility grid, is envisaged by integrating the electrical vehicle as an energy storage system solution. The deployed MG system is depicted in Figure 3.11. The details of RESs integration with EM control approaches are presented in the next chapters.

<table><caption>Table 3.1. The main electrical components of EEBLab</caption><thead><tr><th>Components</th><th>Number</th><th>Characteristics</th></tr></thead><tbody><tr><td>DC bus</td><td>--</td><td>24V</td></tr><tr><td>PV panels</td><td>8</td><td>Polycrystalline, 270Wp,</td></tr><tr><td>Wind turbine</td><td>1</td><td>PMSG, 420W, nominal wind speed: 14.5 m/s, starting speed: 2.0 m/s</td></tr><tr><td>Battery</td><td>4</td><td>Gel, 110Ah/12V, recommended maximum depth discharge: 40%</td></tr><tr><td>Power inverter</td><td>1</td><td>Operating battery voltage: 19-33V; Nominal power: 2200W; Peak power: 3000W, efficiency: 94%.</td></tr><tr><td>Charge controller</td><td>1</td><td>Nominal battery voltage: 12V, 24V, 48V; nominal charge current: 85A; Maximal PV power: 2400W for 24V; efficiency: 96.5%.</td></tr><tr><td>Loads</td><td>--</td><td>Two computers (240W), HVAC system (2000W), 3 lamps (180W), two fans (60W).<br>The system has the possibility to supply the electricity to another test site that contains cooking plate (1500W), 4 lamps (200W), freezer (80W).</td></tr><tr><td>Grid-connected<br>Electrical vehicle</td><td>Yes</td><td>Only extraction<br>Twizy 45; 5 horse; battery type: Lithium ion; battery capacity: 6.1 KWh</td></tr></tbody></table>
<figure><img src="image_42.png" /><figcaption>Figure 3.11. EEBLAB: the deployed energy efficient building laboratory</figcaption></figure>

**5. Conclusions**

The main aim of the work presented in this chapter is to shed more light on the usefulness of developing an integrated platform in order to enable the deployment of smart MG systems in energy-efficient buildings. The MG platform connects the building's components using sensing/actuating, IoT, and Big Data technologies in order to leverage real-time gathering, data processing, and predictive control. RESs and battery storage devices are modeled in order to have both real and virtual MG platforms offering the possibility to validate the studied scenarios by simulations and experimentations. It was used for validating the proposed models and results mainly by investigating, i) the efficient connection, integration, and the management of different RES and storage devices, ii) the suitable dimensions for energy production and storage devices, iii) different possible D/R and predictive algorithms, iv) context-aware driven control of deployed equipment, e.g., lighting and HVAC systems. Methods that allow smart management with predictive analytics are investigated to be integrated into the platform prototype to handle this type of complex systems.
# Chapter 4: The Deployed Micro-grid System Integrating Renewable Energy Sources: Experimental Evaluation and Validation

## 1. Introduction

In the frame of this thesis, we aimed to develop a research MG system, which is used to test and integrate control strategies for predicting, estimating, and controlling the interaction between power production, storage, and building's demands. The system is monitored by an IoT/Big-Data platform for collecting and data processing. Two MG systems have been deployed during the period of this dissertation. The first one is named EEBLab (International University of Rabat, Sala-Eljadida, Morocco), in which the testing scenarios are realized for the components validation and the control scenarios testing. The second MG system is a smart Green-Building, which is deployed during an international competition named “Solar Decathlon Africa” (Green Energy Park, Benguerir, Morocco). The two platforms are actually used as a research platform.

In this chapter, the simulation and the experimental validation of the different components for the MG system are realized and basic control strategies are deployed to show the usefulness of the deployed system to monitor the MG platform. In fact, the deployed IoT/Big-Data platform is used to collect the data that is used to control our deployed control card for EM. Case studies are presented concerning the deployment of an EM control strategy for energy balance in an MG system of RESs, storage devices, and the utility grid. The hybrid MG platform was deployed, several scenarios have been tested and evaluated, and preliminary results showed the usefulness of the platform for efficient management of buildings components. The platform is further enhanced by developing other ongoing scenarios, especially, for predictive control strategies.

## 2. RESs deployment and validation

### 2.1. PV panels

A model of PV panel is deployed in Matlab-Simulink using the same parameters that are noted by the manufacturer for the real PV panels. The PV panel's behavior was verified using both simulations and experimentation and by using real radiation and temperature data. The PV characteristics used in both simulations and experiments are described in Table 4.1.
<table><caption>Table 4.1. PV Characteristics</caption><caption>Standard test condition at:<br>Solar irradiance 1000 W/m²; Cell temperature 25°C, Air mass 1.5</caption><thead><tr><th>Characteristics</th><th>Value</th></tr></thead><tbody><tr><td>Cell type</td><td>Polycrystalline 156*156 mm</td></tr><tr><td>Nominal power</td><td>270 W</td></tr><tr><td>Number of cells</td><td>60 (6*10)</td></tr><tr><td>Open circuit voltage (V<sub>oc</sub>)</td><td>38.4 V</td></tr><tr><td>Short-circuit current (I<sub>sc</sub>)</td><td>9.06 A</td></tr><tr><td>MPP voltage (V<sub>MPP</sub>)</td><td>31.1 V</td></tr><tr><td>MPP Current (I<sub>MPP</sub>)</td><td>8.69 A</td></tr><tr><td>Module efficiency</td><td>16.29 %</td></tr><tr><td>Operating temperature</td><td>-40°C to +85°C</td></tr><tr><td>Maximum system voltage</td><td>1000V DC</td></tr><tr><td>Maximum series fuse rating</td><td>15 A</td></tr></tbody></table>

The deployed weather station (presented in chapter four) collected the input parameters for the same day of the experimentation. Therefore, one panel is used to validate the model, while, our proper card is deployed to measure the generated current and voltage from the PV. The system contains mainly energy sources (PV), storage devices (batteries), and a load (ventilation system). The PV is used to charge the battery, which in turn supplies the ventilation system. The deployed ventilation system is installed in order to ensure that the PV panel could generate its maximum power at each moment. Mainly, the testing scenario is equipped with a DC/DC converter, which implements an MPPT. The main function of the MPP-tracker is to adjust the panel output voltage/current into a value that matches the maximum energy needed by a given load. In our study, we consider that the deployed DC/DC converter ensures the good MPPT algorithms operation that is deployed by the manufacturer. We need also weather conditions (irradiance, temperature, solar panel tilt, and orientation) as input variables. Experiments have been conducted during different scenarios. The tilt of the panel was set to 30° with a southerly orientation (El Mouatamid et al., 2017).

Figures 4.1.a and 4.1.b show respectively the temperature and the irradiation profile, of May 10th, 2020 (06:00 PM to 06:00 AM), collected in our test site (Morocco, Sala-aljadida, International University of Rabat). This data is used as input parameters to the developed simulation model.
<figure><img src="image_43.png" /><figcaption>Figure 4.1. Real data during 12 hours, (a) Temperature, (b) Irradiance</figcaption></figure>

<figure><img src="image_44.png" /><figcaption>Figure 4.2. Simulation and experiment data, a) PV current, b) PV voltage, c) PV power</figcaption></figure>
Figure 4.2.c shows the PV production for 12 hours. These data are presented here to first verify the PV model used for conducting experiments, and then to study the usefulness of the IoT/Big-Data platform for real-time data monitoring and processing. Obtained results, as shown in Figure 4.2, confirm the efficiency of the PV model in capturing the contextual environment in which the PV is deployed and tested as well. We have evaluated the current, the voltage, and the power generated using simulations and experiments in order to show the accuracy of the proposed model. The current obtained by simulations (blue curve) is compared with the measured one (red curve) as shown in Figure 4.2.a. Figure 4.2.b shows the comparison between the voltage values obtained by simulation (blue curve) and these obtained by experimentation (red curve). These results validate the studied module of the PV. Therefore, the deployed measurement system is used to measure the total PV power production for the solar park that is installed in our MG system. The power generated from the PV panels is an interesting input parameter for the control strategies, which are developed in our study. While, in the deployed MG system, eight panels are installed in order to supply the power to different equipment in the laboratory.

## 2.2. Wind turbine

The MG system includes also a horizontal axis WT with three-blade rotor. The installed WT generates an AC power, while, the deployed control card and the bus topology that is deployed in the MG system operate on DC bus topology. For that, a rectifier is installed in order to convert the generated power to DC power, which is coupled in a hybrid system with the PV panels, while, the same battery storage system is used for both PVs and WT. Therefore, a measurement card is installed in order to collect wind power generation. The installed weather station collected the wind speed, which is used to simulate the deployed model for the WT in order to compare and validate both simulation and experimental results. Table 4.2 describes all the parameters used for the deployed WT.

<table><caption>Table 4.2. Parameters of the wind-turbine conversion system</caption><thead><tr><td>Parameters</td><td>Values</td></tr></thead><tbody><tr><td>Ls</td><td>1.25mH</td></tr><tr><td>Rs</td><td>0.9 Ω</td></tr><tr><td>p (pair of pole)</td><td>19</td></tr><tr><td>ψ<sub>f</sub> Flux of the permanent magnetic</td><td>0,09 Wb</td></tr><tr><td>Maximum power</td><td>420 W</td></tr><tr><td>R Radius of the blades</td><td>0,575 m</td></tr><tr><td>J(inertia)</td><td>5 Kg.m.s<sup>-2</sup></td></tr><tr><td>f Coefficient of viscous friction of the generator</td><td>0,06 Kgm<sup>2</sup> s<sup>-2</sup></td></tr><tr><td>Power rate</td><td>420W</td></tr></tbody></table>
In this section, simulation and experimental results are compared to show the accuracy of
the proposed model, especially with a variable wind profile collected according to the local
weather station, which is installed in our MG system (Morocco, Sala-aljadida, International
University of Rabat) as shown in Figure 4.3.a.

<figure><img src="image_45.png" /><figcaption>Figure 4.3. WT generation scenario, a) Wind speed profile, b) Simulation and experiment power generation</figcaption></figure>
The measurement card is installed to collect the data from the WT and the weather station
collected the equivalent wind speed and direction that are used in the simulation to generate
the equivalent behavior of power generation using the deployed mathematical model (Figure
4.3.b). However, the system is installed in a site where the wind speed has only a limited
number of days when it exceeds the rated speed of the WT to levels, which allow giving an
important production, due to different existing obstacles. For that, the power generated by the
WT is less than the power generated by the solar park installed in the MG. Hence, it is
coupled with PV panels in order to study a global control strategy for a hybrid system of
RESs. Moreover, unlike the PV panels' generation, the WT has variable production in the
order of a few seconds due to the highly variable nature of wind speed as mentioned in Figure
4.4. For that, the wind power is converted to DC power in order to be coupled with the
batteries to smooth its behaviors, while, to have reliable control scenarios in the DC bus.

<figure><img src="image_46.png" /><figcaption>Figure 4.4. a) Wind speed variation during one hour, b) The equivalent wind power generation</figcaption></figure>

**2.3. Battery storage device**

The use of storage devices in the MG system is motivated by the intermittent nature of
RESs and the need to regulate the power quality (e.g., frequency, voltage) generated by these
generators. The main aim is to store the surplus of the produced power during the peak
production for possible usage when there is no production and keeping, at the same time, a
maximum state of health for the storage devices. Therefore, a set of batteries are installed in
our deployed MG system due to their benefits (e.g., fast response, modularity, and good energy efficiency). For that, a platform to study, model, and experiment the batteries is required. This platform offers the possibility to monitor the used battery for better SoC estimation. These parameters are required to develop and deploy control strategies for EM in MG systems. In fact, a battery model is designed to estimate and predict the batteries' performance and behavior because the SoC is used as a critical parameter for our control strategy.

Electrical-circuit models (e.g., the first-order RC model, the second-order RC model) are commonly used for batteries' behavior estimation. These models are composed of a voltage source, resistors, and capacitors, which can simulate its dynamic behavior. They become more and more accurate when the model's order increases (i.e., RC networks). Therefore, in order to determine the battery characteristics, an instrumentation platform is first developed using recent sensing/actuating equipment for gathering important battery's parameters, which are then used for building a model for the battery deployed in our EEBLab (Figure 4.5).

<figure><img src="image_47.png" /><figcaption>**Figure 4.5.** Battery characterization system (Naitmalek et al., 2019)</figcaption></figure>

It is composed of a Lead-acid battery and a set of sensors to extract the battery's voltage and current. The sensors are connected to an acquisition board (e.g., Arduino) used to collect the data, and then send them to a cluster for processing and storage. The developed platform provides other information about the estimation of the battery's SoC by the Coulomb Counting method. After validating the battery model, it is integrated into our MG for simulations and experiments. In fact, the deployed model is based on the voltage and current measurement, while, the SoC is estimated using the behavior of the battery voltage variation.
Therefore, the obtained result is compared to the experimental SoC variation. These results show that the SoC and voltage curves have the same behavior due to the mapping function we have used for SoC estimation using the battery's voltage. Experimentally, a mapping function of the battery's voltage is used for SoC estimation. This mapping function attaches each voltage value to an equivalent SoC. The battery's voltage range is defined as follows, the battery is charged during a time period until the voltage is stabilized and the obtained voltage value is attached to 100% of SoC. As shown in Table 4.3, this voltage value is about 14.4V. Therefore, Figure 4.6 presented the voltage variation, which is presented by the manufacturer of the battery for the first use in the specified condition.

<table><caption>Table 4.3. Parameters of the deployed battery</caption><tr><td>Output voltage</td><td>12 V</td></tr><tr><td>Rated Capacity</td><td>110 Ah</td></tr><tr><td>Float charge voltage</td><td>13.5-13.8 @ 25°C</td></tr><tr><td>Cyclic charge voltage</td><td>14.1-14.4 @ 25°C</td></tr><tr><td>Recommended maximum depth discharge</td><td>50%</td></tr><tr><td>Cycle life</td><td>1800 (depth discharge 30 %)<br>750 (depth discharge 30 %)<br>500 (depth discharge 30 %)</td></tr></table>

<figure><img src="image_48.png" /><figcaption>Figure 4.6. Battery voltage characterization for four charging steps</figcaption></figure>

However, the battery used in this experimentation is degraded, this why the voltage stabilizes around 14.25V, which is considered 100% in this case. Moreover, the battery is discharged continuously when supplying the ventilation system. When the current reaches zero, the battery voltage was stabilized on 7.5V, and then this value is attached to 0% of SoC. The obtained voltage range is used to estimate the SoC based on this mapping function, which is implemented and deployed on the Arduino. Figure 4.7 shows the SoC variation using both simulations and experimentations and results confirm their accordance over time with slight differences.
<figure><img src="image_49.png" /><figcaption>a)</figcaption></figure>

<figure><img src="image_50.png" /><figcaption>b)</figcaption></figure>

<figure><img src="image_51.png" /><figcaption>c)</figcaption></figure>

**Figure 4.7.** a) SoC estimation from voltage variation, b) The deployed battery modeling validation, c) The battery SoC estimation using the measured voltage by our deployed platform
The error depends on the stability of the data variability because the SoC measurement based on the voltage variability is not always a suitable method for SoC estimation. The battery voltage varies depending on the connected loads to the batteries. The main aim is to use the SoC as input control parameters but is studied carefully by another dissertation in the same project (Boulmrharj et al., 2018).

As shown in Figure 4.7.c, the blue curve presents the battery SoC variability estimated using the measured battery voltage (orange curve). During this scenario, the battery C/D current and voltage are measured and collected using our deployed IoT/Big-Data platform. The measured parameters are used to estimate the SoC variability. Therefore, the SoC is a key parameter for the EM strategies in the MG systems. In fact, as depicted in Figure 4.7, from 11:00 AM to around 07:00 PM, the battery is charged by the surplus generated from the RESs. During the night, from 07:00 PM to around 04:00 AM, the battery generates the power to the load because the PV generation is unavailable. However, the battery is at rest from 04:00 AM to around 08:00 AM because the SoC reaches the regulated threshold value, which is fixed by the EM strategy, in order to avoid a deep-discharge of the battery.

For the different scenarios, the proposed IoT/Big-Data platform could be used to measure different parameters in the MG system. Depending on the studied scenario, suitable sensors are selected and can be connected to this platform for data collection, monitoring, and processing. Mainly, the measured parameter is used to control efficiently the deployed MG system. In the next section, naïve control strategies are presented to show the usefulness of the deployed system in managing the energy flow, while, proposing a good infrastructure to deploy other intelligent and predictive control strategies. These predictive control strategies are presented in the next chapter. The rest of this section is dedicated to the scenarios related to RES and storage devices integration and control.

# 3. Real-time control scenarios for EM in MG system

## 3.1. RESs coupling and control card deployment

The work focused on the deployment of control strategies for EM in MG system that concerns the tired layer of the proposed study presented in Figure 2.1. After the deployment of the whole components of the MG system, this simple hybrid system, however, needs to be automatically controlled accordingly. In fact, D/R control approaches are therefore required for balancing the intermittent RES generation and the delay might occur between the power
production and the actual building’s consumption. The main aim is to develop a control card to test the different studied control strategies for EM. Unlike existing systems, which are used as a black-box to collect and manage the energy in MG, the deployed control card allows us to measure, monitor, manage, and deploy our algorithms (El Mouatamid et al., 2017; Elmouatamid et al., 2018). In fact, the developed card can be seen as an embedded EM system for optimal energy usage according to the actual context (Figure 4.8). Therefore, different objective functions can be taken into account when optimizing and designing a control strategy, like the smoothing of the production, the continuity of the power generated to the consumer, the energy cost, and the C/D cycle of the batteries (Elmouatamid et al., 2019b). For that, a control strategy should be deployed to satisfy the constraints designed by the optimization functions. The main communication infrastructure is employed for total energy measurement and management purposes. This infrastructure provides the autonomous operation with the required measurements, decisions, and control by collecting data through the sensors and producing the commands for the Hw/Sw card, which is connected to the control switches used in the hybrid system (Elmouatamid et al., 2019a).

<figure><img src="image_52.png" /></figure>

<figure><img src="image_53.png" /><figcaption>**Figure 4.8.** a) Schematic view of the control card, b) The deployed Hw/Sw control card (Elmouatamid et al., 2019a)</figcaption></figure>
For the data measurement, the control card collects the main control parameters (e.g., PV, WT, power consumption) to execute suitable actions depending on the predefined scenarios. However, the power generated by the WT is less than the power generated by the PV, and it is almost zero during the night. During the period of production of the WT, the PV can satisfy the demand and the WT is used to charge the batteries, as shown in Figure 4.9.

<figure><img src="image_54.png" /><figcaption>Figure 4.9. PV-WT power generated during 24 hours</figcaption></figure>

Moreover, a case study is presented for a large-scale installation in which the developed control card and the IoT/Big-Data platform are used to measure and store the data collected by the deployed current and voltage sensors for the total installed RESs, battery storage system, and load consumption. As shown in Figure 4.10, the green curve presents the power generated from the eight PV panels for 24 hours. This power is calculated by measuring the PV current and voltage variability during the day, which depends on the weather conditions (e.g., temperature, irradiance) changeability. At the same time, the battery SoC is calculated using our battery characterization system installed in the MG system. Moreover, the power consumption is measured and stored for the same period. These parameters are the main input for the EM strategy. Mainly, to ensure a high level of reliability and flexibility of the power supply demanded by the consumer in an optimal way, a preliminary control strategy for a hybrid system is presented in this section. In fact, a real hybrid system is deployed in our EEBLab for conducting experiments. Preliminary results are presented to show the usefulness of the control strategy for balancing the D/R according to the actual weather condition (production) and the occupancy (consumption). The installed MG system together with the IoT/Big-Data platform is tested and validated. Therefore, the main aim is to develop our proper control card in which we can deploy different control strategies and predictive approaches based on ML algorithms using the collected data from the deployed MG system.
<figure><img src="image_55.png" /><figcaption>Figure 4.10. Power measurement scenario in our deployed MG system platform</figcaption></figure>

## 3.2. PV-battery-grid control scenario

One of the main objectives of our studies is to minimize the C/D cycle of the battery in a deployed MG system by deploying a control strategy that considers the battery cycle in its operation. The control strategy proposed in this scenario is only to validate the operation modes of the deployed system and it is presented as follows. As described in the abovementioned sections, the estimated SoC together with power production/consumption values are used as input parameters to the proposed controller in order to select the best suitable switching mode. It allows managing the connection between the load and the battery, on one hand, and between the load and the electric grid on other hand. In fact, four modes are considered as shown in Table 4.4.

<table><caption>Table 4.4. Operating mode of the batteries</caption><thead><tr><th rowspan="2">Mode</th><th colspan="2">Battery connection</th><th rowspan="2">SoC</th></tr><tr><th>Charging</th><th>Discharging</th></tr></thead><tbody><tr><td>0</td><td>OFF</td><td>OFF</td><td>Battery at rest</td></tr><tr><td>1</td><td>ON</td><td>OFF</td><td>SoC&lt;SoCmin</td></tr><tr><td>2</td><td>OFF</td><td>ON</td><td>SoC&gt;SoCmax</td></tr><tr><td>3</td><td>ON</td><td>ON</td><td>SoCmin&lt;SoC&lt;SoCmax</td></tr></tbody></table>

For instance, the control algorithm starts first by computing the SoC and the power of the PV. If the estimated SoC is about 100%, the control stops charging and the ventilators are powered by the battery. Otherwise, a threshold value is used to select between the battery and
the utility grid. If the SoC value is above this threshold, the control selects the battery as the main power supplier; otherwise, the control checks the PV power to refine the decision. If it is below a fixed threshold value, the load is powered by the grid; otherwise, it will be powered by the battery. It is worth noting that the deployed prototype includes a ventilation system composed of two ventilators operating with 24 Watts of maximum power. This means that the choice of the threshold values of the switching between the battery and the grid needs to consider the load power. The EEBLab includes also other equipment, mainly lighting, HVAC, and other variable components. It is to notice that the experimental scenarios are realized for a limited number of PV panels in order to balance its power generation with the WT on the one hand, and due to the measurement components limits that we have.

<figure><img src="image_56.png" /><figcaption>Figure 4.11. a) Production and SoC variation b) Consumption from battery-grid and SoC status</figcaption></figure>
Figure 4.11.a shows the power generated by the deployed PV panel and the variation SoC as well. From 11:00 to 15:00, the PV is used to charge the battery and supply the ventilation system. Around 15:00, the battery started to discharge because the PV production is less than the required power. From 20:00 to 03:00, the ventilators are only supplied by the battery and the PV production is almost negligible. Between 03:00 and 08:00, the system switched to the electric grid, and we can see that during this period the battery and the PV current are almost zero.

It is worth noting that the consumption is measured using three current sensors. The first sensor is installed between the regulator and the ventilators, the second is installed between the ventilators and the transformer, which provides the power supplied from the grid, and the third one is installed after the other two sensors for data validation. The aim is to confirm the right behavior of the control strategy as depicted in Figure 4.11.b. At a certain time (around 15:00), the production became low, and therefore the ventilators are powered by the battery. Around 03h00, the SoC decreased to reach the threshold value, and the system switched from the battery to the electric grid throughout the night. At 08:00, the SoC exceeded the threshold value and the system switched back to be powered by the battery.

In this scenario, a preliminary control strategy is introduced for EM in the MG system, which aims to supply, in an optimal way, the power demands. A control card is developed and deployed for real-testing of control approaches. Another interesting point is the integration of the IoT/Big-data platform for real-time data collection, processing, and analysis. These data are used for real-time MG control by balancing the power demand and response according to the actual context.

### 3.3. PV-WD-battery-grid control scenario

PVs and WT are deployed in the EEBLab and connected together with storage devices to supply different AC/DC equipment. To ensure the power when we have bad weather conditions or during the night, the system is connected to the traditional grid. The Hw/Sw control card implements the control approach for EM in the MG system. Real-time data processing is used in this scenario to gather data from weather station, power production, and power consumption. The control approach uses these data to extract the actual context in order to select the best suitable action for either storing extra energy, or supplying directly the building equipment from the PV/Wind/Batteries, or from the electric grid. In this study, the
architecture is consists of two batteries, a buffer battery with less capacity, and the main
battery storage system with high capacity as is depicted in Figure 4.12.

<figure><img src="image_57.png" /><figcaption>Figure 4.12. The test scenario architecture</figcaption></figure>

When the loads are connected directly to the PV, to WT, or to PV/WT, the buffer battery
can smooth the power if there are sudden variations in the weather conditions. The main
storage is used to store the power from the sources and to generate power when the production
is less than the loads demands.

The developed card can be seen as an embedded EM system for optimal energy usage
according to the actual context. In fact, the PV (resp. WT) system produces the electric power
only during sunny (resp. windy) days, but the high power consumption appears to be around
midday and during the moment of sunset. During the day, the aim is to use all the energy
produced from RESs and to avoid high charging and discharging cycles of the batteries. Also
with the EM system, a priority is defined between the PV system and WT to supply the loads.
For example, it is preferable to supply the loads by the PV system and use the WT to charge
the battery because the radiation is more stable than the wind speed. We can calculate the
power produced from each source during a period to define the sources' priority and to
minimize the loss of power supply probability. The total energy produced by the RESs
(equation 4.3) is the summation of E<sub>PV</sub> and E<sub>WT</sub>, respectively produced by the PV and WT
during one day and can be expressed by equation (4.1) and (4.2), and the maximum power
demanded by the storage can be calculated by equation (4.4). The total energy calculated for each source can be taken into account, as the input parameter, to design the control strategies.

$$E_{PV} = \int_{0}^{24h} P_{PV}(t)dt \qquad (4.1)$$

$$E_{WT} = \int_{0}^{24h} P_{WT}(t)dt \qquad (4.2)$$

$$E_{RES} = E_{PV} + E_{WT} \qquad (4.3)$$

$$E_{Bat} = E_{RES} - \int_{0}^{24h} P_{Consumption}(t)dt \qquad (4.4)$$

Different objective functions can be taken into account when optimizing and designing a control strategy, like the smoothing of the production, the continuity of the power generated to the consumer, and C/D cycle of the batteries. For that, a control strategy is designed to satisfy the loads demands (lighting, ventilation system) throughout the day and night by using the PV, WT, batteries, and utility grid. The main communication infrastructure is employed for the total energy measurement and management purposes. This infrastructure provides the autonomous operation with the required measurements, decisions and controls by collecting data through the sensors and producing the commands for the Hw/Sw card connected to the control switches used in the hybrid system.

The proposed strategy could control the deployed MG system according to the following cases: i) the power generated by the PV system has priority in satisfying power demand by loads over that delivered by the WT or by the batteries, because in the testing site there is more radiation during the day than wind, ii) if the power generated by the PV system is higher than the loads demand, the PV system is connected directly to the loads using a buffer battery, which allows balancing the power delivered to the load (Figure 4.12: switch 2), in this case, the power generated by the WT is used to charge the main battery, iii) if the electric power generated by the PV system is less than power demand, PV and WT supply the power to the loads (Figure 4.12: switch 2, 3), iv) if the load demand exceeds the power generated by PV/WT combination, the difference is supplied by the main storage (Figure 4.12: switch 2), v) if the power generated by PV/WT is less than the demand and the SOC of the battery is less than 60 % (to avoid a deep discharging), the power is supplied by the traditional grid (Figure 4.12: switch 1), during this time PV/WT power is used to charge the main storage. The flowchart of the main control strategy is illustrated in Figure 4.13.
<figure><img src="image_58.png" /><figcaption>Figure 4.13. Flowchart of the power flow management</figcaption></figure>

In order to validate the behavior of the control strategy and the functionality of the hybrid system, experimental results have been extracted. The main objective is to minimize the electricity consumption from the traditional grid while maximizing the production of renewable energy. A real system is presented to extract the data to confirm the usefulness of the EM system control. The measurements of the power exchanged in the main elements of the Hybrid system are presented. Figure 4.14 shows the real hybrid system installed for this scenario.

<figure><img src="image_59.png" /><figcaption>Figure 4.14. Hybrid system implemented in the EEBLab</figcaption></figure>
### 3.3.1. Buffer battery

The buffer battery is used when the renewable energy generators are directly connected to the load. The capacity of this battery is less than the main battery storage. As shown in Figure 4.15, the C/D current of this buffer battery is low. From 7:00 AM to around 10:00 AM, the PV production is less than the power demand, for that, the buffer battery is disconnected and the battery current is zero. From 10:00 AM to around 18:00 PM we have some peak due to the variable production during this period.

<figure><img src="image_60.png" /><figcaption>Figure 4.15. Buffer battery current variation</figcaption></figure>

### 3.3.2. Main battery storage

The batteries used in the main storage have a large capacity. When the power production is higher than the power consumption, these batteries are connected to the RES just for charging. For that, in Figure 4.16 we can see that from 07:00 AM to 18:00 PM the current is positive, the batteries are charged. At the same time, the power supplied to the consumer is ensured by the PV and the WT. As shown in Figure 4.16, from 18:00 PM to 20:00 PM the power produced by the RESs is less than the power consumed in the building, and the main battery storage is connected to complete the power needs. During the night, the RESs generations are around zero and the main storage is discharged, for that we can see in Figure 4.17.a that the system switched from the RESs to the traditional grid in order to ensure the power to the loads. The inverter is used to generate the total power from different RESs and storage devices to the loads.
<figure><img src="image_61.png" /><figcaption>Figure 4.16. Main storage C/D current variation with PV production</figcaption></figure>

<figure><img src="image_62.png" /><figcaption>Figure 4.17. a) The power generated from RESs to the loads, b) Power consumed from traditional grid</figcaption></figure>
### 3.3.3. Grid power

As mentioned above, the traditional grid is used to ensure the power to the building when the power production is zero and the storage is discharged. During the 24 hours of the experimentation, the batteries are discharged around 20:00 PM and started charging around 07:00 AM. Figure 4.17.b shows that during this period the power generated by the traditional grid is equal to the power consumption (Lighting, ventilation system). The obtained results from both simulations and experimentations showed the usefulness of the introduced platform as well as the effectiveness of the proposed control strategy in managing the power flows.

## 4. Conclusions

The main aim of the work presented in this chapter is to validate the deployed MG system components with the developed control card for EM. The MG platform connects the building's components using sensing/actuating, IoT/Big-Data technologies in order to leverage real-time gathering and data processing for RESs production, battery SoC variation, and loads consumption. The platform was deployed, several scenarios have been tested and evaluated, and results showed the usefulness of the platform for efficient management of buildings components. In fact, control strategies based on real-time data collection are deployed to control the power flow for a real MG system. The proposed control strategy permits to connect multi-energy sources (e.g., PV, wind) and storage devices together with the TEG. Simulation and experiment results are presented to validate the different used models as well as the interconnection of all MG system components. These latter are used to investigate and evaluate the effectiveness of the proposed predictive approaches using both simulations and experimentations.
# Chapter 5: A Predictive Control Strategy for Energy Management in Micro-grid Systems

## 1. Introduction

Studies conducted in the previous chapter, showed that energy consumption could be efficiently reduced by deploying MG systems (Elmouatamid et al., 2020a). The aim is to minimize the electrical bill's cost while extending the lifetime of the system's components (e.g., converters, batteries, fuel-cells). Generally, an EM system incorporates control strategies and functions, which maximize the MG system's efficiency and minimize energy consumption. The work presented in this chapter introduces an intelligent and predictive control strategy, named MAPCASTE (Measure, Analyze, Plan, foreCAST, and Execute), for EM in MG systems, as depicted in Figure 5.1. MPC and GPC have been investigated in order to carry out the proposed MAPSASTE. This later was deployed and evaluated by assessing its effectiveness for EM in MG systems (Elmouatamid et al., 2020b). In fact, the main aspect of the proposed MAPCASTE approach is to measure, in real-time, the main input control parameters; analyze the data for ML algorithms training, prediction of the future behaviors, forecasting the suitable commands to reach the desired setpoint depending on the predefined constraints and objective functions, and correcting the errors depending on the real measurements.

<figure><img src="image_63.png" /><figcaption>Figure 5.1. EM schemes with GPC operation process</figcaption></figure>
In this chapter, forecasting models are first presented for predicting the power production and consumption in MG systems together with the battery SoC. A control strategy is then implemented to balance the D/R by taking into account the forecasted and real-time values. Therefore, a hierarchical control approach is proposed to manage the energy flow in MG systems. More precisely, an EM system is deployed based on model predictive control in order to manage the operation of such MG and in particular its interaction with the main electricity grid. A power converter is then modeled and controlled by a GPC model in order to ensure the interaction with the grid. An optimization function with dedicated constraints is modeled for both secondary and tertiary layers. For the second layer, the C/D cycle of the battery and the maximum power extracted from RESs are designed as the main constraint to be optimized by the GPC model, while for the tertiary layer the electricity price is integrated as an input parameter for the control.

## 2. Power forecasting for MG systems

The variability and the uncertain nature of power production and consumption make the system more difficult to control. In fact, weather conditions influence the production of RESs while occupancy influences power consumption. Therefore, the development of accurate short term forecasts are needed for seamless integration of RES (e.g. PV system, WT) together with the TEG in MG systems. This section presents a forecasting model for predicting the power production and consumption in MG systems together with the battery SoC. A control strategy is then implemented to balance the D/R by taking into account the forecasted and real-time values. Based on the data collected from a real MG system, simulation results are presented to show the effectiveness of power forecasting for MG control.

### 2.1. Classification of power forecasting techniques

Different ML methods can be used to forecast the power production and consumption using the historical behavior of data. The forecasting can be able to minimize the consumption from TEG by maximizing the RES generation, in consequence reducing the electricity cost. An accurate forecast is used to reduce the uncertainties of the RES integrated into MG by implementing control strategies based on the forecast values. Different techniques can be implemented for load and PV power forecasting: exponential smoothing, multiple regression, stochastic time series, statistical models, and artificial intelligence.
Many methods have been proposed in the literature; however, selecting the best suitable ones to be used for MG control is required. In fact, power forecasting is an integral process in the planning and the control of electric utilities in the MG system. It is frequently identified as an important tool to address the uncertainty and the variability of power production and load consumption in the MG with a large RES integration. Some forecast algorithms need a high quantity of data to be trained and to have a low error (e.g. ANN, LSTM) (Breiman et al., 2001; Nottona et al., 2013; Rana et al., 2015; Pedro et al., 2017). Generally, these algorithms need a long training time to be stabilized and to be executed; it can be used for medium and long-term forecasting cases. In addition, based on the time series analysis, a classification can appear (Figure 5.2). In another way, other algorithms can be trained by a low quantity of data to forecast a very short or short term in the future (e.g. ARIMA, ARX). During a given period, the algorithms calculate the error between the observed and forecasted values in order to ensure that the error does not increase more than the threshold limits. While the application area is an interesting point to define the categories and the algorithms of the forecast to implement. For the control, the time horizon can be very-short, from a few minutes to one hour or more ahead to make decisions. For that, an algorithm, which demands a few time to be trained, can be selected. For example, the control strategy can switch from PV panels and batteries to the traditional electric grid if the forecasted values show that in a few moments the RES cannot satisfy the demand. This decision can be implemented based on the forecasted values obtained during a few minutes. Therefore, the integration of the price as an input parameter to the control strategy needs a few hours ahead of the forecast values to stabilize the system.

<figure><img src="image_64.png" /><figcaption>Figure 5.2. Time scale forecasting classification</figcaption></figure>
The electricity price varies during the time by considering the peak of the consumption and production. Another classification can be used by considering the stability of the data used to train the algorithm and the variability of the values to forecast. Figure 5.3 shows a basic classification of the methods that can be implemented to forecast the RES generation and the load consumption based on the data type used to train the algorithms (i.e., stationary or no-stationary).

<figure><img src="image_65.png" /><figcaption>Figure 5.3. Power forecasting methods</figcaption></figure>

## 2.2. Deployed forecasting technique

Statistical models approaches, as stated above, do not need internal functionality information from the system, which generates the value to forecast. It is a data-driven approach that is able to extract relationships on previous data in order to forecast the future behavior of the values. However, the quality of historical data is essential for an accurate forecast, a large historical of data is typically required. These approaches benefit from the capability of correcting systematic errors associated with the measurement of inputs (Graditi et al., 2016). They include the regressive methods, which estimate a relationship between dependent (e.g. temperature, irradiation) and independent parameters (e.g. model temperature, wind speed).

ARIMA is one of the popular linear models in time series forecasting due to its statistical properties as well as Box Jenkins methodology in the model building process (Box GEP et al., 2008). It is one of the most useful approaches used to analyze the non-stationary time-series,
by integrating two approaches for stationary time series, autoregressive (AR), moving average (MA), and combined AR and MA (ARMA) series. The application of the ARIMA method has a fundamental impact on the study of the non-stationary time series analysis due to Box and Jenkins approach, which includes five iterative steps (Mbamalu et al., 1993) (Figure 5.4), as described below.

<figure><img src="image_66.png" /><figcaption>Figure 5.4. Different iterative steps of ARIMA model</figcaption></figure>

Differentiation step, in this phase general ARIMA models is presented to model the data. The general formulation is presented by equation (5.1) (Alfares et al., 1999):

$$ \varphi_p(B)\Phi_{sp}(B^l)\Delta^d\Delta_l^{sd}X_t = \Theta_{sq}(B^l)\theta_q(B)\epsilon_t \quad (5.1) $$

where B represents the back-shift operator ($B$: $B^{-1}(X_t) = X_{t-1}$ and $B^{-l}(X_t) = X_{t-l}$), this function can contain factors of polynomial functions presented by equation (5.1.a) as follow:

$$ \varphi_p(B) = 1 - \sum_{l=1}^{p} \varphi_l B \\ \theta_q(B) = 1 - \sum_{l=1}^{q} \theta_l B \qquad (5.1.a) $$

$$ \Phi_{sp}(B^l) = 1 - \sum_{m=1}^{sp} \Phi_{ml} B^l $$

$$ \theta_{sq}(B^l) = 1 - \sum_{n=1}^{sq} \theta_{nl} B^l $$

where, the non-seasonal operators are $\varphi_p(B)$ and $\theta_q(B)$ and the seasonal operators are $\Phi_{sp}(B^l)$ and $\theta_{sq}(B^l)$. The terms $\Delta^d = (1 - B)^d$ and $\Delta_l^{sd} = (1 - B^l)^{sd}$ are respectively the
non-seasonal and seasonal differencing operator. $X_t$ is the power at the actual time $t$, and $\epsilon_t$ represents the error at the period $t$.

Identification step is the estimated procedures applied to a data to find the best ARIMA model by determining appropriate parameters $(p, q)$ and $d$, in order to obtain the stationary time series. It is a critical step to build an ARIMA $(p, d, q)(sp, sd, sq)$ model, where AR: $p$ is the auto-regression order of the model, which indicates the number of parameter $\phi$, and I: $d$ is the degree of differencing to make a stationary data $X$ of the model, and MA: $q$ is the order of the moving average aspect, which indicates the number of the model parameter $\theta$, $sp$ is the seasonal AR order, which indicates the number of parameter $\Phi$, $sq$ is the seasonal MA order, which indicates the number of parameter $\Theta$, and $sd$ is the number of times the data series needs to be seasonally differenced in order to indicate a seasonally stationary series. Estimation step, once the model is specified to obtain the stationary time series, the model parameters are estimated in such a way that the error is minimized. Its parameters are estimated from the conditional least squares methods, based on the values estimated during the identification step. The last step of ARIMA model's building is the diagnostic checking, after the identification and the estimation of the model parameters, this step checks if the model is a good fit for the data, the assumptions about the errors (also known as the residuals) are satisfied, then determines if the autocorrelation is zero or insignificant. If the model is inadequate, a new model should be identified by the different steps of parameter estimation and model verification.

The idea with ARIMA model is that the finale residual should look like white noise and verify if there is information available in the data to extract. In each step of ARIMA modeling (AR, I, MA), time-series data is passed through these three parts to produce less residual. The sequence of three steps for ARIMA analysis is started by the integrated step, in this step the model subtracts time series with its lagged series in order to extract trends from the original series data. The differencing order is used to subtract the data; equation (5.2) presents the differencing order one and two.

$$ \left. \begin{array}{l} (d=1): X'_{t} = X_{t} - X_{t-1} \\ (d=2): X'_{t} = X_{t} - X_{t-1} - (X_{t-1} - X_{t-2}) \end{array} \right\} \qquad (5.2) $$

The formula is used to remove the trend in order to make data stationary on average but it is not stationary on variance. In order to produce reliable forecasts through ARIMA models, we need to make the series stationary on variance. For this reason, the original time series data
is transformed by a logarithmic function. The following equation represents the process of log transformation mathematically (equation (5.3)).

$$X_t'' = \log_{10}(X_t) - \log_{10}(X_{t-1}) \qquad (5.3)$$

After the time series data is transformed in the integrated step, the influence of the previous observed values on the current values is extracted in the autoregressive step. This is done by developing a regression model with the time-lagged period values as predictor variables. Equation (5.4) presents the general form for the regression model.

$$X_t = \phi_1 X_{t-1} + \phi_2 X_{t-2} + \cdots + \phi_p X_{t-p} + \epsilon_t \qquad (5.4)$$

Concerning MA step, the influence of the previous period's error terms on the current period's error is extracted. MA part of ARIMA is developed with the simple multiple linear regression values with the lagged error values as predictor variables (equation (5.5)).

$$X_t = \epsilon_t + \theta_1 \epsilon_{t-1} + \theta_2 \epsilon_{t-2} + \cdots + \theta_q \epsilon_{t-q} \qquad (5.5)$$

ARIMA model is defined by coupling the three models (AR, I, MA). The values of ARIMA should firstly be defined by optimizing a metric of interest, such as partial correlation and autocorrelation of the series, AIC and BIC values. The idea is to choose a model with minimum AIC and values. AIC is a measure of the quality of fitting an estimated model. It is based on the concept of entropy, which is a measure of the information lost when a mathematical model is used to describe the actual data. The AIC can be defined by equation (5.6).

$$AIC = \log Z + \frac{2n}{N} \qquad (5.6)$$

where N is the number of values in the estimation data set, n is the number of the estimated parameters, and Z is the loss function.

It is worth noting that another key factor that should be taken into consideration is the precision of the model. To measure the accuracy of the predictions, the errors between the forecasted values and actual data are analyzed. Tow indicators are used, MAE and the MSE. These two indicators have been used to evaluate the accuracy of the obtained model to be used for forecasting.
$$MAE = \frac{1}{N} \sum_{t=1}^{N} |X_t - F_t| \qquad (5.7)$$

$$MSE = \frac{1}{N} \sqrt{\sum_{t=1}^{N} (X_t - F_t)^2} \qquad (5.8)$$

## 2.3. Control strategy based on forecasting method and simulation results

The proposed strategy could control the deployed MG system, which contains a PV panel connected to battery storage in order to ensure the power to a ventilation and lighting systems. In this case study, the control strategy is based on the forecasted values to make control decision according to the following cases: i) the power generated by the PV system has priority in satisfying power demand by loads over that delivered by the TEG or by the batteries, ii) if the power generated by the PV system is higher than loads demand, the PV system is connected directly to the loads, iii) if the electric power generated by the PV system is less than demand, power will be supplied from the PV and the main storage, v) if the power generated by PV is less than the demand and the SoC of the battery is less than 40 % (to avoid a deep discharging), the power will be supplied by the traditional grid, during this time PV power is used to charge the main storage.

In fact, during the day the PV production is used to ensure the power to the loads and to charge the battery as well. As shown in Figure 5.5.a, from 01:00 PM to thereabouts 08:00 PM the irradiation decreases, during this time the battery starts to discharge in order to ensure the power to the loads together with the PV panel. Moreover, during the night only the battery is used to supply the power to loads, but when the SoC reaches the threshold value the control strategy switches from RES to the TEG. In addition, the power consumption data are collected and the ARIMA model is deployed to forecast the consumption during the same period for the test. In fact, the consumption depends on the occupant's activities in the building. As shown in Figure 5.5.c, the consumption variety is due to the ventilation speed variety, which depends on the indoor CO₂ concentration. The previous data are used to train ARIMA, which starts to forecast the consumption around 01:00 AM and the obtained results are compared to the real data.
<figure><img src="image_67.png" /><figcaption>Figure 5.5. a) Forecasting and real PV power, b) Forecasting and real SoC, c) The real and the forecasted power consumption</figcaption></figure>

The input parameters used for this control strategy are the PV power production, load consumption, and SoC of the battery. For that, a dataset of the PV power production, load consumption, and SoC is used to train the implemented ARIMA forecasting algorithm. The obtained algorithm is used to forecast the control strategy input parameters. Figure 5.5.a presents the forecasting power together with the real power of the PV, the values are obtained a few minutes before the real-time values. The same for the SoC of the battery, Figure 5.5.b shows that around 2:30 AM the control strategy switches from RES to the traditional grid because the forecasting value obtained shows that the threshold value of the SoC will be attended (Figure 5.6.b). For that, the SoC remains constant at 50% from 2:30 AM to the end of the simulation.
<figure><img src="image_68.png" /><figcaption>Figure 5.6. Control decision: a) The switching moment based on real-time values, b) The switching moment based on forecast values</figcaption></figure>

Therefore, the battery is discharged to 40% around 3:00 AM (Figure 5.6.a) when the control strategy is based on the real-time values of the SoC. Figure 5.6.a shows the switching moment of the control strategy based on the real data obtained. Around 3:00 AM the battery is discharged and the system switches at this moment when the threshold value of the SoC is obtained, from the RES to the TEG. The same model is simulated using the forecast values like input parameters to the control strategy. Figure 5.6.b shows that the control strategy switches from PV and battery to the traditional grid when the threshold value of the SoC is obtained by the forecasting algorithm. In this case, the switching moment is obtained before the switching (Naïve approach) moment obtained in the case when the real values are used as input parameters. In fact, a predictive control strategy allows for avoiding possible blackouts
in the MG. The system is able, via the forecasting process, to process future values, which allow deciding on the best suitable source before getting in these blackouts situations.

In another scenario, the deployed algorithm computes at each time the different parameters based on the minimum AIC. As shown in Table 5.1.a, the minimum AIC is calculated and the equivalent ARIMA parameters are selected. For that, the ARIMA steps are realized in order to predict future values by maximizing the accuracy between the predicted and the real values. In fact, to measure the prediction accuracy, the errors are calculated by comparing the predicted and the real values (Table 5.1.b).

<table><caption>Table 5.1. The minimum AIC, b) The errors for ARIMA parameters determination</caption><thead><tr><th colspan="2">a)</th></tr></thead><tbody><tr><td>ARIMA(0, 0, 1)x(0, 1, 0, 12)</td><td>AIC:62710.84745637427</td></tr><tr><td>ARIMA(0, 0, 1)x(0, 1, 1, 12)</td><td>AIC:62753.61460619093</td></tr><tr><td>ARIMA(0, 0, 1)x(1, 0, 0, 12)</td><td>AIC:62714.03259053544</td></tr><tr><td>ARIMA(0, 0, 1)x(1, 0, 1, 12)</td><td>AIC:62720.49716196509</td></tr><tr><td>ARIMA(0, 0, 1)x(1, 1, 0, 12)</td><td>AIC:62671.88138477944</td></tr><tr><td>ARIMA(0, 0, 1)x(1, 1, 1, 12)</td><td>AIC:62695.284563062145</td></tr><tr><td>ARIMA(0, 1, 0)x(0, 0, 0, 12)</td><td>AIC:-3234.553093513031</td></tr><tr><td>ARIMA(0, 1, 0)x(0, 0, 1, 12)</td><td>AIC:-3659.388317612963</td></tr><tr><td>ARIMA(0, 1, 0)x(0, 1, 0, 12)</td><td>AIC:15472.320320780986</td></tr><tr><td>ARIMA(1, 0, 1)x(0, 1, 1, 12)</td><td>AIC:9679.542874411818</td></tr><tr><td>ARIMA(1, 0, 1)x(1, 0, 0, 12)</td><td>AIC:-10955.736960633389</td></tr><tr><td>ARIMA(1, 0, 1)x(1, 0, 1, 12)</td><td>AIC:-10852.704233932041</td></tr><tr><td>ARIMA(1, 0, 1)x(1, 1, 0, 12)</td><td>AIC:181.01318158835284</td></tr><tr><td>ARIMA(1, 0, 1)x(1, 1, 1, 12)</td><td>AIC:443.1730259998549</td></tr><tr><td>ARIMA(1, 1, 0)x(0, 0, 0, 12)</td><td>AIC:-17301.58083630186</td></tr><tr><td>ARIMA(1, 1, 0)x(0, 0, 1, 12)</td><td>AIC:-17921.721669614883</td></tr><tr><td>ARIMA(1, 1, 0)x(0, 1, 0, 12)</td><td>AIC:2209.839536935602</td></tr><tr><td>ARIMA(1, 1, 0)x(0, 1, 1, 12)</td><td>AIC:-17185.339012788172</td></tr></tbody></table>

b)

<table><thead><tr><th></th><th>coef</th><th>std err</th><th>z</th><th>P>|z|</th><th>[0.025</th><th>0.975]</th></tr></thead><tbody><tr><td>ar.L1</td><td>0.9869</td><td>0.000</td><td>2027.760</td><td>0.000</td><td>0.986</td><td>0.988</td></tr><tr><td>ma.L1</td><td>0.4186</td><td>0.002</td><td>224.696</td><td>0.000</td><td>0.415</td><td>0.422</td></tr><tr><td>ar.S.L12</td><td>-0.5821</td><td>0.002</td><td>-258.078</td><td>0.000</td><td>-0.587</td><td>-0.578</td></tr><tr><td>sigma2</td><td>0.0590</td><td>0.000</td><td>316.822</td><td>0.000</td><td>0.059</td><td>0.059</td></tr></tbody></table>

The prediction of the power generation and the electricity demand can be used to calculate the battery SoC and the predicted parameter is used as input to the control strategy. During the day, the PV panels generate the power to the loads, charge the battery, and the surplus is transmitted to a resistance, which is considered as the grid injection. As shown in Figure 5.7.a, for 48 hours the PV power production is collected. For the first day, from 02:00 PM to around 06:00 PM and due to the bad weather conditions, the PVs generation decreases. During this period, the battery supplies the power to the load accumulating the need for power caused by the decrease of PV generation (Figure 5.7.b). Moreover, during the night, only the batteries generate electricity to supply the load, and when the SoC is at its minimum, the control strategy switches from RES to the TEG.
<figure><img src="image_69.png" /><figcaption>a)</figcaption></figure>

<figure><img src="image_70.png" /><figcaption>b)</figcaption></figure>

<figure><img src="image_71.png" /><figcaption>c)</figcaption></figure>

Figure 5.7. a) Predictive and real PV generation, b) Predictive and real SoC, c) Predictive and real loads consumption
In addition, to forecast the power consumption during the same period of the tests, the ARIMA model is deployed using the real data-set of power consumption. It is worth noting that the occupants' activities influence power consumption. As shown in Figure 5.7.c, the energy demand behavior varies due to lighting and the ventilation speed's variation, which is mainly influenced by occupants' activities. The ARIMA model is trained using the gathered data and then the obtained model is used to forecast the desired parameters' values.

Figure 5.7.a illustrates the power forecast (orange curve) with the real PVs generation (Blue curve). For each instance, the deployed ARIMA model generates a value with a timestamp of about three minutes. The same for the battery SoC, Figure 5.7.b indicates that around 06:00 PM the control approach switches from renewable energy to the TEG because the battery SoC reaches the threshold value as predicted. At the same time, the power consumed from RES was measured (Figure 5.7.c), the orange curve presents the power consumption generated by ARIMA model and the blue curve is the real power consumption. The Obtained results are used as inputs for the MPC in order to predict the suitable action by respecting the predefined constraints ($P_{load} = P_{pv} \pm P_{bat}$).

As described above, the predictive control approach is able to balance the power generated from a PV panel using battery storage in order to ensure the power to the load. The input parameters used in the control strategy are the PV power production, SoC of the battery, and the load power consumption. These input parameters are forecasted and the values obtained for a very short term are used as input parameters to the control strategy. In the rest of this chapter, we carry out the MAPCASTE approach using model predictive control, the MPC and GPC, using the abovementioned forecasting method of power consumption and production including the battery's SoC.

### 3. MPC-based control for energy balance in MG Systems

A ML algorithm, as described in the previous section, was deployed to predict future values, which are used by the control strategy. In this section, an MPC strategy is developed to solve the optimal constraints function by computing efficient management actions. It presents an essential control approach that can be used to predict and forecast the suitable actions in MG systems according to the system's constraints. More precisely, the main objective is the development of an intelligent and predictive control strategy for EM in the MG system based on an MPC model. To reach this aim, the following studies are realized. An EM approach based on the MAPCASTE principles is introduced for MG system's control, the
controllable system and the operational constraints are modeled by a state-space equation for MPC deployment, a data-monitoring platform is installed for real-time data forecasting in order to carry out the MAPCASTE control loop. The effectiveness of the deployed control approach is studied in real-sitting scenarios using our MG system.

## 3.1. MG modeling and control approach

The deployed control approach considers the batteries SoC evolution in order to keep the operating costs of the whole system at a reasonable level. For this aim, the deployed batteries are modeled and simulated using the OCV model with resistance. As mentioned in equation (5.9), the OCV is written as an SoC function.

$$V_{bat}(t) = OCV(SoC(t)) + R \cdot I_{bat}(t) \qquad (5.9)$$

The dynamic voltage of the *Ohmic* resistance *R* and the OCV present the behavior of the battery voltage variability. This equation can be stated as follows:

$$Y(t) = a \cdot SoC(t) + R \cdot I \qquad (5.10)$$

where *I* represents the C/D battery current, *a* is a factor defined by the experimental battery characterization using the least-squares method, and *R* presents the *Ohmic* resistance. By considering that the battery current is null during the full charged mode of the battery, we can then calculate the SoC by exploiting directly the battery's voltage variability. In fact, equation (5.10) can be presented as follows:

$$Y(t) = SoC(t) \qquad (5.11)$$

Moreover, using the Coulomb method, the SoC can be formulated as the nominal capacity *C* ratio and is accumulated on the operation period *τ*. It is calculated by the current flow-rate measurement and integration over the interval of time (equation (5.12)).

$$C(t + \tau) = C(t) + \Delta C \qquad (5.12)$$

We can use the measured battery C/D current $I_{bat}$ together with the actual $SoC(t)$ in order to estimate the future values $SoC(t + 1)$ by applying equation (5.13). In this work, the measured $I_{bat}$ is implemented to train the ML algorithm and the forecasted current is used to calculate the SoC. The deployed predictive control approach uses input prediction values to generate the feed-forward.
$$ SoC(t + 1) = SoC(t) + I_{bat}(t) \cdot \Delta t/C \qquad (5.13) $$

The main aim is to manage the C/D current based on the control strategy. Therefore, the MPC adjusts the $I_{bat}$ by considering the variability of RESs generation and loads demand in order to define the operation mode: battery charging, battery discharging, or battery-at-rest. The constraints of the model are presented by equation (5.14), where $P_{pv}$ is the PV panels' generation, $P_{load}$ is the loads' consumption, $P_{bat}$ and $P_{grid}$ represent respectively the power extracted or generated from batteries, and the power extracted from the TEG.

$$ P_{load} = \begin{cases} P_{pv} \pm P_{bat}; & \text{if } P_{pv} \ge 0 \text{ and } SoC > SoC_{min} \\ P_{grid}; & \text{if } P_{pv} < P_{load} \text{ and } SoC < SoC_{min} \end{cases} \qquad (5.14) $$

In fact, the control strategy specifies a discharge limit to avoid battery deep-discharge when the RESs production is unavailable and the battery is at its minimum SoC. Moreover, the batteries store the surplus of the PV panels generation according to the following cases: the battery starts charging during the peak production ($P_{load} < P_{pv}$), it starts to supply the loads when the demand surpasses the PV panels' production ($P_{load} > P_{pv}$), and finally the battery is at rest if the SoC is at the fixed threshold and the PV power generation is unavailable ($SoC < SoC_{min}$ and $P_{pv} = 0$) or the battery SoC is at the maximum. To keep the SoC at its maximum as much as possible, the optimization function can be represented by the given objective function $E_N$ (equation (5.15)), which should be minimized within a future horizon $n$.

$$ E_N = SoC_{max} \begin{pmatrix} 1 \\ \vdots \\ 1^n \end{pmatrix} - \begin{pmatrix} SoC(t) \\ \vdots \\ SoC(t+n) \end{pmatrix} \qquad (5.15) $$

The problem constraints that should be satisfied are formulated in equation (5.16) as follows:

$$ \begin{cases} SoC_{min} < SoC_k(t + k) < SoC_{max} \\ P_{pv} \pm P_{bat} = P_{load} \end{cases} \qquad (5.16) $$

Now, the MPC strategy could be designed based on the formulated constraints and the above-mentioned equations, which we have defined for managing the power exchange in the MG system. In fact, for our system modeling, the $SoC(t)$ is considered as the system state equation. The equation (5.11) expression can be rewritten in the state equation form as follows:
$$x(k+1) = Ax(k) + BU(k) \qquad (5.17)$$

where $x(k)$ represents the system state for $A = 1$. In this case, the $I_{bat}$ is the systems' input. The equality could be interpolated to n-steps-ahead to obtain the following representation (equation (5.18)):

$$\left\{
\begin{array}{l}
x(k + 2) = A^2 x(k) + ABU(k) + BU(k + 1) \\
x(k + 3) = A^3 x(k) + A^2 BU(k) + ABU(k + 1) + BU(k + 2) \\
\vdots \\
x(k + n) = A^n x(k) + A^{n-1} BU(k) + \cdots + BU(k + n - 1)
\end{array}
\right.
\qquad (5.18)$$

The matrix form for this representation could be written as follows:

$$\begin{pmatrix} x(k+1) \\ \vdots \\ x(k+n) \end{pmatrix} = \begin{pmatrix} A \\ \vdots \\ A^n \end{pmatrix} x(k) + \begin{pmatrix} B \\ AB \\ \vdots \\ A^{n-1}B \end{pmatrix} \begin{pmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ \vdots & B & 0 \\ \vdots & \cdots & AB \end{pmatrix} \begin{pmatrix} U(k) \\ \vdots \\ U(k+n+1) \end{pmatrix} \qquad (5.19)$$

This equation takes the following form:

$$\bar{X} = \bar{A} x(k) + \bar{B} U(k) \qquad (5.20)$$

The observation equation could be interpolated to n steps as follows:

$$\begin{pmatrix} y(k+1) \\ \vdots \\ y(k+n) \end{pmatrix} = \begin{pmatrix} CA \\ \vdots \\ CA^n \end{pmatrix} x(k) + \begin{pmatrix} CB \\ CAB \\ \vdots \\ CA^{n-1}B \end{pmatrix} \begin{pmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ \vdots & CB & 0 \\ \vdots & \cdots & CB \end{pmatrix} \begin{pmatrix} U(k) \\ \vdots \\ U(k+n+1) \end{pmatrix} \qquad (5.21)$$

$$\text{This representation is equivalent to: } \bar{Y} = \bar{C}x(k) + \bar{D}\bar{U} \qquad (5.22)$$

The following variation of the input vectors is considered as follows,

$$\left\{
\begin{array}{l}
U(k) = U(k-1) + \Delta U(k) \\
U(k+1) = U(k) + \Delta U(k+1) = U(k-1) + \Delta U(k) + \Delta U(k+1) \\
\vdots \\
U(k+n-1) = U(k-1) + \Delta U(k) + \Delta U(k-1) + \cdots + \Delta U(k+n-1)
\end{array}
\right.
\qquad (5.23)$$

The matrix form for this representation is:

$$\begin{pmatrix} U(k) \\ U(k+1) \\ \vdots \\ U(k+n) \end{pmatrix} = \begin{pmatrix} 1 \\ \vdots \\ 1^n \end{pmatrix} U(k-1) + \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 1 & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 1 & \cdots & 1 & 1 \end{pmatrix} \begin{pmatrix} \Delta U(k) \\ \Delta U(k+1) \\ \vdots \\ \Delta U(k+n+1) \end{pmatrix} \qquad (5.24)$$

This representation is equivalent to:
$$ \bar{U} = I_1 U(k-1) + I_2 \Delta \bar{U}(k) \qquad (5.25) $$

Equations (5.25) and (5.20) can be combined to obtain the following predictive model (equation (5.26)):

$$ \bar{X} = \bar{A} x(k) + \bar{B} I_1 U(k-1) + \bar{B} I_2 \Delta \bar{U}(k) \qquad (5.26) $$

Combining equations (5.19) and (5.20), the predictive observation model is presented as follows:

$$ \bar{Y} = \bar{C} x(k) + \bar{D} I_1 U(k-1) + \bar{D} I_2 \Delta \bar{U}(k) \qquad (5.27) $$

The constraint function to optimize is represented by the equation (5.28), which is equivalent to the command $\Delta \bar{U}(k)$ to reduce the error. In fact, the battery is used to absorb or generate the power satisfying the energy balance (D/R). At the same time, it is more important to keep the battery at its maximum $SoC_{max}$ when it is possible.

$$ Y_{ref} = [SoC_{max}(k+1), SoC_{max}(k+2), \dots, SoC_{max}(k+n)] \qquad (5.28) $$

Finally, the error is formulated by equation (5.28.a) by considering the desired regulation, which is required to reach by the control model.

$$ E = Y - Y_{ref} \qquad (5.28.a) $$

Then, to get the control series $\Delta U$, the criterion function to optimize is represented by the following:

$$ J = \frac{1}{2} (EQE^T + \Delta \bar{U} R \Delta \bar{U}^T) \qquad (5.29) $$

where $Q$ and $R$ are, respectively, the error and the inputs' variation covariance matrices. A priory is choosing for the diagonal matrix $R$ to ensure the algorithm convergence. The control approach manages the system to generate the values that minimize the $J$ while respecting the constraint (equation (5.16)). As illustrated in Figure 5.8, by respecting the constraints, the deployed MPC controls the battery charged/discharged state accordingly. The MPC controller either charges the batteries, absorbing the PV panels' production surplus or discharges the batteries to ensure the power demand to the consumers.
<figure><img src="image_72.png" /><figcaption>Figure 5.8. A schematic view of the predictive control model</figcaption></figure>

Mainly, by considering the constraints, the TEG is integrated and it is used when the battery SoC extents the limit value and the PV panels' production cannot satisfy completely the demand. The SoC is considered as an input parameter to the MPC model, it is calculated by predicting the battery C/D current using the deployed ARIMA algorithm. The battery current is also obtained by the prediction of the PV panels' generation as well as the load consumption.

## 3.2. MPC strategy deployment and validation

As described early, we are aiming to deploy the MAPCASTE closed-loop for MG management. A platform was deployed to allow sensing and analyzing data generated by sensors. The stored data are used to train the ARIMA model and the predicted values are used as inputs for the control strategy. In fact, input parameters are predicted using ARIMA while control actions' forecasting are computed using the MPC controller. These two last phases are described in this section together with the performance evaluation.

The deployed MG system is used to collect real data, which are used to validate the results for both the MPC and a PID controller. As stated above, this system contains RESs (e.g., PV, grid), storage systems, and active loads (e.g., lighting, ventilators). The PV panels charge the batteries, which in turn provide the power to the lighting and ventilation systems. However, during the night or cloudy days, the batteries discharge and the operation of the loads is ensured from the TEG. So, to ensure efficient MG management, the control approach uses the predicted values (from the ARIMA model) to forecast the control decisions. The following cases are obtained: i) the PV power production has the priority to generate the electricity in order to satisfy the loads over the TEG and the storage devices; ii) the PV panels supply directly the electricity to the loads when it is more important than the loads' demand,
iii) when the PV generation could not satisfy the loads' demand, PV and the main battery storage supply the power to the loads, v) if the battery SoC is less than 50 % and the RESs generation is less than the loads demand, then the system switches to the TEG. During this period the PV panels charge the main energy storage.

Essentially, the aim of the proposed MAPCASTE is to optimize the batteries' C/D current according to electricity production and consumption. In fact, the MPC controller allows balancing the power flows accordingly. In order to show the effectiveness of the MAPCASTE, results obtained when using the MPC are compared with those obtained from a PID controller. Mainly, the PID model is deployed in the charge controller in order to regulate the PV power production. Unlike PID, the MPC strategy forecasts suitable actions for either switching to the batteries or to the TEG. It's worth noting that the PV system is simulated with the same input parameters for real a scenario (e.g., irradiance, temperature) with the same load demand variability. In addition, a model for the deployed battery is characterized in order to be integrated into the simulation. The duty cycle of the charge controller and the converter are controlled by the commands that are generated by the MPC bloc depending on the predicted context of the PV power generation, the battery SoC, and the load consumption. The predictive commands are generated and shifted by the forecast time horizon compared to the real command obtained by the PID control. Moreover, the C/D current variability depends on the PV panels' generation and the demand variability. In fact, the battery SoC influences directly to the battery current; more the battery is charged more the current decreases. In this scenario, the battery C/D current is the setpoint for the MPC and the PID model (Figure 5.9). It is calculated by the predictive C/D current, which depends mainly on the PV panels' production and power consumption as well.

Figure 5.9 presents the real variability of the C/D current during two days (orange curve). Around 02:00 PM, the batteries start to discharge supplying the power to the load depending on the constraints presented in equation (5.16). Almost at 06:00 PM, the minimum SoC is reached, and during the night, the control/card switches from RESs to the TEG. In the morning, the RES start producing the electricity, which is used mainly to supply the power to the load, the surplus is used to charge the battery. In fact, the obtained results are used as a setpoint for the MPC and the PID model in order to calculate the SoC.
<figure><img src="image_73.png" /><figcaption>Figure 5.9. a) Battery C/D current variability, b) Comparison of the current for the different methods</figcaption></figure>

Figure 5.10 presents the SoC obtained by the MPC (blue curve) and the PID (green curve). The SoC variability is presented depending on the MPC and PID controller command, which is required to reach the desired SoC. Moreover, the ML algorithm predicts future values with insignificant errors. Through the deployment of this model, the current is generated and it is used to predict the future SoC desired at each time. The MPC model uses the SoC to forecast future control actions depending on the operational context. As shown in Figure 5.10.b, during sudden change of the values, the PID presents an interesting peak for the
transit regime. Unlike the PID, the MPC forecasts the corresponding power to generate or to
extract from storage devices avoiding a sudden change of the current. For that, the MPC
presents a stable regime compared to the PID (Figure 5.10.a).

<figure><img src="image_74.png" /><figcaption>Figure 5.10. a) SoC variability for the different methods, b) The obtained SoC comparison for the different methods</figcaption></figure>

As stated by the abovementioned results, the proposed predictive control approach manages the MG by maximizing the usage of the RES while considering the storage devices' limits. In fact, the MPC strategy forecasts future actions to control the C/D currents of the battery, by considering the specific variability of power production and loads' consumption. The optimization function and the constraints are presented for the proposed MPC strategy
and the obtained results illustrate the utility of the model for efficient control of the MG compared to the PID control.

Next section will enhance the MPC by considering its generalized version (GPC) by including additional constraints, in particular, the electricity price forecasts. Therefore, the energy price is an interesting exogenous for both the consumer and the central grid. Firstly, as most known, the main challenge for the actual grid is the “electricity blackouts” that are generally caused by high demands during the “peak hours” (e.g., morning, evening). Within this context, the electricity operators use the price as penalties for the consumer to avoid “peak demand” during some periods. Thus, the energy price has become an exogenous factor for the grid by minimizing the consumption during the period when the price is expensive, which is equivalent to the “peak demand period”. Secondly, a consumer that has RESs installation with a storage system can locally manage the energy flow depending on electricity price. For a given scenario, the consumer can use the central grid avoiding then the use of the local storage system, which will be kept at its maximum for usage during the high price periods.

# 4. MG system modeling for GPC integration

## 4.1. GPC modeling, constraints and objective functions

The GPC is a predictive approach that allows computing and predicting the suitable actions for being performed according to forecasted and contextual information/constraints of MG systems. It can be classified with advanced process control families with less variation in process variables. Its main concept, as depicted in Figure 5.11, is described as follows. Based on a predefined model of the MG system, optimal future actions (controls/commands) are computed to reach the desired setpoint according to the defined constraints and optimization functions. These functions consider future error, constraints, and control parameters.

<figure><img src="image_75.png" /><figcaption>Figure 5.11. A schematic view of GPC concept and control mechanism</figcaption></figure>
As described in Figure 5.11, the predictor generally calculates, for each instant $t$, the predictions of the dynamic evolution of the process $[y(t+1), ..., y(t+N)]^T$ throughout the defined horizon, N-steps ahead. This prediction is based on the dynamic parameters, which are measured at $t$, as well as the future control system's regulation $[u(t), u(t+1), ..., u(t+N)]^T$, along the prediction horizon $N$. The future control actions are then generated in order to optimize the desired cost function by resolving, at each defined time step, the predefined constraints. The designed cost function keeps the system's output at $(t+k)$ as close as possible to the defined setpoint. This setpoint dictates the output evolution accordingly. Generally, the cost function takes the form of a quadratic function of the errors between the predicted output and the setpoint (Ławryńczuk, 2014).

For GPC integration within the MG system, we focus only on secondary and tertiary control. The former control considers that the EM supervises the MG system by gathering the required data from its entities, mainly RES, batteries, and loads. It mainly manages the energy for both grid-connected and islanded modes with the reliable and secure operation. Accordingly, the controllable units of the studied MG system, in both modes, are modeled by a state-space equation, described in equation (5.30), where $x(t)$ is the system state, $u(t)$ is the vector of manipulated variables, $y(t)$ is the output vector, and $A, B, C$ are respectively the system matrix, the control matrix, and output matrix.

$$ \begin{cases} x(t+1) = Ax(t) + Bu(t) \\ y(t) = Cx(t) \end{cases} \qquad (5.30) $$

In the secondary layer, we have incorporated the GPC within the EM in order to generate suitable control actions for efficient power D/R balance. More precisely, the batteries SoC is controlled by the GPC strategy according to the variability of predicted power production, power consumption, and electricity cost. In fact, the power generated by the RESs and the power consumption are considered as disturbances sources for the MG system during its operation. Therefore, batteries SoC could be modeled by a state-space equation while the variability of these controllable parameters is considered as a result of the disturbances variation described as follows:

$$ P_{bat} = \begin{cases} P_{RES} - P_{load} & ; \text{ if } 0 \le P_{RES} \text{ and } SoC_{min} < SoC \le SoC_{max} \text{ (Charge)} \\ P_{load} & ; \text{ if } P_{RES} = 0 \text{ and } SoC_{min} < SoC \text{ (Discharge)} \end{cases} \qquad (5.31) $$
where $P_{bat}$ is the power generated or extracted from the battery, $P_{RES}$ is the power generated by RES, $P_{load}$ is the load demand, $SoC_{min}$ is the minimum batteries SoC (to avoid a deep discharge), and $SoC_{max}$ is the SoC when the batteries are fully-charged.

Generally, the controller cannot manipulate the disturbances of the system. Hence, in our GPC model, the RES power generation and the load consumption are represented as measured system disturbances. These disturbances can be computed using actual measured power production/consumption, which are in turn affected by external disturbances (e.g., weather conditions, occupant's activities). The deployed IoT/Big data platform, as stated above, could handle this task by forecasting these disturbance parameters (i.e., RES, load power), and consequently, minimizing the GPC prediction errors (Elmouatamid et al., 2019b; Elmouatamid et al., 2019c).

In fact, if the disturbances can be measured or predicted, their influence on the system's output can be included in the GPC model. This allows anticipating their effect on the control command. Alike any predictive control model, the GPC can reject disturbances according to the feedback mechanism. In this way, the GPC can inherently include a feed-forward effect. Therefore, the $d(t)$ disturbances' effect is added to the state-space formulation (equation (5.30)) and the equivalent dynamic model is then written in equation (5.32), where $B_d$ is the matrix, which quantifies the effect of the disturbances on the system states, and $d(t) = P_{RES} - P_{load}$ combines the disturbances into one variable.

$$ \begin{cases} x(t + 1) = Ax(t) + Bu(t) + B_d d(t) \\ y(t) = Cx(t) \end{cases} \qquad (5.32) $$

As stated above, the main aim of the GPC is to control the battery charging/discharging power. In fact, the GPC regulates the battery state in order to reach the operating goal (i.e., D/R balance) and to make the right decision: charge, discharge, or battery-at-rest. At a first step, these decisions are made depending on the conditions, which are mentioned in equation (5.31). It is worth noting that for modeling the SoC dynamics, the disturbances could be indirectly integrated into the control variables. More precisely, the future values $SoC(t + 1)$ can be calculated by accumulating the actual $SoC(t)$ and the battery C/D current, as described in equation (5.13).

Alike the secondary control, which manages the energy for both grid-connected and islanded modes with reliable and secure operation, the tertiary control tackles all issues related to the interconnection between the MG system and the utility grid. It mainly adjusts the power
setpoint in order to manage efficiently the power flows by having the possibility to interconnect multiple MG systems. This control layer is mainly considered at the same time as a part of the main grid and the MG. Under this control, several constraints could be included as a cost function for the efficient management of MG systems. Examples are the electricity price (i.e. the cost for purchasing electricity from the utility grid), the system's profitability (i.e. daily operation costs of the battery storage system and RESs), and the revenue related to the excess energy, which is injected to the utility grid (i.e., selling energy to the neighboring MG systems).

In this work, the electricity price is considered as a fundamental constraint, which is shared between the secondary and the tertiary control layer. In fact, by interpolating this constraint in both layers, the control actions must be generated according to the electricity price variability. The cost function variability used in our work follows the energy price, as presented by the European Foundation (Grigg et al., 1990). In fact, the following control strategy is adopted. When the electricity price is inexpensive, the control strategy could charge the batteries from the main grid for being used during the morning peak consumption, otherwise, the batteries and RESs could be used to supply the power to the building's loads while the surplus can be injected to the grid. Mainly, when the price is less than a defined threshold value, a simple conditional control strategy could be deployed to balance the power flow by providing the priority to RESs and the utility grid than batteries, otherwise, the batteries and the RESs have the priority to supply the building's loads, as shown in Figure 5.12.

<figure><img src="image_76.png" /><figcaption>Figure 5.12. EM and control strategy</figcaption></figure>
In all cases, the battery can be charged from either RESs or TEG according to the daily electricity price variation. In order to include the above-mentioned constraints into the GPC, we use an incremental model by considering $\Delta u(t) = u(t) - u(t - 1)$ as the control decision variable, and, therefore, the state-space equation could be presented as in equation (5.33), where the new state vector is $z(t) = [x(t).u(t - 1)]^T$ and the matrices $M, N$, and $Q$ are obtained by comparing equations (5.32) and (5.33).

$$ \begin{cases} z(t + 1) = Mz(t) + N \Delta u(t) + N_d d(t) \\ y(t) = Qz(t) \end{cases} \qquad (5.33) $$

In this state-space equation (5.33), the prediction includes the estimated disturbances (i.e. RESs production, load consumption). The GPC original algorithm is extended to include the cases of measurable disturbances and change in the predictor. In fact, by considering a system that operates around a practical setpoint, the single-input single-output of the system plant can be described by equation (5.34), after linearization, as follows:

$$ A(z^{-1})y(t) = z^{-d}B(z^{-1})u(t - 1) + C(z^{-1})\frac{e(t)}{\Delta} \qquad (5.34) $$

where $e(t)$ is a zero mean white noise, $d$ is the dead time of the system, and the polynomials, in the backward shift operator $z^{-1}$, $A$, $B$, and $C$ are presented by:

$$ \begin{aligned} A(z^{-1}) &= 1 + a_1 z^{-1} + a_2 z^{-2} + \dots + a_{na} z^{-na} \\ B(z^{-1}) &= b_0 + b_1 z^{-1} + b_2 z^{-2} + \dots + b_{nb} z^{-nb} \\ C(z^{-1}) &= 1 + c_1 z^{-1} + c_2 z^{-2} + \dots + c_{nc} z^{-nc} \end{aligned} \qquad (5.35) $$

This model is known as a CARMA, in which the disturbances are non-stationary. Therefore, the main objective of predictive control is to predict future control actions $u(t)$, $u(t + 1)$, and $u(t + i)$ in such a way that the future system's output is driven to reach the setpoint. The GPC model consists of applying a sequence of control actions in order to minimize a defined multi-objective cost function. It is worth noting that this vector is generated by an ML algorithm, which is mainly used to forecast the RESs power generation and load consumption (Elmouatamid et al., 2019b; Elmouatamid et al., 2019c). Consequently, the GPC predictor can reject the effect of these disturbances, along the horizon $N$, by providing a feed-forward effect. Within this context, the prediction is generated by considering only the cost function, which is modeled by the electricity price as well as the cost associated with the energy used in order to keep the batteries' SoC at its maximum. Therefore, the constraint defined for the tertiary level control can be written as follows:
$$J = \sum_{i=1}^{N_c} |u(t + j - 1)|_{Q_1}^2 + \sum_{i=1}^{N_c} |\Delta u(t + j - 1)|_{Q_2}^2 + \sum_{i=1}^{N_c} |y(t + j)|_T - y_{ref}(t + j)|_R^2 \quad (5.36)$$

The first term of equation (5.36) represents the cost related to the energy supplied to the building's load by RESs and storage devices. The matrix $Q_1$ is generally diagonal and its values depend on the defined priority, which is set-up to control energy sources, as stated above (Figure 5.12). The second term considers the variability of the electricity price along the prediction horizon $N$. It mainly represents the cost optimization function for the GPC. The third term is responsible for setpoint tracking errors; at each moment, the main aim is to regulate the equality $I_{bat} = I_{RES} - I_{load}$ by regulating the battery current while respecting, as much as possible, the constraint described by equation (5.15). However, keeping the SoC at its maximum is highly desirable in order to avoid high cycles of C/D, which could have a direct impact on batteries' state-of-health. This constraint is, however, not mandatory for the MG system's operations. Therefore, the elements of the matrix $R$ will be smaller than other matrix elements. Accordingly, the optimal solution of equation (5.36) could be obtained by solving a quadratic programming problem, as presented in (Camacho et al., 2013).

It is worth noting that the control strategy decisions are generated for a DC MG bus, but the main grid is, however, an AC power system. Thus, a voltage source inverter is required to convert the DC voltage into AC voltage. This will allow generating efficiently the control actions by the above-mentioned GPC model. The next section focuses on the MG synchronization issue by providing a single-phase power converter model.

## 4.2. Single-phase modeling for MG synchronization

The simulated MG system is connected to the utility grid by a bidirectional interface. The aim is to have a complete scenario in order to study the usefulness of the GPC-based control strategy. However, the converter is one of the power electronic devices, which requires time's latency in the order of tens to hundreds of microseconds in order to operate efficiently (Vazquez et al., 2016). This technical constraint could be avoided using the GPC for predictive control. In fact, in order to compute the predictive output parameters (e.g., voltage, current), a state-space equation is required to generate equivalent duty cycle impulse. As depicted in Figure 5.13, the simulated model is, therefore, represented by a closed-loop configuration of a single-phase MG system. The system is modeled by a DC voltage source and other electronics components, which act as an interface between RESs and the AC utility
grid. Usually, an IGBT is used as a voltage source inverter due to its fast switching speed, which is represented by $V_{sw} = \tau(s)V_{dc}$, where $V_{dc}$ meant for the deployed DC voltage sources, and $\tau(s)$ is the duty ratio, which is controlled by the GPC model.

<figure><img src="image_77.png" /><figcaption>Figure 5.13. Single-phase MG system</figcaption></figure>

The main objective of this system's model is to convert the DC power generated by RESs to AC power while controlling the active and reactive power in order to have an equal power of both DC and AC sides. In fact, the voltage through the inductor of the single-phase MG is described by equation (5.37.a) (see Figure 5.13).

$$V_L = L \frac{dI_L}{dt} \qquad (5.37)$$

By considering $V_{sw}$ as the switching voltage, the equation can be written as follows:

$$\frac{dI_L}{dt} = \frac{V_L}{L} = \frac{V_{sw} - V_g}{L} \qquad (5.37)$$

where, $V_g$ is the voltage through the capacitor, which acts as an MG voltage, and $I_L$ is the current across the inductor. By deploying the Laplace Transform, we obtain:

$$I_L(s) = \frac{V_L(s)}{sL} = \frac{V_{sw}(s) - V_g(s)}{sL} \qquad (5.38)$$

Moreover, the grid voltage of the single-phase is written as: $C \frac{dV_g}{dt} = I_c$, where $I_c$ is the current across the capacitor. So, we obtain the following equations:
$$ \frac{dV_g}{dt} = \frac{1}{c} I_c \qquad (5.39) $$

The system state-space equation for a linear time invariant is:

$$ \left\{ \begin{aligned} \frac{dx(t)}{dt} &= Ax(t) + Bu(t) \\ y(t) &= Cx(t) + Du(t) \end{aligned} \right. \qquad (5.40) $$

From equations (5.37) and (5.39), we obtain respectively the system state matrix, the input variable, and the disturbances matrix: $x = [\begin{matrix} I_L \\ V_g \end{matrix}]$, $u = [V_{sw}]$, and $d = I_g$. The duplication of this presentation with equation (5.40), we obtain equation (5.41) as follows, where, $y = V_g = [0 \quad 1] [\begin{matrix} I_L \\ V_g \end{matrix}]$ represents the output of the system.

$$ \frac{d}{dt} \begin{bmatrix} I_L \\ V_g \end{bmatrix} = \begin{bmatrix} 0 & -\frac{1}{L} \\ \frac{1}{c} & 0 \end{bmatrix} \begin{bmatrix} I_L \\ V_g \end{bmatrix} + \begin{bmatrix} I_L \\ 0 \end{bmatrix} V_{sw} + \begin{bmatrix} 0 \\ -\frac{1}{c} \end{bmatrix} I_g \qquad (5.41) $$

Generally, the GPC-based controller computes, for each sampling time, a sequence of actions that minimize the defined cost function. Only the first action is applied to the controllable system by solving the open-loop optimal control problem. This process is repeated, at every sampling time horizon, for remaining actions. In our case, the GPC strategy is applied to the current's control of a power converter, as described in the block diagram of Figure 5.13. For instance, when the predictive time horizon is 1, the optimal control action $S(t_k)$, calculated at $t_{k-1}$, is applied to the converter. The measured current $i_k$ and voltage $V_{dc}$ are used by the reference design model in order to generate the reference current $i_{k+1}^*$ and voltage $V_{k+1}^*$. The predictive model allows then computing the predicted current $\hat{i}_{k+1}^*$ and voltage $\tilde{v}_{k+1}^*$. Furthermore, the defined references and the predicted current and voltage values are used to improve the cost function, and consequently generating the optimal control action $S(t_{k+1})$ for being applied at $t_{k+1}$. However, the main problem, which could face this predictive approach, is its deployment in actual inverters for real-time control. This is due mainly to the considerable processing time delay, which is required to generate predictive values. This delay must be considered in the design of the power controller, and consequently, the delay compensation is a practical method that is used to solve such problem (Cortes et al., 2011). Within this context, we consider a single-phase system, which is interfaced with the utility grid, as depicted in Figure 5.13. Therefore, the predicted current vector $\hat{i}_{k+1}^*$ is calculated, during a sampling time $T_s$, by a discrete-time model, which is a function of the
measured currents $i_k$, the inverter voltage $V_{gk}$, and the electromotive force $\tilde{e}(k)$. This current vector is described as follows:

$$ \hat{i}_{k+1}^* = \left(1 - \frac{RT_s}{L}\right) i_k + \frac{T_s}{L} (V_{gk} - \tilde{e}(k)) \quad (5.42) $$

Moreover, as stated in (Larrinaga et al., 2007; Cortes et al., 2011), the three-phase is presented by seven different voltage vectors. To simplify the presentation, the system is represented by three values of $\beta$ in order to have only three possible trajectories for $i_\beta$, in particular for a single-phase system. Figure 5.14 highlights the problem related to the processing delay, especially for ideal and practical cases.

<figure><img src="image_78.png" /><figcaption>Figure 5.14. Predictive control operation, a) Ideal case: calculation time is negligible, b) Practical case: calculation time is significant</figcaption></figure>

In Figure 5.14, the red curve represents the predicted current, as mentioned in equation (5.42), the green curve is the actual current, which is obtained by minimizing the cost function, and the black line is the considered current reference. Depending on the processing speed and the sampling frequency, the time is significant between the parameters’ measurement and the application time (including the time for prediction) of the new control action. For an ideal case, the processing time, spent by the microcontroller, is insignificant and the predictive control model operates as shown in Figure 5.14.a. In fact, at the present time $t_k$, the current is measured and the optimal action is immediately calculated, consequently, the control action, which minimizes the error at the time $t_{k+1}$, is generated and applied at time $t_k$. For that, the output reaches the reference current correctly on time $t_{k+1}$. Practically, the calculation time is significant compared to a given sampling time of the
model. As a result, a delay is created between the measurement time and the application of the predicted control action. Figure 5.14.b shows that during the time $T_s$ (between $t_k$ and $t_{k+1}$) the previous state continues to control the system, accordingly, the voltage vector, which is selected at time $t_k$, continues to be applied after $t_{k+1}$. In this way, the next action is selected considering the measurement in $t_{k+1}$ and it will be applied near to $t_{k+2}$. This makes the current oscillate around the reference, which then increases the “current ripple”.

As a solution to this problem, the delay compensation method for the predictive control is proposed in order to take into account the calculation time. In fact, the calculated control action, at time $t_k$, is applied at the sampling time $t_{k+2}$, as shown in Figure 5.15. The measured current at $t_k$ is used as the starting point for the next switching state and the predicted current for the delay compensation is calculated by equation (5.43), where $\hat{i}_{k+1}^*$ is the previous prediction of the current, and $V_{g(k+1)}$ presents the actuation to be evaluated.

$$ \hat{i}_{k+2}^* = \left(1 - \frac{RT_s}{L}\right) \hat{i}_{k+1}^* + \frac{T_s}{L} (V_{g(k+1)} - \tilde{e}(k+1)) \quad (5.43) $$

Accordingly, the cost function uses the predicted current $\hat{i}_{k+2}^*$ in order to calculate, at the next sampling time, the switching state. This single-phase modeling is simulated in order to synchronize the MG system with the electrical grid, while the surplus of RESs power generation is injected through a power converter controlled by the GPC model. The obtained results are reported in the next section.

<figure><img src="image_79.png" /><figcaption>Figure 5.15. Predictive control with significant calculation time: operation of delay compensation method</figcaption></figure>
**5. Results and performances evaluation**

The MG system is composed, as already described, of RESs and batteries in order to supply clean energy to the building's load. It is also connected to the utility grid and could operate in either connected or standalone modes. More precisely, two RESs have been considered, solar and wind. In fact, PV panels and a WT are deployed to generate a maximum power of 1KW and 1.5KW respectively. These RESs generators are connected to a battery storage system in order to supply the building's load with continuous power. A variable behavior of power demand is used to simulate the load consumption presenting two peak-demand periods.

Furthermore, the MG system couples both DC and AC buses. In fact, the power generated from RESs is converted to DC power due to its robustness face to the power quality problems (e.g., reactive power, harmonics). An EM system is deployed using the GPC model in order to generate control actions accordingly (Figure 5.12) while minimizing the predefined cost function. The GPC-based predictive control model is also used to control the power converter in order to ensure the quality of power while converting DC to AC power before being injected into the utility grid.

For performance evaluation, four main scenarios have been considered by conducting a sensitivity analysis of the GPC-based control strategy according to different situations. The first scenario is dedicated to investigating the operational capability of the MG system when coupling different RES and batteries with the developed EM system. In this scenario, we have considered that initially batteries are fully charged, while in the second scenario batteries are initially discharged and the threshold value of the electricity price is already fixed. The third scenario augments the second scenario by a further constraint regarding the electricity price by using a dynamic threshold value according to the peak-demand periods. The fourth scenario simulates the complete behavior of the MG system and the GPC-based control according to the electricity price by favoring the usage of RESs and storage devices while minimizing the usage of the electrical grid. In addition, batteries could be charged from the electric grid, especially when the electricity price is lower. Table 5.2 below summarizes the characteristics of the MG system's entities and initial conditions. It is worth noting that in all scenarios, the battery discharging (resp. charging), as well as the extracted (resp. injected) power from (resp. to) the utility grid, have positive (resp. negative) sign in all experimental results, presented in the rest of this section.
<table><caption>Table 5.2. MG system parameters</caption><thead><tr><td>Description</td><td>Value</td></tr></thead><tbody><tr><td>DC bus voltage</td><td>320V</td></tr><tr><td>AC bus voltage</td><td>240V</td></tr><tr><td>System frequency</td><td>50Hz</td></tr><tr><td>DC link capacitance</td><td>2.2μF</td></tr><tr><td>LC Filter inductance</td><td>0.4μH</td></tr><tr><td>LC Filter capacitance</td><td>6.85μF</td></tr><tr><td>Load capacitance</td><td>100mH</td></tr><tr><td>Load inductance</td><td>1pF</td></tr><tr><td>Battery capacity</td><td>150Ah</td></tr><tr><td>Maximum PV power</td><td>1KW</td></tr><tr><td>Maximum wind power</td><td>1.5KW</td></tr></tbody></table>

## 5.1. EM scenarios using GPC control approach

In the first scenario, a GPC model is integrated to regulate the battery C/D according to the constraints, which are presented by equations (5.31) and (5.29) (i.e., the batteries are initially fully charged). In this scenario, the controller manages the power production/consumption by interacting with the batteries by performing the actions presented in Figure 5.12. In this case, batteries are first used to supply the building's load, especially when the RESs cannot satisfy demand. The operational behavior of the MG system is depicted in Figure 5.16. As shown, around 07:00 AM, the PV panels start to generate the power (green curve), which is accumulated with the batteries' power (blue curve) in order to ensure the power to the load. Around 08:30 AM, the WT starts to generate the power (yellow curve) together with the PV and batteries. At 10:00 AM, the RESs (i.e. PV and WT) generation is becoming higher than the power demand, and the surplus is used to charge the batteries.

<figure><img src="image_80.png" /><figcaption>Figure 5.16. GPC control for autonomous operation mode</figcaption></figure>
It is also shown that the GPC-based model took into consideration the objective function (equation (5.15)) by keeping, as much as possible, the batteries SoC at its maximum. From 10:00 AM to 05:00 PM, batteries power is again accumulated with the power generated from RESs in order to supply the building's load, while around 05:00 PM, the power generated from RESs is almost negligible and, therefore, batteries are the most powerful supplier.

In summary, during this scenario, the MG system is tested in order to show its capability to operate within the variable RESs generation while respecting the abovementioned constraints, which are incorporated within the GPC-based control model. As demonstrated, without considering the electricity price, the MG system is operated in the autonomous mode and the GPC controller manages efficiently the variable production of RESs by interacting with the storage system. In fact, the proposed GPC model could ensure the island mode detection by managing the power dispatching tasks, which are handled by the secondary layer.

As stated above, the second scenario is mainly dedicated to evaluate the MG system's behavior when batteries are initially discharged. Since RESs generations and load demand are considered as measurable system disturbances, and only the electricity price is uncontrollable, the operational behavior MG needs to be adapted, by the GPC-based control, in order to supply the building's load. In this scenario, we consider that the same RESs and loads behaviors are used, but by having the possibility to extract or inject the electricity from or to the grid. The GPC controller is designed to manage the switching between batteries and the grid without controlling the power generated by RESs. As shown in Figure 5.17, RESs are considered generating the maximum power using the MPPT of the first control layer (green curve for PV generation and yellow curve for WT generation). Under this scenario, the electricity price is taken into account as the main constraint for the tertiary control layer (equation (5.36)) for managing the interconnection between the MG system and the utility grid. As defined in equation (5.36), the $Q_1$ matrix elements represent the priority between the RESs, the batteries, and the utility grid for supplying the power to the building's load while minimizing the cost function, which represents the electricity price variability.

As is depicted in Figure 5.17, the consumption (orange curve) is the setpoint willing to reach by the GPC model. The aim is to accumulate the RESs power generation, batteries, and the utility grid while minimizing the cost function, which is embedded in the GPC-based control.
<figure><img src="image_81.png" /><figcaption>Figure 5.17. EM scenarios based on GPC model controller for grid-connected mode and static setpoint</figcaption></figure>

At the starting time, the batteries are discharged and the RESs generation is null, though the controller uses the utility grid for supplying the building's load. As clearly mentioned in Figure 5.17, from 06:30 AM to 10:00 AM, the RESs generation (green curve) is less than the power demand, consequently, and according to the control diagram of Figure 5.12, the power generated by RES is only used to charge the batteries. Therefore, the building's load is completely supplied by the utility grid (black curve). It's worth noting that, the operational behavior needs to be avoided in MG systems, as also indicated in Figure 5.12. More precisely, during this period, the electricity price is higher than the defined threshold value, but the RESs generation is less than the load demand while the batteries are not at the maximum. However, the GPC model could not operate efficiently, since it needs to satisfy firstly the constraint defined for the secondary control layer while using the RESs power generation in order to charge the batteries, keeping their SoC at a maximum level. At 10:00 AM, the RESs generation is higher than the power demand. In this case, the energy excess is managed according to the electricity price variation. In fact, during the following periods, 10:00 AM-11:00 AM, 02:00 PM-03:00 PM, and 04:00 PM-05:00 PM, the electricity price (pink curve) is higher than the threshold value (red curve). Therefore, the surplus is injected into the grid in order to increase the prosumers' profitability by selling the energy at a high price. From 11:00 AM to around 01:00 PM, the electricity price is less than the threshold value; in this case, the surplus is used to charge the batteries instead to inject it into the utility grid. Therefore, the batteries will be charged and could supply the building's load, as shown during the period
from 03:00 PM to around 04:00 PM. They are also used for supplying the load even after 05:00 PM despite that their SoC is not at the minimum. To summarize, in this second scenario, a fixed threshold value (red curve in Figure 5.17) of the electricity price is integrated as a cost function for being minimized by the GPC-based control. In fact, the GPC manages the power between the RESs, the batteries, and the utility grid according to the defined priority as well as the constraints for the secondary and the tertiary layers.

Unlike the second scenario, in the third scenario, a dynamic threshold value is used for the electricity price by considering the peak-demand periods. In fact, the electricity price is an interesting exogenous for both prosumers and the utility grid operators. For instance, it could be used by the grid operators as penalties for the consumers, avoiding then the peak-demand. In fact, the consumers can efficiently manage their consumption by using, for example, programmable machines, which could be controlled by integrating the “Internet of Things” technologies, or by the deployment of intelligent and predictive control strategies. Moreover, in the MG system, the proposed GPC model can locally manage the RESs generation and storage devices. For the studied scenario, the electrical grid is used only during some periods, mainly when the electricity price is inexpensive. Batteries SoC is kept at its maximum for being used during periods with high electricity prices, and consequently, the electricity bill is minimized. Furthermore, the high electricity demand from the grid is minimized avoiding then the generation of peak-demand. As shown in Figure 5.18, at the starting time, the RESs start charging the batteries and the grid generates the power for supplying the building’s load. From 06:00 AM to 08:00 AM, the MG system operates like in the second scenario. However, during the morning peak-demand period (from 08:00 AM to 10:00 AM), the electricity price (pink curve) increases to reach the maximum, although the batteries start to generate the electricity to the load in order to avoid using the utility grid, having the highest price. During the periods (from 10:00 AM to around 02:00 PM), which show the lowest electricity price, the RESs (green curve) supply the power to the load while the surplus is managed in a similar manner as the previous scenario. In the afternoon (from 02:00 PM to 04:00 PM), there is a peak-demand, as shown by the orange curve (Figure 5.18). In this period, the surplus generated by RESs is injected into the grid while the batteries are used to supply the building’s load (especially when RES generation is low), respecting then the electricity price variation and the battery SoC constraints.
<figure><img src="image_82.png" /><figcaption>Figure 5.18. GPC controller for grid-connected mode and dynamic setpoint</figcaption></figure>

In summary, from the results, depicted in Figure 5.18, the deployed GPC model manages the energy flow according to the defined constraints, which related to the secondary layer (equation (5.29)). It also handles efficiently the cost function related to the tertiary layer (equation (5.36)).

The fourth scenario is mainly included to investigate the MG system behavior taking into consideration all constraints defined in equation (5.36). The aim is to maximize supplying the building's load from RESs and batteries, especially when the electricity price is expensive. This priority is selected depending on the elements of the diagonal matrix $Q_1$ presented in equation (5.36). In addition, the action selected by the GPC model during a giving prediction horizon N considers the variability of electricity price, which is presented by the second term of the equation (5.36). Thus, the sources selected to generate the electricity to the loads should be capable to generate the equivalent energy in order to reach the selected setpoint presented in the third term of the equation (5.36), while the setpoint is presented by the electricity consumption variability.

In this scenario, the GPC model for EM is deployed during 24 hours with the main aim is to show the utility of this model in minimizing the electricity bill. Two cases are considered in order to make a comparative study regarding the electricity cost. For the first case (Case 1), as described in Figure 5.19.a, we have considered a dynamic threshold value for the electricity price, in a similar way as the third scenario. In the second case (Case 2), as depicted in Figure
5.19.b, we consider that the EM system can use the electrical grid to charge the batteries, mainly when the electricity price is inexpensive.

As already known, batteries are used during the night when the RESs power is unavailable, especially for the PV panels. As shown in Figure 5.19.a, around 05:00 PM the RESs generation becoming insignificant (green curve for PV power, and yellow curve for the wind power). Consequently, the batteries start generating the power (blue curve) to the loads (orange curve). When the batteries are used, their energy is accumulated with the WT in order to satisfy the requested power. However, at 08:00 PM, the batteries’ SoC reached the minimum threshold value (to avoid a deep-discharging) and the WT cannot satisfy alone the energy demand. In this case, the utility grid is used to supply the electricity to the building’s loads, while the power, which is generated by the WT, charges the batteries, from 08:00 PM to around 02:00 AM. During the rest of the night, the batteries are not fully charged, and, therefore, the load is supplied by the utility grid while the batteries remain at rest. In the morning, starting from 06:00 AM to 12:00 AM, the RESs generation is less than the load’s demand. In this period, as shown in Figure 5.19.a, the power generated by the RESs is entirely stored in the batteries, while the building’s load is supplied by the utility grid. However, from 12:00 AM to 04:00 PM, the RESs generation is higher than the building’s load demand. During this period, and because the electricity price is low, the surplus is then used to charge the batteries. From 04:00 PM to 05:00 PM, the surplus is, however, injected into the utility grid. The aim is to profit from the high electricity price by selling it, and then reducing the electricity bill for consumers.

Regarding the second case, as presented in Figure 5.19.b, we consider that the batteries can be charged at night from the utility grid, especially when the electricity price is lower. The system operates like in case 2. Though, at 02:00 AM, the utility grid charges the batteries because the electricity price is low and the batteries SoC should be kept at its maximum for being used during the morning in order to avoid the peak-demand. Unlike the first case, the building’s load is supplied, during this peak-demand, only by both the batteries and RESs, without using the utility grid.

To summarize, the abovementioned scenarios focused on the performance evaluation of the GPC-based control for EM in MG systems. We put more emphasis on the operation behavior of the considered MG system following a cost function and the system’s constraints. The next sub-section will focus on the benefit of the GPC-based control of the electricity price.
<figure><img src="image_83.png" /><figcaption>Figure 5.19. EM scenarios based on GPC model, a) Case 1: without battery-grid interaction, b) Case 2: with battery-grid interaction</figcaption></figure>

## 5.2. The benefit of GPC model on the electricity price

In this section, the profit of electricity price is computed for the fourth scenario and in both cases (1&2, Figure 5.19), since they represent the entire system's operations. In this study, the kilowatt-hour is calculated for the power, which extracted or injected into the utility grid, as well as the power used to charge or discharge the batteries. It's worth noting that the RESs generate the maximum power at each moment without limiting the power by the LPPT
algorithms. In the studied scenarios, the possibility to charge the battery from the grid was integrated as an important element in the proposed EM strategy for the MG system.

<table><caption>Table 5.3. Electricity price benefit for case 1</caption><thead><tr><th rowspan="2">Time</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost exchange</th></tr></thead><tbody><tr><td>06h-07h</td><td>0.58</td><td>-0.02</td><td>0.41</td><td>0.24</td></tr><tr><td>07h-08h</td><td>0.56</td><td>-0.19</td><td>0.50</td><td>0.28</td></tr><tr><td>08h-09h</td><td>0.6</td><td>-0.44</td><td>0.98</td><td>0.59</td></tr><tr><td>09h-10h</td><td>0.72</td><td>-0.69</td><td>1.00</td><td>0.73</td></tr><tr><td>10h-11h</td><td>0.70</td><td>-1.05</td><td>1.48</td><td>1.05</td></tr><tr><td>11h-12h</td><td>0.57</td><td>-1.35</td><td>1.48</td><td>0.84</td></tr><tr><td>12h-13h</td><td>0.45</td><td>-1.13</td><td>0.54</td><td>0.25</td></tr><tr><td>13h-14h</td><td>0.33</td><td>-0.46</td><td>0</td><td>0</td></tr><tr><td>14h-15h</td><td>0.28</td><td>-0.67</td><td>0</td><td>0</td></tr><tr><td>15h-16h</td><td>0.43</td><td>-0.47</td><td>0</td><td>0</td></tr><tr><td>16h-17h</td><td>0.63</td><td>-0.04</td><td>-0.28</td><td>-0.18</td></tr><tr><td>17h-18h</td><td>0.66</td><td>-0.65</td><td>0</td><td>0</td></tr><tr><td>18h-19h</td><td>0.62</td><td>-1.42</td><td>0</td><td>0</td></tr><tr><td>19h-20h</td><td>0.59</td><td>-1.17</td><td>0</td><td>0</td></tr><tr><td>20h-21h</td><td>0.58</td><td>-0.49</td><td>1.48</td><td>0.85</td></tr><tr><td>21h-22h</td><td>0.58</td><td>-0.45</td><td>1.48</td><td>0.85</td></tr><tr><td>22h-23h</td><td>0.68</td><td>-0.47</td><td>1.22</td><td>0.83</td></tr><tr><td>23h-00h</td><td>0.74</td><td>-0.51</td><td>1.22</td><td>0.90</td></tr><tr><td>00h-01h</td><td>0.61</td><td>-0.35</td><td>0.99</td><td>0.59</td></tr><tr><td>01h-02h</td><td>0.49</td><td>-0.05</td><td>0.98</td><td>0.48</td></tr><tr><td>02h-03h</td><td>0.37</td><td>-0.02</td><td>0.47</td><td>0.17</td></tr><tr><td>03h-04h</td><td>0.27</td><td>-0.02</td><td>0.47</td><td>0.12</td></tr><tr><td>04h-05h</td><td>0.29</td><td>-0.02</td><td>0.47</td><td>0.13</td></tr><tr><td>05h-06h</td><td>0.48</td><td>-0.02</td><td>0.47</td><td>0.22</td></tr><tr><td>Total</td><td>--</td><td>-5.71 KWh</td><td>15.36 KWh</td><td>8.97 €</td></tr></tbody></table>

However, a high cycle of the batteries' C/D could play a major role in decreasing the batteries' state-of-health. The GPC-based control manages the power flow in order to keep, as much as possible, the battery SoC at its maximum (equation (5.28)). This avoids a high cycle of C/D and a deep-discharge of batteries, which causes the degradation of their state-of-health. Regarding case 1, batteries can only be charged from RESs production. They are mainly used to compensate the power generated for supplying the building's load according to the constraints, which are set in the deployed GPC model. As presented in Tables 5.3 & 5.4, the cost average, the battery power average, and the grid power average are calculated for each hour during the system's operation period. In fact, the negative average power represents the equivalent power, which is used to charge the batteries, while the positive value is the equivalent power, which is generated from the batteries in order to supply the electricity to the load. By comparing this factor in both cases, the batteries have a total battery power-average equal to "-5.71KWh" and "-0.0042KWh" respectively for cases 1 and 2.
<table><caption>Table 5.4. Electricity price benefit for case 2</caption><thead><tr><th rowspan="2">Time</th><th colspan="2">Battery</th><th colspan="2">Grid</th></tr><tr><th>Cost Average (€)</th><th>Power Average (KWh)</th><th>Power Average (KWh)</th><th>Equivalent Cost exchange</th></tr></thead><tbody><tr><td>06h-07h</td><td>0.58</td><td>0.45</td><td>0</td><td>0</td></tr><tr><td>07h-08h</td><td>0.56</td><td>0.38</td><td>0</td><td>0</td></tr><tr><td>08h-09h</td><td>0.6</td><td>0.60</td><td>0</td><td>0</td></tr><tr><td>09h-10h</td><td>0.72</td><td>0.41</td><td>0</td><td>0</td></tr><tr><td>10h-11h</td><td>0.70</td><td>0.50</td><td>0</td><td>0</td></tr><tr><td>11h-12h</td><td>0.57</td><td>0.25</td><td>0</td><td>0</td></tr><tr><td>12h-13h</td><td>0.45</td><td>-0.20</td><td>0</td><td>0</td></tr><tr><td>13h-14h</td><td>0.33</td><td>-0.36</td><td>0</td><td>0</td></tr><tr><td>14h-15h</td><td>0.28</td><td>-0.40</td><td>0</td><td>0</td></tr><tr><td>15h-16h</td><td>0.43</td><td>-0.37</td><td>0</td><td>0</td></tr><tr><td>16h-17h</td><td>0.63</td><td>-0.01</td><td>-0.26</td><td>-0.16</td></tr><tr><td>17h-18h</td><td>0.66</td><td>0.65</td><td>0</td><td>0</td></tr><tr><td>18h-19h</td><td>0.62</td><td>1.42</td><td>0</td><td>0</td></tr><tr><td>19h-20h</td><td>0.59</td><td>1.17</td><td>0</td><td>0</td></tr><tr><td>20h-21h</td><td>0.58</td><td>-0.49</td><td>1.51</td><td>0.87</td></tr><tr><td>21h-22h</td><td>0.58</td><td>-0.45</td><td>1.51</td><td>0.87</td></tr><tr><td>22h-23h</td><td>0.68</td><td>-0.48</td><td>1.25</td><td>0.85</td></tr><tr><td>23h-00h</td><td>0.74</td><td>-0.51</td><td>1.25</td><td>0.92</td></tr><tr><td>00h-01h</td><td>0.61</td><td>-0.35</td><td>1.01</td><td>0.61</td></tr><tr><td>01h-02h</td><td>0.49</td><td>-0.05</td><td>1.01</td><td>0.49</td></tr><tr><td>02h-03h</td><td>0.37</td><td>-1.04</td><td>1.54</td><td>0.57</td></tr><tr><td>03h-04h</td><td>0.27</td><td>-1.02</td><td>1.51</td><td>0.40</td></tr><tr><td>04h-05h</td><td>0.29</td><td>-0.10</td><td>0.59</td><td>0.17</td></tr><tr><td>05h-06h</td><td>0.48</td><td>-0.004</td><td>0.50</td><td>0.24</td></tr><tr><td>Total</td><td>--</td><td>-0.0042 KWh</td><td>11.42 KWh</td><td>5.85 €</td></tr></tbody></table>

For case 1, this is due to the high usage of the utility grid, and consequently, the batteries receive maximum power from the RESs without considering the electricity price variation, especially during the day. However, in case 2, the batteries can be charged from the electrical grid, mainly when the electricity price is inexpensive. In fact, the negative average of the power grid represents the equivalent power, which is injected into the grid from RESs, while the positive average is equivalent to the power, which is extracted from the grid in order to satisfy the load demand. As depicted in Table 5.3, in case 1, “15.36 KWh” of energy is used from the grid, representing an equivalent of “8.97€” for 24 hours, while in case 2, only “11.42KWh” of energy is extracted from the grid, which is equivalent to “5.85€” for the same period.

Therefore, different factors are considered in order to manage the energy flow in the MG system. In order to maximize its profitability, for all studied scenarios, the RESs generate maximum power at each moment. When RESs cannot satisfy the demand, the grid and the batteries' power are efficiently managed in order to avoid the degradation of batteries state-of-health, while minimizing the electricity bill. In summary, the above-mentioned results show
the usefulness of the GPC-based control in minimizing the electricity bill for the consumer by
integrating the electricity price as main an important factor for EM of MG systems. However,
the power quality as well the timely decision, which is provided by the GPC-base control, has
to be assessed. The next sub-section focuses on evaluating and assessing these two important
factors.

**5.3. Power quality for GPC controller**

Computing and processing for providing timely decisions and actions are most important,
especially in systems requiring real-time predictive control. For instance, as stated above, a
delay is created between the measurement time and the application of the predicted control
action. In fact, between two moments (t<sub>k</sub> and t<sub>k+1</sub>), the previous state continues to control the
system, and consequently, the voltage vector, selected at time t<sub>k</sub>, continues to be applied after
t<sub>k+1</sub>. This makes the power oscillates around the reference, and then the “current ripple”
increases. Therefore, by using the GPC controller for the tertiary control layer, the predictor
calculates, for each instant t<sub>k</sub>, the predictions of the dynamic evolution of the process
[y(t + 1), ..., y(t + N)]<sup>T</sup>, throughout the prediction horizon N. This prediction is based on
dynamic parameters, which are measured at this moment, as well as on future control
regulation [u(t), u(t + 1), ..., u(t + N)]<sup>T</sup>, along the prediction horizon N. As depicted in
Figure 5.20, the orange curve represents the output power, which is generated by the inverter
according to GPC-based control, while the blue curve represents the power, which is
generated by the inverter according to a PID controller.

<figure><img src="image_84.png" /><figcaption>Figure 5.20. Power regulation for GPC and PID controller</figcaption></figure>
As shown in Figure 5.20, unlike the PID controller, which takes a few moments to reach the setpoint regulation (1000W of load consumption), the GPC controller generates the future control actions by keeping the system’s output as close as possible to the setpoint. In fact, the GPC controller shows more system’s stability during the switching moments. Moreover, the control strategy decision by the GPC-based control is mainly generated for the secondary and tertiary control layer. In fact, the GPC manages the system for the secondary control layer by taking the right action on batteries C/D according to the detected mode, autonomous, grid-connected. As shown in Figure 5.21, the PID controller takes more time to converge to the desired references, especially during switching moments.

<figure><img src="image_85.png" /><figcaption>Figure 5.21. Power regulation for GPC and PID controller, a) Battery power regulation, b) Grid power exchange</figcaption></figure>
Since the PID is based on a feedback control mechanism (i.e., cannot generate future actions) and the studied constraints cannot be modeled for real-time control, we present only the result when the PID is applied for the grid-connected mode with a static setpoint. Unlike PID, the GPC controller is based on a feed-forward control mechanism, which allows it to generate future actions according to a predefined cost function and constraints. As depicted in Figure 5.21.a, the regulation of batteries C/D decision is more stable at the switching moments and without a significant “current ripple”. Similarly, high switching performances are presented for the interconnection with the electrical grid (Figure 5.21.b). This is due to the delay compensation method, which is used by the GPC-based control. Furthermore, the GPC model gives an exact solution to an approximated optimization problem by calculating the voltage reference to the inverter.

<figure><img src="image_86.png" /><figcaption>Figure 5.22. Current and voltage regulation, a) DC bus voltage, b) DC bus current, c) the current across the filter capacitor</figcaption></figure>
However, this voltage is generated by a PWM or SVM technique. As presented in Figure 5.13, the power circuit of a grid-connected converter is represented by a smoothing inductor. The main objective of the GPC model is to calculate, for the inverter, the reference of the output voltage for each connected source and load or injection of power to the grid. For the controller, the main variables are the DC voltage/current, the grid voltage/current, and the load voltage/current. The inverter should be able to regulate the output depending on the parameter variation of the DC bus. The output of the system is modeled by equation (5.43), in which the output voltage and current are regulated following the references that are generated by the GPC-based control. Figure 5.22 presents the obtained regulation of voltage and current for the deployed power converter depending on the DC voltage variation. Figure 5.22.a, b, and c present respectively the DC voltage, the DC current, and the current across the LC filter capacitor.

The active power filter essentially consists of a voltage source inverter and a DC bus connected to a capacitor while the AC bus is connected to the main grid through an LC filter. Mainly, for each load connected to the AC bus, the converter should be capable to generate suitable current and voltage. For the studied scenarios, the voltage and frequency of the grid are set as 240V and 50Hz respectively. Depending on the deployed loads used for our scenarios, Figure 5.23.a presents the current variation and Figure 5.23.b presents the voltage, which is measured at the output of the inverter.

<figure><img src="image_87.png" /><figcaption>Figure 5.23. a) Load current variation, b) Load voltage variation</figcaption></figure>
The frequency spectrum is presented for the AC bus voltage and current and for the load voltage as shown in Figure 5.24. Depending on the equation (5.40) dynamics, the voltage-source-inverter output is chosen as the control signal and the final switching sequence is generated through a PWM technique. The performance is analyzed for an RLC load, which is deployed for simulation purposes. Thus, the converters must ensure the stability of the energy injected into the utility grid, according to the rules established by the operators (IEEE Standard Association, 2018).

<figure><img src="image_88.png" /><figcaption>Figure 5.24. Frequency spectrum, a) Inverter output current, b) Inverter output voltage, c) Load voltage</figcaption></figure>

It is worth noting that, in power electronics, the state feedback regulators do not guarantee a good performance in terms of rapid recovery and low harmonic distortion of the
output, especially when the system is affected by disturbances and variations in parameters. However, the use of a feed-forward technique improves the transient response and minimizes, even remove harmonic disturbances. Better performance of this type of controllers is achieved, as shown in Figure 5.24. The output tracks the reference voltage and current with good behavior by ensuring the stability of the system's frequency at 50Hz for harmonic loads. Furthermore, the GPC provides an explicit solution for unconstrained predictive control. It is also able to handle the problem of mismatch between the model and the deployed load.

## 6. Conclusions

This chapter introduced an intelligent and predictive control strategy, named MAPCASTE, for EM in MG systems. MPC (Model Predictive Control) and GPC (Generalized Predictive Control) have been investigated in order to carry out the proposed MAPSASTE. This later was deployed and evaluated by assessing its effectiveness for EM in MG systems. In fact, the main aspect of the proposed MAPCASTE approach is to measure, in real-time, the main input control parameters; analyze the data for ML algorithms training, prediction of the future behaviors, forecasting the suitable commands to reach the desired setpoint depending on the predefined constraints and objective functions, and correcting the errors depending on the real measurements. In fact, ML algorithms classifications are presented for power forecasting in MG systems. In addition, an EM system, based on MPC and GPC principles, is developed for being deployed in the secondary and the tertiary control layers. In fact, the secondary layer focused on power regulation and energy D/R balance. An optimization function was defined, for this level. State-space equations are presented for the controllable MG system's entities depending on the constraint, which is defined in the tertiary control layer. Therefore, the tertiary control focused only on power dispatch and economic aspects. Within this context, the electricity cost is used as a constraint to control the batteries C/D. Indeed, the electricity price is integrated as a cost function to be minimized while respecting the defined constraints. The controller manages the power between the RESs, the batteries, and the utility grid depending on the operational constraints of the EM strategy. The powerful of the MAPCASTE for the EM system was shown by minimizing the electricity bill.
# General Conclusions and Perspectives

## Conclusions

In this dissertation, an intelligent and predictive control strategy for EM (energy management) in MG (micro-grid) systems has been developed, deployed, and tested. The aim was to define an appropriate predictive control approach for EM, which allows an optimal control and scheduling operations of hybrid renewable energy sources. In fact, by first studying the environmental and global energy context, the concept of MG systems for buildings is introduced. The need to integrate RESs into the building is studied, by highlighting important problems that need to be tackled for efficient EM. Therefore, a concise state of the art is presented by introducing the main control approaches, which have been proposed for EM in hybrid RESs systems. Principally, this study is carried out in order to define the suitable control approach by identifying the interconnection method and the main components of the studied MG system. Modeling of the different components of the hybrid energy system is realized following a specific problems classification, especially, for MG systems. Moreover, an MG system infrastructure is developed together with a platform for data gathering, monitoring, and processing. We put more emphasis on MG systems as crucial infrastructures for leveraging energy-efficient and smart buildings by developing and deploying a holistic IoT/Big-Data platform in which sensing and actuation tasks are performed according to the actual contextual changes. The developed platform integrates the new information and communication technologies making the buildings more intelligent. It was used for validating the proposed models and results mainly by investigating, i) the efficient connection, integration, and the management of different RES and storage devices, ii) the suitable dimensions for energy production and storage devises, iii) different possible demands/responses and predictive algorithms, iv) context-aware driven control of deployed equipment (e.g., lighting and HVAC systems).

A predictive control strategy is then developed, named MAPCASTE, for measuring, analyzing, predicting, and forecasting actions in order to ensure efficient and optimal operation of MG systems. The control strategy is based on machine-learning algorithms to predict main input parameters, which are used for forecasting suitable actions. The main objective is to connect efficiently the electricity generators and consumers in order to predict the most suitable actions for energy flow management. More precisely, based on energy production and consumption profiles as well as the availability of energy storage systems, the proposed control strategy selects the best suitable energy source for supplying the building's
loads. It manages efficiently the usage of energy storage and utility grid while maximizing RESs power generation. Simulations and experimentations have been conducted and results are presented to validate the proposed predictive control approach by showing its effectiveness for MG systems control, in particular the system's profitability and energy cost minimization.

## Perspectives

Ongoing works focuses on the development of smart converters according to the thesis findings. In fact, the actual commercial inverters offer the possibility to manage the power flows between different power sources, loads, energy storage systems, and utility grid with high performances. However, these inverters are limited generally to a single objective function, which is the satisfaction of the loads demand without considering other operating constraints, like the electricity price and the battery state-of-health. Moreover, the integration of new IoT/Big-data technologies to the actual inverter improved the performance of the system to control and predict the suitable actions for EM and control. Mainly, the integration of machine-learning algorithms is required to analyze the data and to predict the actions for EM in MG systems. In this way, the development of smart inverter enhanced the possibility to integrate multiple objective functions and operating constraints that can be integrated in the EM approaches. Therefore, the deployment of predictive control strategies in real scenarios requires the use of open access power converter. For that, we are deploying our proper power inverter in order to have the ability to conduct real-testing of predictive control strategies with specific constraints and multiple objective functions. Moreover, the development of predictive control strategies improves the actual MG building systems by offering the possibility to interconnect multiple MG systems with the possibility to exchange power. The deployment of smart inverter offers the possibility to create MG networks using IoT/Big-data technologies. In this context, a platform for MG2MG energy and data exchange will be developed based on the predictive control deployed in the smart inverters.

Two ongoing theses have already started, the first one deals with the first perspective by including other constraints and objective functions for being integrated into our developed inverter, while the second thesis will focus on the development of distributed EM for MG2MG.
# Author's Publications

## Journal papers

[1] Elmouatamid, A., Ouladsine, R., Bakhouya, M., El kamoun, N., Zine-Dine, K., & Khaidar, M. (2020). *Review of Control and Energy Management Approaches in Micro-Grid Systems*. In Smart Grids and Microgrids. Energies.

[2] ELMOUATAMID, A. (2020). MAPCAST: *an Adaptive Control Approach using Predictive Analytics for Energy Balance in Micro-Grid Systems*. International Journal of Renewable Energy Research (IJRER), 10(2), 945-954.

[3] Elmouatamid, A., NaitMalek, Y., Bakhouya, M., Ouladsine, R., Elkamoun, N., Zine-Dine, K., & Khaidar, M. (2019). *An energy management platform for micro-grid systems using Internet of Things and Big-data technologies*. Proceedings of the Institution of Mechanical Engineers, Part I: Journal of Systems and Control Engineering, 233(7), 904-917.

[4] Boulmrharj, S., NaitMalek, Y., Elmouatamid, A., Bakhouya, M., Ouladsine, R., Zine-Dine, K., ... & Siniti, M. (2019). *Battery Characterization and Dimensioning Approaches for Micro-Grid Systems*. Energies, 12(7), 1305.

## Chapter books

[5] Elmouatamid, A., NaitMalek, Y., Ouladsine, R., Bakhouya, M., Elkamoun, N., Khaidar, M & Zine-Dine, K. (2020). *A Micro-grid system Infrastructure for Efficient Energy Management in Smart Buildings*. In ATSPES'1 (Advanced Technologies for Solar Photovoltaics Energy Systems), Book Chapters (Springer Book).

## Conference papers

[6] Elmouatamid, A., Alidrissi, Y., Ouladsine, R., Bakhouya, M., El kamoun, N., M., Zine-Dine, K., & Khaidar, M. (2021). *Towards an IoT/Big-Data Platform for Data Measurements, Collection and Processing in Micro-grid Systems*. In The 2021 International Conference on Digital Technologies and Applications (ICDTA'21). Springer series “Lecture Notes in Networks and Systems”.

[7] Elmouatamid, A., Ouladsine, R., Bakhouya, M., El Kamoun, N., Zine-Dine, K., & Khaidar, M. (2019, September). *A Model Predictive Control Approach for Energy Management in Micro-Grid Systems*. In 2019 International Conference on Smart Energy Systems and Technologies (SEST) (pp. 1-6). IEEE.

[8] Elmouatamid, A., Ouladsine, R., Bakhouya, M., Zine-Dine, K., & Khaidar, M. (2019, October). *A Control Strategy Based on Power Forecasting for Micro-Grid Systems*. In 2019 IEEE International Smart Cities Conference (ISC2) (pp. 735-740). IEEE.

[9] Elmouatamid, A., Bakhouya, M., Ouladsine, R., Zine-Dine, K., Khaidar, M., & Abid, R. (2018, December). *Deployment and Experimental Evaluation of Micro-Grid Systems*. In 2018 6th International Renewable and Sustainable Energy Conference (IRSEC) (pp. 1-6). IEEE.
[10] **Elmouatamid**, A., NaitMalek, Y., Ouladsine, R., Bakhouya, M., Elkamoun, N., Zine-Dine, K., ... & Abid, R. (2018, April). *Towards a Demand/Response Control Approach for Micro-grid Systems*. In 2018 5th International Conference on Control, Decision and Information Technologies (CoDIT) (pp. 984-988). IEEE.

[11] **El Mouatamid**, A., Ouladsine, R., Bakhouya, M., Felix, V., Elkamoun, N., Zine-Dine, K., ... & Abid, R. (2017, December). *Modeling and performance evaluation of photovoltaic systems*. In 2017 International Renewable and Sustainable Energy Conference (IRSEC) (pp. 1-7). IEEE.

[12] Elibrahimi, M., **Elmouatamid**, A., Bakhouya, M., Feddi, K., & Ouladsine, R. (2018, December). *Performance Evaluation of Fixed and Sun Tracking Photovoltaic Systems*. In 2018 6th International Renewable and Sustainable Energy Conference (IRSEC) (pp. 1-6). IEEE.

[13] Boulmrharj, S., NaitMalek, Y., **El Mouatamid**, A., Ouladsine, R., Bakhouya, M., Ouldmoussa, M., ... & Abid, R. (2018, September). *Towards a battery characterization methodology for performance evaluation of micro-grid systems*. In 2018 International Conference on Smart Energy Systems and Technologies (SEST) (pp. 1-6). IEEE.

[14] Boulmrharj, S., NaitMalek, Y., **Elmouatamid**, A., Bakhouya, M., Ouladsine, R., Zine-Dine, K., ... & Abid, R. (2018). *Approach for dimensioning stand-alone photovoltaic systems*. Energy Procedia, 153, 56-61.

[15] Bakhouya, M., NaitMalek, Y., **Elmouatamid**, A., Lachhab, F., Berouine, A., Boulmrharj, S., ... & Elkamoune, N. (2017, October). *Towards a context-driven platform using IoT and big data technologies for energy efficient buildings*. In 2017 3rd International Conference of Cloud Computing Technologies and Applications (CloudTech) (pp. 1-5). IEEE.

## Patent

[16] A. **Elmouatamid**, Y. NaitMalek, S. Boulmrharj, M. Bakhouya, R. Ouladsine, M. Elkamoun, K. Zine-dine, M. Khaidar. *Procédé de monitoring, estimation, prédiction et contrôle en temps réel des systèmes multi-sources*. Number MA43611. November 2018.
REFERENCES

Abbes, D. (2012). Contribution au dimensionnement et à l'optimisation des systèmes hybrides éoliens-photovoltaïques avec batteries pour l'habitat résidentiel autonome. Ecole Nationale Supérieure d'Ingénieurs-Poitiers.

Abd-El Baset, D., Rezk, H., & Hamada, M. (2020, March). Fuzzy Logic Control Based Energy Management Strategy for Renewable Energy System. In 2020 International Youth Conference on Radio Electronics, Electrical and Power Engineering (REEPE) (pp. 1-5). IEEE.

Aftab, M. A., Hussain, S. S., & Ali, I. (2019). ICT Technologies, Standards and Protocols for Active Distribution Network Automation and Management. In Advanced Communication and Control Methods for Future Smartgrids. IntechOpen.

Aghajani, G. R., Shayanfar, H. A., & Shayeghi, H. (2015). Presenting a multi-objective generation scheduling model for pricing demand response rate in micro-grid energy management. Energy Conversion and Management, 106, 308-321.

Aghdam, F. H., Salehi, J., & Ghaemi, S. (2018). Contingency based energy management of multi-microgrid based distribution network. Sustainable Cities and Society, 41, 265-274.

Agnoloetto, E. J., Neves, R. V., Bastos, R. F., Machado, R. Q., & Oliveira, V. A. (2016, June). Fuzzy secondary controller applied to autonomous operated AC microgrid. In 2016 European Control Conference (ECC) (pp. 1788-1793). IEEE.

Alavi, S. A., Ahmadian, A., & Aliakbar-Golkar, M. (2015). Optimal probabilistic energy management in a typical micro-grid based-on robust optimization and point estimate method. Energy Conversion and Management, 95, 314-325.

ALFARES, H. K., and NAZEERUDDIN, M., 1999, Regression-based methodology for daily peak load forecasting. Proceedings of the 2nd International Conference on Operations and Quantitative Management, Ahmedabad, India, 3±6 January, pp. 468-471.

Al-Ghussain, L., Samu, R., Taylan, O., & Fahrioglu, M. (2020). Sizing renewable energy systems with energy storage systems in microgrids for maximum cost-efficient utilization of renewable energy resources. Sustainable Cities and Society, 55, 102059.

Ali, A. S. (Ed.). (2013). Smart grids: opportunities, developments, and trends. Springer Science & Business Media.

Alsema, E. (2012). Energy payback time and CO2 emissions of PV systems. In Practical Handbook of Photovoltaics (pp. 1097-1117). Academic Press.

An, L. N., & Quoc-Tuan, T. (2015, July). Optimal energy management for grid connected microgrid by using dynamic programming method. In 2015 IEEE Power & Energy Society General Meeting (pp. 1-5). IEEE.

Anvari-Moghaddam, A., Rahimi-Kian, A., Mirian, M. S., & Guerrero, J. M. (2017). A multi-agent based energy management solution for integrated buildings and microgrid system. Applied energy, 203, 41-56.

Arcos-Aviles, D., Sotomayor, D., Proaño, J. L., Guinjoan, F., Marietta, M. P., Pascual, J., ... & Sanchis, P. (2017, June). Fuzzy energy management strategy based on microgrid energy rate-of-change
applied to an electro-thermal residential microgrid. In 2017 IEEE 26th international symposium on industrial electronics (ISIE) (pp. 99-105). IEEE.

Aristizábal, A. J., Habib, A., Ospina, D., Castaneda, M., Zapata, S., & Banguero, E. (2019, July). RenPower: Software for sizing renewable energy microgrids for academic teaching. In AIP Conference Proceedings (Vol. 2123, No. 1, p. 020011). AIP Publishing LLC.

Asaad, M., Ahmad, F., Alam, M. S., & Sarfraz, M. (2019). Smart grid and Indian experience: A review. *Resources Policy*, 101499.

Augustine, S., Mishra, M. K., & Lakshminarasamma, N. (2014). Adaptive droop control strategy for load sharing and circulating current minimization in low-voltage standalone DC microgrid. *IEEE Transactions on Sustainable Energy*, 6(1), 132-141.

Bakhouya, M., NaitMalek, Y., Elmouatamid, A., Lachhab, F., Berouine, A., Boulmrharj, S., ... & Elkamoune, N. (2017, October). Towards a context-driven platform using IoT and big data technologies for energy efficient buildings. In 2017 3rd International Conference of Cloud Computing Technologies and Applications (CloudTech) (pp. 1-5). IEEE.

Barakat, M., Tala-Ighil, B., Chaoui, H., Gualous, H., & Hissel, D. (2020). Energy Management of a Hybrid Tidal Turbine-Hydrogen Micro-Grid: Losses Minimization Strategy. *Fuel Cells*.

Basso, T. (2014). IEEE 1547 and 2030 standards for distributed energy resources interconnection and interoperability with the electricity grid (No. NREL/TP-5D00-63157). National Renewable Energy Lab.(NREL), Golden, CO (United States).

Basu, K., Guillame-Bert, M., Joumaa, H., Ploix, S., & Crowley, J. (2011, December). Predicting home service demands from appliance usage data. In International Conference on Information and Communication Technologies and Applications ICTA.

Bellido, M., Rosa, L., Pereira, M., Falcao, D., Ribeiro, S., 2018. Barriers, challenges and opportunities for microgrid implementation: the case of Federal University of Rio de Janeiro. *J. Cleaner Prod.* 188, 203_216.

Berouine, A., Akssas, E., Naitmalek, Y., Lachhab, F., Bakhouya, M., Ouladsine, R., & Essaaidi, M. (2019a, April). A Fuzzy Logic-Based Approach for HVAC Systems Control. In 2019 6th International Conference on Control, Decision and Information Technologies (CoDIT) (pp. 1510-1515). IEEE.

Berouine, A., Ouladsine, R., Bakhouya, et al. (2019b). A Model Predictive Approach for Ventilation System Control in Energy Efficient Buildings. In 2019 4th World Conference on Complex Systems (WCCS) IEEE.

Birleanu, F. G., & Bizon, N. (2020). Control and Protection of the Smart Microgrids Using Internet of Things: Technologies, Architecture and Applications. In Microgrid Architectures, Control and Protection Methods (pp. 749-770). Springer, Cham.

Bordons, C., & Montero, C. (2015). Basic principles of MPC for power converters: Bridging the gap between theory and practice. *IEEE Industrial Electronics Magazine*, 9(3), 31-43.

Bordons, C., Teno, G., Marquez, J. J., & Ridao, M. A. (2019, September). Effect of the Integration of Disturbances Prediction in Energy Management Systems for Microgrids. In 2019 International Conference on Smart Energy Systems and Technologies (SEST) (pp. 1-6). IEEE.
Boulmrharj, S., NaitMalek, Y., El Mouatamid, A., Ouladsine, R., Bakhouya, M., Ouldmoussa, M., ... & Abid, R. (2018, September). Towards a battery characterization methodology for performance evaluation of micro-grid systems. In 2018 International Conference on Smart Energy Systems and Technologies (SEST) (pp. 1-6). IEEE.

Box GEP, Jenkins GM, Reinsel GC. Time series analysis: forecasting and control. 4th ed. Wiley; 2008.

Bozchalui, M. C., Hashmi, S. A., Hassen, H., Canizares, C. A., & Bhattacharya, K. (2012). Optimal operation of residential energy hubs in smart grids. IEEE Transactions on Smart Grid, 3(4), 1755-1766.

Breiman, L., 2001. Random forests. Machine Learn. 45 (1), 5–32.

Bridier, L. (2016). Modélisation et optimisation d'un système de stockage couplé à une production électrique renouvelable intermittente (Doctoral dissertation).

BUILD UP, 2020. The European Portal for Energy Efficiency in Buildings. Available at: https://www.buildup.eu/en/practices/publications/re-thinking-2050-100-renewable-energy-vision-european-union (accessed 10 May 2020).

Bukar, A. L., Tan, C. W., Yiew, L. K., Ayop, R., & Tan, W. S. (2020). A rule-based energy management scheme for long-term optimal capacity planning of grid-independent microgrid optimized by multi-objective grasshopper optimization algorithm. Energy Conversion and Management, 221, 113161.

Buyak, N. A., Deshko, V. I., & Sukhodub, I. O. (2017). Buildings energy use and human thermal comfort according to energy and exergy approach. Energy and buildings, 146, 172-181.

Camacho, E. F., & Alba, C. B. (2013). Model predictive control. Springer Science & Business Media.

Cannata, N., Cellura, M., Longo, S., Montana, F., Sanseverino, E. R., Luu, Q. L., & Nguyen, N. Q. (2019, June). Multi-Objective Optimization of Urban Microgrid Energy Supply According to Economic and Environmental Criteria. In 2019 IEEE Milan PowerTech (pp. 1-6). IEEE.

Cao, X., Dai, X., & Liu, J. (2016). Building energy-consumption status worldwide and the state-of-the-art technologies for zero-energy buildings during the past decade. Energy and buildings, 128, 198-213.

Castilla, M., Bordons, C., & Visioli, A. (2020). Event-based state-space model predictive control of a renewable hydrogen-based microgrid for office power demand profiles. Journal of Power Sources, 450, 227670.

Castro, M. A. L. (2020). Urban microgrids: benefits, challenges, and business models. In The Regulation and Policy of Latin American Energy Transitions (pp. 153-172). Elsevier.

Celik, B., Roche, R., Suryanarayanan, S., Bouquain, D., & Miraoui, A. (2017). Electric energy management in residential areas through coordination of multiple smart homes. Renewable and Sustainable Energy Reviews, 80, 260-275.

Chandan, R. S., Kiran, T. S., Swapna, G., & Muni, T. V. (2020). Intelligent Control Strategy for Energy Management System with FC/Battery/SC. JCR, 7(2), 344-348.

Chauhan, R. K., & Chauhan, K. (Eds.). (2019). Distributed Energy Resources in Microgrids: Integration, Challenges and Optimization. Academic Press.
Chen, C., Duan, S., Cai, T., Liu, B., & Hu, G. (2011). Smart energy management system for optimal microgrid economic operation. IET renewable power generation, 5(3), 258-267.

Chen, H., Chen, J., Lu, H., Yan, C., & Liu, Z. (2020). A Modified MPC-based Optimal Strategy of Power Management for Fuel Cell Hybrid Vehicles. IEEE/ASME Transactions on Mechatronics.

Chen, H., Cong, T. N., Yang, W., Tan, C., Li, Y., & Ding, Y. (2009). Progress in electrical energy storage system: A critical review. Progress in natural science, 19(3), 291-312.

Chiang, M., & Zhang, T. (2016). Fog and IoT: An overview of research opportunities. IEEE Internet of Things Journal, 3(6), 854-864.

Consortium for Electric Reliability Technology Solutions (2020), available at: http://certs.lbl.gov (accessed 1 May 2020).

Corchero, C., Cruz-Zambrano, M., & Heredia, F. J. (2014). Optimal energy management for a residential microgrid including a vehicle-to-grid system. IEEE transactions on smart grid, 5(4), 2163-2172.

Correa, P., Rodríguez, J., Rivera, M., Espinoza, J. R., & Kolar, J. W. (2009). Predictive control of an indirect matrix converter. IEEE Transactions on Industrial Electronics, 56(6), 1847-1853.

Cortes, P., Rodriguez, J., Silva, C., & Flores, A. (2011). Delay compensation in model predictive current control of a three-phase inverter. IEEE Transactions on Industrial Electronics, 59(2), 1323-1325.

Cortes, P., Wilson, A., Kouro, S., Rodriguez, J., & Abu-Rub, H. (2010). Model predictive control of multilevel cascaded H-bridge inverters. IEEE Transactions on Industrial Electronics, 57(8), 2691-2699.

Cupelli, M., Monti, A., De Din, E., & Sulligoi, G. (2016, April). Case study of voltage control for MVDC microgrids with constant power loads-Comparison between centralized and decentralized control strategies. In 2016 18th Mediterranean Electrotechnical Conference (MELECON) (pp. 1-6). IEEE.

Dagdougui, H., Ouammi, A., & Sacile, R. (2017). Towards a Concept of Cooperating Power Network for EM and Control of Microgrids. In Microgrid (pp. 231-262). Butterworth-Heinemann.

Dali, M., Belhadj, J., & Roboam, X. (2010). Hybrid solar-wind system with battery storage operating in grid-connected and standalone mode: control and energy management-experimental investigation. Energy, 35(6), 2587-2595.

Dash, V., & Bajpai, P. (2015). Power management control strategy for a stand-alone solar photovoltaic-fuel cell-battery hybrid system. Sustainable Energy Technologies and Assessments, 9, 68-80.

De Florio, V., Bakhouya, M., Coronato, A., & Di Marzo, G. (2013). Models and concepts for socio-technical complex systems: towards fractal social organizations. Systems Research and Behavioral Science, 30(6), 750-772.

De Nadai, N. B., de Souza, A. Z., Costa, J. D. C., Pinheiro, C. A. M., & Portelinha, F. M. (2017, June). A secondary control based on fuzzy logic to frequency and voltage adjustments in islanded microgrids scenarios. In 2017 IEEE Manchester PowerTech (pp. 1-6). IEEE.