*Article* **Internet-of-Things Based Hardware-in-the-Loop Framework for Model-Predictive-Control of Smart Building Ventilation**

**Abdelhak Kharbouch 1,2,\*, Anass Berouine 1,3, Hamza Elkhoukhi 1,2, Soukayna Berrabah 1, Mohamed Bakhouya 1,\*, Driss El Ouadghiri <sup>2</sup> and Jaafar Gaber <sup>4</sup>**


**Abstract:** In this work, a Hardware-In-the-Loop (HIL) framework is introduced for the implementation and the assessment of predictive control approaches in smart buildings. The framework combines recent Internet of Things (IoT) and big data platforms together with machine-learning algorithms and MATLAB-based Model Predictive Control (MPC) programs in order to enable HIL simulations. As a case study, the MPC algorithm was deployed for control of a standalone ventilation system (VS). The objective is to maintain the indoor Carbon Dioxide (CO2) concentration at the standard comfort range while enhancing energy efficiency in the building. The proposed framework has been tested and deployed in a real-case scenario of the EEBLab test site. The MPC controller has been implemented on MATLAB/Simulink and deployed in a Raspberry Pi (RPi) hardware. Contextual data are collected using the deployed IoT/big data platform and injected into the MPC and LSTM machine learning models. Occupants' numbers were first forecasted and then sent to the MPC to predict the optimal ventilation flow rates. The performance of the MPC control over the HIL framework has been assessed and compared to an ON/OFF strategy. Results show the usefulness of the proposed approach and its effectiveness in reducing energy consumption by approximately 16%, while maintaining good indoor air quality.

**Keywords:** Internet of Things; model predictive control; hardware in the loop; machine learning; energy efficiency; smart buildings

#### **1. Introduction**

Heating, ventilation, and air-conditioning (HVAC) systems are considered among the main building's energy consumers. They account for approximately 50% of the global energy usage in buildings and 36% of all energy-related CO2 emissions worldwide [1,2]. Therefore, HVAC systems need to be efficiently designed and controlled, in reference to international standards, to ensure optimal trade-off between the occupants' comfort and energy efficiency in buildings [3,4]. On the other hand, to assess the energy performance in the design of HVAC management services in buildings, four main comfort metrics need to be considered, which are the visual comfort, acoustic comfort, thermal comfort, and the Indoor Air Quality (IAQ) [5]. This latter has been identified as one of the most important metrics influencing the indoor environmental comfort of the occupants as well as one of the main sources of energy consumption in buildings [4,6], which depends mainly on standalone ventilation management systems.

On the other hand, the indoor concentration of CO2 is considered among the most important parameters for developing efficient control strategies of VSs [7]. The aim is to minimize their electrical energy consumption, while providing good IAQ to the occupants.

**Citation:** Kharbouch, A.; Berouine, A.; Elkhoukhi, H.; Berrabah, S.; Bakhouya, M.; El Ouadghiri, D.; Gaber, J. Internet-of-Things Based Hardware-in-the-Loop Framework for Model-Predictive-Control of Smart Building Ventilation. *Sensors* **2022**, *22*, 7978. https://doi.org/ 10.3390/s22207978

Academic Editors: Antonio Cano-Ortega and Francisco Sánchez-Sutil

Received: 29 September 2022 Accepted: 13 October 2022 Published: 19 October 2022

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Copyright:** © 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

The objective is to keep the CO2 concentrations within the comfort range by providing the required fresh air from outside to the inside of the building using optimal ventilation flow rates. Basically, the majority of conventional building's VSs are operated by simple rules-based controllers (e.g., intuitive ON/OFF controllers or simple PID controllers). Most of them are based on predefined operating parameters, which use normal ventilation rates, to provide the amount of outside air demanded by the building. However, their control mechanism is still inefficient regarding the performance decrease in frequent system context changes as well as dealing with the time-delay [8]. Typically, the ventilators acts automatically on behalf of many buildings' context-awareness parameters, such as the indoor temperature (based on the envelope characteristics), control modes of the VSs, and occupants' presence [9]. This can affect the energy operation flexibility, indoor environmental comfort, and occupants' productivity due to uncontrollable ventilation rates, resulting in wasted energy [10].

