*3.4. MPC for Predective Control*

The work presented in [29], presents the developed dynamic model for CO2-based MPC of a building's VS. The model, describing this system, is a state-space model, which is based on the relationship between the input/output airflow rates and indoor CO2 concentrations. The MPC controller model was tuned to be deployed in a real case scenario, considering the real context of the EEBLab, in particular, the building space and occupancy number profile as well as the characteristics of the VS. Simulations have been conducted to the following highlights during the tuning of the MPC controller input parameters:


• A longer control horizon (i.e., M ≥ 10 steps ahead), the response of the controller output becomes too aggressive and therefore overshoots, which does not occur when using a small control horizon.

In fact, the control horizon M and the prediction horizon P inputs are the key design parameters of the MPC. They have a significant impact on its performance (i.e., settling/rise time and stability), especially in the presence of disturbances.

In this experimental study, as schematized in Figure 8, the optimal control problem (OCP) of the MPC is solved for every time interval (30 s) in which its optimal control output is calculated for the entire horizon P. The inputs to the OCP are the forecasted occupancy number, the outdoor CO2 concentration, and the previous measurement of indoor CO2 concentration (k−1), along with the system constraints (i.e., indoor CO2 set point and airflow limits).

**Figure 8.** The general structure of the MPC framework for the EEBLab ventilation control system.

The prediction and control horizons used in the MPC framework are respectively P = 10 (i.e., 300 s) andM=5 (i.e., 150 s) steps ahead. For occupancy, the forecasted number is used to control the indoor CO2 dynamics, including the CO2 generated by the occupants over the horizon P. The forecast of the occupants' number and measurements of the indoor/outdoor CO2 are forwarded to the OCP. The optimized control output (i.e., minimal required airflow) is fed back to the dynamic model to calculate the future predictions of indoor CO2 concentrations for the entire prediction horizon P. This calculation is repeated every time interval. At each time interval, the future occupancy and prediction of the indoor CO2 concentrations along with the constraints are updated and passed to the OCP to plan the next sequence of control inputs to be applied at that time. Only the first optimal input of the control sequence is implemented, and the remaining input values are discarded.

To solve the OCP, the following quadratic cost function is used, which reduces the future error *e*ˆ between the CO2 set point references *yref* and predicted indoor CO2 concentration *y*ˆ through the prediction Horizon *P*. This is mainly achieved by applying the optimal control increment action Δ*u*ˆ in which the minimum of airflow *u* is delivered and the indoor CO2 concentration *y* is maintained within comfort bounds. *Q* and *R* represent weighting matrices. The set point of indoor CO2 concentration is defined at 550 PPM, whereas the outdoor CO2 is kept at a constant value of 400 PPM.

$$Minimize J = \frac{1}{2} \sum\_{K=0}^{k=P} \left[ \left( \mathfrak{F} - y\_{ref} \right) \mathbf{Q} \left( \mathfrak{F} - y\_{ref} \right)^{T} + \left( \Delta \mathfrak{A} \right) \mathbf{R} \left( \Delta \mathfrak{A} \right)^{T} \right],$$

Subject to, *y* < 550 PPM and 0 < *u* < 440 m3/h - <sup>∼</sup> 0.12 m3/s <sup>∼</sup> 122.22 L/s <sup>∼</sup> 259 scfm .

#### **4. Real-Time Implementation**

This section presents the implementation of the MPC framework for controlling the VS with the aim to improve both the indoor air quality and energy saving. An HIL experiment in which the MPC model controller is physically implemented in an RPi development board is conducted. Figure 9 shows the blocks that have been integrated to enable the communication between the MPC VS model, which is carried out with the MPC toolbox of MATLAB/Simulink environment and the HOLSYS platform.

**Figure 9.** MATLAB/Simulink model for ventilation system's control using MPC.

To enable the use of MQTT in the MATLAB/Simulink model, the Raspberry Pi support package for MATLAB and Simulink have been installed using MATLAB Add-ons.

