Development of a Coupled EnergyPlus-MATLAB Simulation Based on LSTM for Predictive Control of HVAC System
To avoid unnecessary energy waste due to the single temperature setpoints of the heating, ventilation, and air conditioning (HVAC) system during the seasonal variation period, this study proposed a long-short-term memory (LSTM) neural network to predict and control the temperature setpoint. The thermal comfort, cooling rate, and heating rate were predicted with outdoor environment parameters and occupant count. A large scale of operation data was collected from the EnergyPlus simulation, which was previously developed based on the characteristics of a real case study house. Different kinds of input characteristics were offered to test the stable use of LSTM and other artificial neural networks. This paper discusses the development of a Matlab EnergyPlus co-simulation to predict and control the temperature setpoints of a variable air volume system, especially the relationship between temperature setpoint and energy consumption. The simulation results indicate the advantages of the LSTM prediction of energy consumption and the potential for energy saving with predictive control.
Building energy consumption accounts for about 40% of the global total energy consumption and is expected to reach about 50% by 2030 [1, 2]. Recent research proved that dynamic temperature control can be employed in HVAC systems according to building characteristics and outdoor environment to avoid unnecessary energy waste [3, 4], especially in seasonal variation period .
Dynamic control of HVAC system temperature relies on its model and simulation. Data-driven, physics-based, and grey box modelling techniques are used to complete the model of the HVAC system . Compared to other control objects, the control of HVAC has unique challenges, including nonlinear dynamics, time-varying system dynamics and setpoints, time-varying disturbances, interacting, and at times conflicting control loops . To simplify the HVAC model, linearized sampled data were used with a regression analysis method, such as least absolute shrinkage and selection operator . Economic objective functions are offered with predictive control of HVAC for load transfer and cost saving .
Cosimulation is often used to provide advanced control strategies for building energy management systems. Many of the previous studies used energy simulators such as TRNSYS, EnergyPlus, and Matlab/Simulink to simulate the HVAC operating conditions. Peng et al.  used Matlab and EnergyPlus co-simulation to study the PID control of thermal comfort in four typical kinds of climates, depending on the occupancy rate of buildings. Lapusan et al.  studied an equivalent thermal multiroom model in Simscape, a toolbox of Matlab. The main aim of this paper is to build a simulation tool based on physical models. Avoiding incompatibility problems comes from doing the modelling in the Simulink environment. To utilize an artificial neural network (ANN) to simulate the model predictive control of the HVAC system, Venkatesan et al.  established a heat flow model and equivalent thermal model from EnergyPlus. Alibabaei et al.  used a TRNSYS-Matlab cosimulator with an advance control strategy to study the efficiency of different strategy models. Narayanan et al.  developed a TRNSYS and Matlab co-simulation framework, which was used to implement MPC and optimization algorithms in a standard single-family house. Wang et al.  utilized a reinforcement learning controller in Matlab to control EnergyPlus depending on building controls virtual test bed (BCVTB). Rosato et al.  used experiments to test the accuracy of TRNSYS and Matlab co-simulation model. The correlation coefficients of supply air temperature and open percentage of different valves were above 0.95. Homod et al.  developed a co-simulation framework between Matlab and ANSYS to verify the accuracy of the HVAC model. The correlation coefficient of indoor temperature was 0.9897, and the coefficient of the vernacular predicted mean value (PMV) is 0.839.
The prediction errors between different articles were difficult to compare because of different input features. The input features of LSTM predictions lacked past energy consumption, and the RMSE of it reached 618.40 . Some used energy-normalized RMSE as a criterion for prediction accuracy, and the RMSE of it reached 0.13 . Mtibaa et al. used LSTM neural network to predict indoor temperature, which showed that the LSTM models outperform multilayer perceptron models by reducing the prediction error by 50% . To control the thermal comfort with smart WIFI, Huang et al. compared back-propagation (BP) neural network with LSTM and encoder-decoder LSTM about thermostat setting. The LSTM control reduced the range of heating and cooling by 14.3% significantly .
Thermal comfort is not only the limit of temperature setpoints but also the evaluation standard of temperature control effect. Baldi et al.  developed a self-tuning load management program with smart zoning to reduce energy by 4% and improve thermal comfort by 8% in an actual EnergyPlus model. De Dear et al.  reviewed the research progress on adaptive thermal comfort and some outstanding problems since 1998, such as the intersection of thermal comfort temperature in the conventional comfort model and adaptive comfort model based on RP-884 (actual observation database). Alfano et al.  summarized the calculation methods of thermal comfort software on the APP market and the problems needing attention in the process of PMV calculation. Cao et al.  reviewed the research related to dynamic thermal comfort, aiming to explain the development, prospects, and necessity of dynamic thermal comfort research. Somu et al.  used transfer learning and a comprehensive thermal comfort evaluation index to solve the lack of thermal comfort samples. Korkas et al.  guaranteed the independence of microgrid with supervisory strategy to improve the thermal comfort when energy storage and renewable energy sources are used.
In this paper, environmental parameters are used to set thermostat of HVAC based on LSTM prediction in a co-simulation platform. The paper consists of 4 sections. In Section 2, the Matlab and EnergyPlus co-simulation platforms are described. The process models of simulation and an overview of the principle of LSTM are also described, especially focusing on the input and output parameters of the prediction model. In Section 3, we will provide results and a discussion about the simulation. In Section 4, the conclusion is provided.
2. Materials and Methods
2.1. EnergyPlus Simulation
The simulation location is set at 20.03°N, 110.35°E, which belongs to the tropical monsoon marine climate. The run period of the control simulation is from March 1st to April 30th (the latter spring and early cooling period ). The run period of the simulation without control is from January 1st to December 31st for comparison. The HVAC system in this paper is a variable air volume system with reheat, including chiller, cooling water coil, heating water coil, variable pump, variable fan, boiler, and cooling tower. The floor area is 98 m2, and the building height is 3 m. Tables 1 and 2 and Figure 1 show other parameters of the EnergyPlus building model.
The energy consumption of the water chilling unit in the EnergyPlus simulation is calculated by the chilled water outlet temperature and inlet water temperature of the compressor at the rated conditions. The formula is built by experimental data, and the data from manufacturers are based on the least-squares method.
2.2. Thermal Comfort
The thermal comfort model plays a significant role in LSTM neural network prediction. PMV is used as a widely used index in evaluating users’ thermal comfort. According to the ISO-7730 standard, the factors affecting PMV include indoor air temperature, mean radiation temperature, relative humidity, metabolic rate, mechanical work, clothing isolation value, and clothing surface temperature . The following PMV calculation formula works well except under high relative humidity:
In order to simplify the model, mechanical work is set to zero. The above formulas are used to calculate thermal comfort during EnergyPlus simulation, which has limitations. When using neural network to predict the thermal comfort of occupancy, it can be modified appropriately. It is difficult to measure clothing surface temperature and metabolic rate in practical applications. Therefore, the former features are not used as the input to the prediction of the LSTM neural network.
2.3. LSTM Prediction
To fit the diffusion or explosion of the gradient with recurrent neural network (RNN), LSTM was proposed . LSTM includes input gate, output gate, forget gate, cell gate as shown in Figure 2. The Adam optimizer is chosen. It has strong adaptability to training parameters as the default optimizer in many application scenarios. The gradient threshold is 1, the initial learning rate is 0.005, the learning rate drop period rate is 125, and the drop factor is 0.2. After testing and verification, the above parameters can control the training time and accuracy within a relatively reasonable range. In order to strengthen the learning ability of the LSTM neural network and avoid overfitting or other problems caused by too many hidden units, the influence of different numbers of hidden units about the error of the test set is tested, and the prediction is better when 48 hidden units are tested.
The prediction error of the LSTM neural network is calculated according to the mean absolute error (), root mean square error (), and coefficient of determination ().
In this paper, a total of two LSTM predictions are made to analyse the influence of the change of air conditioning temperature setting value on the cooling rate, heating rate, and PMV. The input characteristics of the first LSTM do not include the temperature setting value. LSTM trains and predicts the output when the air conditioning temperature setting value is fixed at 26°C. A pseudorandom temperature setpoint between 24°C and 28°C coming from the Simulink block is transferred to EnergyPlus with the same time step. Data are obtained through EnergyPlus simulation and calculated the difference with the result of the first simulation. The second LSTM takes the difference of the temperature setpoints (from −2°C to 2°C) and the prediction results of 26°C as the input characteristics to predict the difference. The final prediction result is obtained by adding and correcting the former prediction results.
The co-simulation model of MATLAB and EnergyPlus obtains the local air dry bulb temperature, relative humidity, solar radiation, and other data from the weather file and transmits them to the LSTM prediction model in EnergyPlus and MATLAB through the BCVTB interface.
2.4. EnergyPlus and Matlab Co-simulation
The calculation process of EnergyPlus is equivalent to a loop in the Matlab program as shown in Figure 3. The condition of the loop is that the simulation time is less than the end time. The content of the loop is to obtain the output of EnergyPlus first and then the input of the BCVTB interface. Therefore, it is necessary to set an initial value of the input. During the loop, the inputs will be calculated into outputs in combination with weather data, building structure, and HVAC settings.
In the co-simulation model, k represents the value of the current time, k + 1 represents the value of the next time, and the interval between the two values is 10 minutes or 1 hour. The LSTM model obtains the value at time k, predicts the thermal comfort, cooling rate, and heating rate at time k + 1, and compares the LSTM predicted value at time k − 1 with the actual output value of EnergyPlus at time k. Calculates the error and adds a coefficient as a correction. Based on the predicted value of thermal comfort, using the optimization algorithm, select the appropriate value of air conditioning temperature and input it into EnergyPlus to complete the loop calculation.
In the co-simulation, the optimization condition is the minimum energy consumption of HVAC or the minimum energy consumption under the condition of ensuring thermal comfort. The calculation amount for optimal operation of the HVAC system is increasing, especially if the prediction horizon is extended.
3. Results and Discussion
According to the EnergyPlus weather document, the outdoor temperature in the area changed dramatically from March 1 to April 1. The maximum outdoor temperature is close to 34°C, the minimum temperature is close to 14°C, and the temperature span is nearly 20°C. Single cooling or heating temperature of 26°C will cause unnecessary energy waste. Air conditioning systems with room temperature set to a constant value tend to waste energy unnecessarily during seasonal switching periods. By querying and simulating the outdoor temperature throughout the year, it is found that the outdoor temperature changes drastically in March and April. When the room temperature is set to 26°C, the changes in indoor and outdoor temperature, cooling power, and heating power are shown in Figure 4.
When the temperature is set to be constant at 26°C, the PMV cooling rate and heating rate at time k + 1 are predicted by the LSTM neural network. The input characteristics include PMV, cooling rate, heating rate, outdoor temperature, clothing thermal resistance, occupancy, and outdoor relative humidity at time k.
Pearson correlation coefficient is used to test the correlation extent of the input characteristics of the LSTM prediction. The Pearson correlation coefficients are shown in Figure 5.
Principal component analysis is used to reduce the dimension of the data. According to the principal component analysis, the contribution rates are 48.8087%, 18.2022%, 13.4150%, 7.7321%, 4.4815%, 3.7200%, 2.3225%, 1.0113%, 0.3066%. Therefore, solar radiation is not considered as the input characteristic in this paper.
The difference in data compared to 26°C is calculated to clear the relationship between the effect of temperature setpoint changes and the prediction results as shown in Figures 6 and 7. When the temperature setpoints of the HVAC system change randomly, the accuracy of LSTM prediction is higher than that of SVM and BP.
To avoid frequent changes in the temperature setpoint of the HVAC system, the time step of the predictive control in the co-simulation is extended to one hour. The LSTM neural network generated by the prediction of the differenceis used to reduce the error. When the optimization condition is the minimum energy consumption of HVAC, the simulation results are shown in Figures 8 and 9.
From the analysis of previous literature and simulation results, the difficulty of thermal comfort prediction mainly is the lack of data. The prediction of air conditioning energy consumption often needs to remove outliers, obtaining parameters of the operating system, such as the temperature or pressure of the refrigerant. Therefore, the accuracy of the prediction has decreased in the real-time control of the co-simulation simulation for various reasons. In Figure 10, the sum of cooling and heating energy consumption with LSTM predictive control in a week is 47.6903 kWh. When the single cooling or heating setpoint is 26°C, the sum of energy consumption is 98.4682 kWh. The energy consumption is 109.2425 kWh at 24°C and 70.7526 kWh at 28°C.
To meet different application scenarios, different control equations are established. For complex and nonlinear HVAC systems, there are often contradictions between different control conditions. Simulation time changed from July 1st to August 31st, and the training and prediction methods of the LSTM neural network are the same as the previous simulation. If the control conditions are directly set to the minimum value of the energy consumption of the HVAC system that limits the PMV between −0.5 and 0.5, the indoor temperature will fluctuate. The temperature setpoint needs to avoid frequent changes by setting the softening factor as shown in Figure 11.
In this paper, a Matlab and EnergyPlus co-simulation was established to study the accuracy of LSTM prediction based on weather data and occupancy. EnergyPlus can provide accurate and useful simulation results, while Matlab can provide LSTM prediction and control strategies. The results show that LSTM has stronger antiinterference in the accuracy of prediction. The predictive control supported by LSTM neural network can save 25.70% energy consumption of the HVAC system in a certain seasonal variation period.
There are contradictions in the actual HVAC control of temperature setpoints. For example, the temperature setpoint will always be the maximum value (28°C) when the control condition is only the minimum energy consumption in the simulation from July 1st to August 31st. Energy consumption will be increased when thermal comfort limits are imposed.
LSTM predicted control with a single predictive time step is limited, especially when the outdoor temperature rises rapidly. With the increase of the prediction step, the simulation results will become more stable. The prediction and comparison of different time steps need to be further studied and verified.
|Metabolic rate in PMV calculation (W/m2)
|Mechanical work of people in PMV calculation (W/m2)
|Air pressure (Pa)
|Mean air temperature (°C)
|Temperature of the cloth surface (°C)
|Mean radiant temperature (°C)
|Convective heat transfer coefficient (W/(m2·K))
|Clothing area coefficient
|Clothing isolation ((m2·K)/W)
|Relative clothing isolation ((m2·K)/W)
|Relative air speed (m/s)
|Input of the LSTM
|Output of the LSTM
|Constant, and denote activation function
|Number of samples
|Target mean value
|Setting value of the system output
|Output of the EnergyPlus
|LSTM neural network and other prediction models replace the system identification model to provide the data
|The error of the last prediction
|Correction value of model prediction
|The coefficient of the prediction error
|Weighting coefficient of output
|Weighting coefficient of input
The datasets used during the study are available from the corresponding author upon reasonable request.
Conflicts of Interest
The authors declare that there are no conflicts of interest with this study.
The authors gratefully acknowledge the financial support of National Natural Science Foundation of China (Grant no. 51575286) and Key R&D Plan of Shandong Province (public welfare science and technology research) (Grant no. 2018GGX 105007).
J. Wang, Y. Zhang, and M. Liu, “Comparison of building energy consumption benchmark in China, US and UK,” Building Science, vol. 31, no. 10, pp. 48–51, 2015.View at: Google Scholar
R. Ming, W. Yu, and X. Zhao, “Assessing energy saving potentials of office buildings based on adaptive thermal comfort using a tracking-based method,” Energy and Buildings, vol. 208, no. Feb, pp. 109611.109611–109611.109614, 2020.View at: Google Scholar
B. Peng and S. J. Hsieh, “Simulation Model of Automated HVAC system control strategy with thermal comfort and occupancy considerations,” in Proceedings of the Asme International Manufacturing Science & Engineering Conference Collocated with the Jsme/asme International Conference on Materials & Processing, p. V003T004A003, 2017.View at: Google Scholar
M. Narayanan, A. F. de Lima, A. F. O. de Azevedo Dantas, and W. Commerell, “Development of a Coupled TRNSYS-MATLAB Simulation framework for model predictive control of integrated electrical and thermal residential renewable energy system,” Energies, vol. 13, no. 21, p. 5761, 2020.View at: Publisher Site | Google Scholar
A. Rosato, F. Guarino, S. Sibilio, E. Entchev, M. Masullo, and L. Maffei, “Healthy and faulty experimental performance of a typical HVAC system under Italian climatic conditions: artificial neural network-based model and fault impact assessment,” Energies, vol. 14, no. 17, p. 5362, 2021.View at: Publisher Site | Google Scholar
R. Z. Homod, A. Almusaed, A. Almssad, M. K. Jaafar, M. Goodarzi, and K. S. Sahari, “Effect of different building envelope materials on thermal comfort and air-conditioning energy savings: a case study in Basra city, Iraq,” Journal of Energy Storage, vol. 34, Article ID 101975, 2021.View at: Publisher Site | Google Scholar
N. Somu, A. Sriram, and A. Kowli, “A hybrid deep transfer learning strategy for thermal comfort prediction in buildings,” Building and Environment, vol. 204, 2021.View at: Google Scholar