Recent studies highlighted that weather conditions and occupants' behavior are the most important information that can help to improve a building's services (e.g., VSs) [7]. Occupancy detection systems in buildings are mostly involved in extracting meaningful occupancy information, which could be used for setting up different control strategies. Different occupancy parameters can be collected from the building's environment including occupants' presence, number, activity, identity, location, and tracks. All of these metrics can be integrated in Building Energy Management Systems (BEMS) as a primary input for controlling active/passive systems, such as HVAC, standalone ventilation, and lighting [11–14]. Most recent research work investigated the development of intelligent methods by integrating machine learning, deep learning, and reinforcement learning [15,16]. In addition, advanced techniques from automation, system modeling and optimization, Internet of Things (IoT) for real-time systems monitoring, data processing and context-aware computing techniques could be combined for the development of BEMS [17].

As is commonly known, new innovative designs of equipment and system components need to be tested while going through extensive essays [18]. The aim is to validate and properly ensure their reliability before deploying them in real-sitting scenarios. The tests can either be run in a laboratory (small scale), using only pure simulations, or by combining both ways, resulting in HIL simulations [19]. Unlike conventional simulations, concrete testing in laboratories may be seen as the most accurate and is a sure indicator of performance. However, it has some limitations. First, it can generate high costs and is subject to many constraints. For instance, the number of tests that can be run over a period of time and under the same conditions are very limited. Hence, comparing different control approaches or different products providing the same function becomes challenging. On the other hand, numerical simulation is another used method among engineers and researchers to properly evaluate the performances of control methods of many applications, which can be deployed in buildings or other sectors. Numerical models could capture the dynamic of the equipment and the building while considering real weather conditions (if available), the combined internal loads (gains, lighting, occupancy, etc.), and other stimuli. Furthermore, once the numerical model is mature enough, it can be used repetitively to evaluate equipment's control at lower costs. For this, the model should prove its fidelity and accuracy in mimicking the real system's behavior and the related building. As can be noticed, a variety of validated models and toolkits are available for a variety of domains using different simulation tools [20]. It is worth mentioning that, during the recent decades, co-simulation capabilities expanded the modeling scope further to other domain systems at a very precise resolution [21]. However, some problems cannot be tackled easily through simulations, especially if numerical models cannot capture all necessary details [22].

In parallel, recent advances in IoT and big data technologies allow for real time data monitoring and processing, while enabling predictive analytics and advanced systems' control. In fact, IoT is considered the most important emerging technology, allowing for the development of advanced and smart connected solutions varying from eHealth, industry and transportation to energy management and smart control [23–31]. Any system

or device having the capability to connect to a network and communicate over the Internet is considered a thing in an IoT infrastructure [32]. This latter provides required tools to manage, control, monitor, visualize and process the things' data (e.g., embedded devices, smartphones, smart actuator, sensors). In parallel to this progress, the integration of smart energy grids with IoT and big data techniques has recently emerged into what is named the Internet of Energy or Energy Internet [19,20]. In fact, with the emergence of smart power meters and smart electrical appliances, it is now possible for users to closely monitor energy consumption while having the ability to plan and manage their consumption. The IoT infrastructure makes it possible to capture and analyze sensor data in real time, allowing consumers to interact with data and decision making [33].

The main aim behind the framework proposed in this paper is to fill the gap between simulations and real case experimental validation of control approaches and mechanisms. The framework could be used not only to control buildings systems but also for other use cases in which the experimental validation of a developed control model is needed. A flexible architecture of the platform has been introduced and its components are detailed to provide an easy to implement solution for similar applications. The work presented in this paper focuses on the integration of IoT/big data techniques with simulation tools in order to enable HILS. The aim is to join both field testing and numerical modeling by combining hardware and software to form HILS frameworks. These latter make it easy to assess multiple tests under the same conditions and, eventually, to accommodate for dangerous operations. As a case study, to show the usefulness of the HILS framework, a Model Predictive Control approach (MPC) was deployed on standalone VS. The framework integrates recent IoT and big data platforms together with machine-learning algorithms and MATLAB-based MPC model.

In summary, the objective of the work is twofold, first to show the usefulness of the proposed IoT based HIL framework together with the integrated machine learning model and smart control technique of MPC, and second, to study the performance of the MPC model combined with forecasted occupancy number and real-time test site's contextual data. The goal of the experimentation is to maintain the indoor CO2 concentration at the standard comfort range while enhancing the energy efficiency. Setting up a field operational testing predictive control techniques is a very challenging and time consuming task. This work could leverage the gap between simulations and real application of predictive control in smart buildings.