Many blocks are available in the Simulink libraries under "Simulink Support Package for Raspberry Pi Hardware". The two used blocks are "MQTT subscribe" and "MQTT publish". The former subscribes to the topics "MPC/IN/OCC" and "MPC/IN/CO2" to get, respectively, the forecasted occupant's number and CO2 measurements from the forecast model and the HOLSYS platform. The latter publishes the required flow rate into the "MPC/OUT" topic to control the ventilation speed. As shown in Figure 3b, the ventilation control node is wired to the inlet and outlet fans and controls them using PWM. In fact, the node receives the required flow rate from the platform through MQTT and transforms it to the corresponding PWM signal. The general architecture of the experimental setup from sensing till the control execution is illustrated in Figure 10.

The MPC controller, which is run from MATLAB/Simulink simulator, is emulated and embedded into the RPi as an independent hardware in the network.

However, Simulink is able to keep monitoring the simulation run time as well as the inputs and outputs of the MPC model. Using an MQTT publisher and subscriber tool, it is possible to inject test data into the model or monitor any variable from all over the experimental setup and its system entities.

**Figure 10.** The experimental setup architecture of HIL implementation of the MPC for EEBLab ventilation system control enabled by the HOLSYS IoT platform.

#### **5. Results and Discussions**

In this section, the results obtained from the experimental setup of the different deployed systems are presented. In fact, after connecting everything together, the simulations have been run and data are collected during the experiment's time. The experimentation started at 13:36 at the EEBLab test site. All the windows were closed and the only source of fresh air was the ventilation inlet. The HVAC was set to off. The weather station readings at the time were 23 ◦C for the ambient temperature and 56% for the relative humidity. The behavior of two employees at an office of 12 m<sup>2</sup> was simulated. Other staff joined the team from time to time. While the occupants were performing moderate activities (e.g., using their personal computers and reading several articles while conversing), CO2 was changing its levels and increasing with more people inside the test site. At each new visit, the door was opened and closed in approximately 5 to 8 s. However, the influence of the door openings and the air exchanged during this time has not been taken into consideration. In fact, the objective behind the experimental setup is to show the usefulness of the proposed framework with all its components. It is a proof of concept of the intercommunication of different entities that form the entire concept. The idea is to integrate control strategies and modern technologies into a holistic framework for enabling real time monitoring and control of buildings' systems.

First, advanced methods for forecasting indoor occupancy are implemented. Real occupancy data is sent to the server to be processed and exploited by the deployed forecasting model. It is implemented to read 10 instances and forecast 10 values ahead. The model gets new data every 1 min. It means that the model is able to forecast 10 min ahead. the forecasted occupancy data is sent to the MPC model to measure the flow rate needed to adjust optimal operation of the VS. The calculated accuracy and root mean square error (RMSE) parameters of the LSTM forecasting are respectively, 3.34% and 98.7%. Secondly, an MPC control strategy is integrated for VS's control. All together, these systems have been inter-communicated via the deployed IoT platform. The simulation model of the MPC controller has been compiled via MATLAB/Simulink and embedded into the RPi 4 B+ installed into the test site. Afterwards, the installed sensors began to inject input data to the forecasting and MPC models and outputs (controls) were executed by the ventilators.

In order to assess the performance of the MPC against the ON/OFF, three metrics have been generated: (i) the regulation of indoor CO2 concentration, (ii) the ventilation flow rate evolution, and (iii) the instantaneous power consumption, which are calculated using the smart metering platform [26]. Experiments have been conducted using the above-mentioned set-up and the three metrics have been evaluated for the ON/OFF and MPC controllers during five hours and a half from 13:30 to 19:00. The occupants' number together with the behavior of indoor CO2 concentration, ventilation flow rate, and power consumption of two controllers can be observed in Figures 11–14.

**Figure 11.** Occupancy forecasting results using LSTM.

**Figure 12.** The MPC flow rate output together with the CO2 concentration variation.