The remainder of this paper is structured as follows. Section 2 presents recent work related to advanced strategies for smart control and IoT-HIL based approaches. In Sections 3 and 4, the description of the used materials as well as the architectures of the proposed control strategies and the IoT-HIL platform will be presented. In Section 5, results are presented to demonstrate the accuracy of the proposed models as well as the developed framework. Conclusions and perspectives are presented in Section 6.

#### **2. Related Work**

Recent research work showed that reducing energy consumption in buildings, especially those related to HVAC systems, can be attained through the usage of advanced control strategies. In this regard, two main approaches of rule-based control algorithms have recently emerged in the field of advanced HVAC control: Learning based approaches (e.g., fuzzy logic, Artificial Neural Networks (ANNs), fuzzy and adaptive fuzzy neural networks and genetic algorithms) and MPC [34]. Among these control algorithms, MPC has been introduced as one of the most powerful control techniques used to manage complex processes, such as in HVAC systems [35] studies. This control technique can handle nonlinear processes and their dynamics according to different objectives functions, such as those related to indoor air quality and thermal comfort improvement [36,37].

On the other hand, one of the most efficient ways of conducting field operational testing appears to be the HIL simulations seeing its various advantages (low cost, accurate results, etc.) [38]. This new concept is becoming widely used in developing and testing complex real-time embedded systems [39]. This is mainly done by adding, through mathematical representations (also referred to as "plant simulation"), the complexity of the plant to be controlled into the test bed [40]. To perform HIL simulations, electrical emulation of sensors and actuators is used to interface between the "plant simulation" and the "system under test". In fact, the plant simulation controls the value of the emulated sensor, which is then read by the embedded system under test. In HIL simulations for system synthesis, major physical equipment and their associated controllers are integrated with simulated devices or building spaces to investigate behaviors under realistic dynamic conditions.

In the last decade, researchers focused their interest on the HIL approach and used it not only in automotive and spatial systems but also in buildings' equipment testing and control. For instance, Missaoui et al. [41] proposed new BEMS strategies to support demand side management and to validate them using a Power-Hardware-in-the Loop (PHIL) test bench. However, the proposed solution can be used to validate control algorithms in a reasonable time. Schneider et al. in [42] focused their work on investigating the interaction of a real circulating pump with the hydronic network of a virtual building energy and control system. The presented model, using Modelica for building simulation, is used to bridge the gap between the design and commissioning stage of a control algorithm for HVAC components. The used model is a single-family dwelling with limited complexity. The comparison between simulation results and measured data proved the accuracy of the model with a mean relative error less than 4%. De la Cruz et al. in [43] presented, in their paper, the implementation of an HIL real time simulation test bunch for Air-to-Water-Heat-Pumps (AWHP). This will allow HVAC manufacturers to optimize the control of their systems and to improve their efficiency. A real AWHP was tested under real climate conditions, as for the thermal loads, they were calculated through the connection of the AWHP and a virtual building, simulated using Modelica software, via HIL real time simulation. Seifried et al. in [44] proposed a new model, based on the interconnection of a prominent building automation protocol, namely BACnet, and the PowerDEVS simulator to facilitate HIL testability of new and existing building automation system components. Huang et al. in [22] presented an agent-based framework for HIL simulations, which could either be used for investigating the controller performance or HIL for system synthesis. In other words, it is possible to involve controllers as well as other major equipment in the test to ensure that their dynamic behavior is being correctly captured. Zahari et al. [45] developed a control algorithm to bring the HIBORO helicopter prototype into equilibrium. The developed algorithm is a combination of the MPC and the black box nonlinear autoregressive model. Using the Xpc Target rapid prototype under Simulink, HIL simulations have been run for different set points to evaluate the performances of the proposed model. This latter contains inertial measurement unit sensor software, the MPC, and C/T blocks for capturing and generating Pulse Width Modulation (PWM) signals. The controller proved its efficiency in terms of stabilizing the prototype under all disturbances.