**Figure 13.** The ON/OFF flow rate output together with the CO2 concentration variation.

**Figure 14.** Energy consumption variation of the ventilation system during control for both ON/OFF and MPC controllers.

As can be seen from Figure 11, the forecasted occupants' number seems to be close and to correlate well with the collected real occupants' number. A minor difference is seen at the peak points of the real occupancy.

The ON/OFF approach has been chosen for comparison as it is the most used control approach in VSs. It is a simple control mechanism which triggers full On or full Off in case of CO2 variation from the fixed setpoint. The ON/OFF control was deployed using the above-mentioned approach the next day.

In terms of CO2 regulation, both controllers provide good performance in maintaining the CO2 concentration with faster settling/rise responses for the ON/OFF to achieve and maintain the desired level, which is fixed to 550 PPM setpoint. Unlike the ON/OFF, the MPC was able to provide a better transient response to refresh the air inside the EEBLab using the optimal ventilation rate, as can be observed from Figures 12 and 13.

For energy consumption, the obtained results presented in Figure 14, showed that the MPC outperforms the ON/OFF and allowed higher performance in improving energy savings. This performance can be explained by the predictive mechanism of the MPC, which includes the optimized criterion Δ*u*ˆ that predict the effective ventilation flow rate according to the indoor CO2 dynamics, including the CO2 generated by occupants.

Regarding the total energy consumption of the VS during this experiment time period, the MPC outperformed the ON/OFF control and allowed a significant energy reduction by 16.44%. It can be noticed from Figure 14, that the peak energy consumed by the ventilators is reached only a few times by the MPC control unlike the ON/OFF method. The total energy consumed by MPC control is 119.4 Wh while the ON/OFF consumed a total of 142.88 Wh.

#### **6. Conclusions and Perspectives**

In this work, an HIL based framework was introduced for standalone VSs using MPC control method. The objective was to assess the effectiveness of the proposed framework in terms of indoor air quality improvement and energy efficiency in real-setting scenario. In fact, a Simulink based HIL model was proposed and implemented in the EEBLab to assess the effectiveness of MPC control. Contextual data are collected using the HOLSYS IoT platform and LSTM machine learning models have been integrated for real time occupants' number forecasting. Resulting forecast data have been exploited by the MPC for optimal regulation of the ventilation flow rate. The performance of the MPC over the HIL framework has been assessed and compared to the ON/OFF strategy. Experimental results showed that both controllers provide acceptable performance in regulating the indoor CO2 concentration. However, the MPC allowed significant energy reduction by approximately 16% compared to ON/OFF.

As a perspective of this work, the framework will be applied and experimented for the HVAC system's control using MPC. This latter has already been validated by simulations [66]. Furthermore, additional experiments will be conducted to shed more light on the integration of IoT and machine learning algorithms for setting up context-driven control approaches of different building services, including lighting, shading, and HVAC systems. Additionally, the perspective includes integrating the proposed framework for developing other buildings services, such as renewable energy production forecasting and predictive control of power systems [24].

**Author Contributions:** Conceptualization, A.K., A.B. and H.E.; methodology, A.K.; software, A.K., A.B. and H.E.; validation, A.K., A.B., H.E., S.B., M.B. and D.E.O.; formal analysis, A.K., A.B. and H.E.; investigation, M.B.; resources, M.B. and J.G.; data curation, A.K.; writing—original draft preparation, A.K., A.B., H.E. and S.B.; writing—review and editing, M.B., J.G. and D.E.O.; visualization, D.E.O.; supervision, M.B. and D.E.O.; project administration, M.B.; funding acquisition, M.B. and J.G. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research was supported by IRESEN under the HOLSYS project (2020–2022), Green Inno-PROJECT-2018.

**Institutional Review Board Statement:** Not applicable.

**Data Availability Statement:** Not applicable.

**Conflicts of Interest:** The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript; or in the decision to publish the results.