Samano-Ortega et al. [46] developed a platform for the validation of photovoltaics (PVs) system controllers using IoT and HIL concept. The platform englobes five main parts: (i) a control emulator based on HIL, producing the behavior of PVs' arrays, a converter, and Alternating-Current (AC) loads, (ii) Cloud database, (iii) smart sensors for load monitoring, (iv) residential PVs (RPVs) connected to the Internet, and (v) a mobile application for tracking and monitoring. The main principle is that measured voltage and current of the AC loads (using smart sensors) and the production of RPVs are downloaded to the HIL, which reproduces the behavior of the PVs and loads in real-time. The platform proved its efficiency in emulating the behavior of the installed PVs with a mean relative error of 0.42% and the AC load with a mean absolute error of 10 mA. Conti et al. [47] showed the relevance of the dynamic coupling between an air-source heat pump and a building apartment, located in Pisa (Italy), in winter in terms of energy performances under three different operational modes. The adopted HIL extensive experimental campaign proved its potential in properly estimating the energy consumption as well as developing advanced operational strategies. Frison et al. [48] developed a simple low cost MPC controller, which

has been evaluated using HIL experiments, for assessing, under realistic conditions, the energy performances of a heat pump system.

Furthermore, due to the large availability of smart low-cost embedded devices (e.g., Arduinos, Raspberry pi, NVidia Nano, actuators, and distributed sensors), and data streaming processing tools, such as Storm/SAMOA and Kaa applications [49], and generally, the advances of information and communication of IoT technologies [50], the implementation of optimal control strategies for improving the energy efficiency as well as indoor air quality and thermal comfort is becoming immediate and more viable [51]. Their application has been widely studied for the development and deployment of intelligent context-aware services and applications, such as occupancy prediction [52], healthcare [31], transportation and logistics [53], smart grids [54,55], and smart homes [56]. For example, Huchuk et al. [16] evaluated numerous classification machine learning algorithms and models for predicting occupants' presence in smart buildings using thermal data. Further, Zhang et al. [57] presented a literature review about the integration of machine learning for predicting occupancy patterns to improve indoor air quality, while optimizing energy use. In addition, online machine learning techniques (e.g., vertical Hoeffding tree and self-adjusting memory for KNN) can be included for predicting occupants' number and presence using environmental data, such as CO2 temperature and humidity [58,59]. IoT and HIL concepts could provide an integrated solution to cover the important aspects of BEMS by enabling the collection, monitoring, and processing of stream data together with machine-learning techniques. These latter are, for instance, used to compute accurate forecasts, which are required for the MPC to compute accurate predictions, i.e., forecast optimal actions for real-time control of a building's services.

In this work, a case study that focuses on a standalone VS, is worked out to assess the usefulness and effectiveness of the proposed HIL framework. In fact, data that has been collected from a set of sensors, such as temperature, motion, and CO2 concentration, is used to predict occupancy patterns [30]. These latter are then fed to the MPC to control indoor CO2 dynamics by forecasting the optimal ventilation rates.

#### **3. Materials and Methods**

In this section, an HIL experiment of a closed-loop VS driven by the MPC is performed. The MPC ventilation controller model, which has been previously designed, developed, and validated using simulations [28,29], has been physically deployed to the Raspberry Pi (RPi) located at the EEBLab test site. The RPi-in-the-loop experiment has been run under realistic conditions to dynamically actuate the fans of the VS and to assess the controller's performance in terms of energy efficiency and indoor CO2 improvement. In fact, the deployed VS is made of two standalone controlled fans, which are respectively responsible for bringing the fresh outdoor air to the indoor and draining the CO2 out of the building. More precisely, these two fans are installed in both side walls and operate instantaneously under the same control signals. The VS can provide a maximum airflow rate of 440 m3/h, which is equivalent to a rated speed of 3800 rpm and is powered by a photovoltaic solar system. The occupancy information was used as a disturbance as well as a forecast input for the MPC.

#### *3.1. Description of the Case Study Building: EEBLab*

The considered specimen, named Energy Efficient Building Laboratory (EEBLab), is a rectangular cavity, which is part of a set of two identical prefabricated structures (Figure 1), located at the International University of Rabat. Each test bed is 12 m2 of occupied surface and 30 m3 of volume. Additionally, each prefabricated has one single glazed window on its south façade. The laboratory has been made essentially for implementing and testing different scenarios related to eHealth, Energy efficiency, ICT, and renewable energies integration and control. The main aim is to investigate the integration of recent IoT, big Data technologies, and advance real-time machine learning algorithms for developing context-aware services and applications.

**Figure 1.** (**a**) Energy Efficient Building Lab (EEBLab) test site; (**b**) Interior side wall of EEBLab with ventilation fan and a set of sensors and other equipment.
