Model Predictive Control for room temperature control in buildings is an e ective approach to energy management in buildings. However, the development and maintenance of physical models may be a bottleneck for widespread real life application. Data Predictive Control is an attempt to address this problem by learning the behaviour of the building from historical data and thus reducing the modelling e ort. Here, we present an application of a Data Predictive Control approach, based on Random Forests with a ne functions and convex optimization, to control the room temperature in a real life apartment. When compared to a conventional hysteresis controller, the applied approach saves 24.9 % of cooling energy while reducing the integral of comfort constraint violations by 72.0 % in a six-day experiment. Keywords: Data Predictive Control, Model Predictive Control, building energy, Random Forests, Machine Learning 1. Introduction Predictive control has the potential to reduce the en- ergy consumption for heating and cooling in the build- ing domain. Model Predictive Control (MPC) has been demonstrated many times successfully for temper- ature control in buildings (see for example (Oldewurtel et al., 2010; ˇSirok ´y et al., 2011; Oldewurtel et al., 2012; Huang et al., 2015) or the articles reviewed in (Hameed Shaikh et al., 2014)). However, there is to the best of the authors’ knowledge, no widespread industrial appli- cation of MPC in residential buildings. Some authors ((ˇZ´aˇcekov ´a et al., 2014; Sturzenegger et al., 2016; Jain et al., 2018)) argue that the e ort to develop and main- tain ﬁrst principle models of buildings might in many cases be prohibitive for real life deployment of MPC to building energy management. The increasing availability of monitoring data in the building domain gives rise to the possibility of using data-driven modelling approaches for buildings. Here, the challenge lies in ﬁnding methods that show good prediction performance for temperatures in buildings and at the same time allow online real-time optimization over the control inputs, which usually requires at leasta convex model. Regression trees approximate a func- tiony=f(x) by splitting xinto partitions and approx- imating ywith constant values within these partitions (more detail in Section 2). In contrast to conventional Artiﬁcial Neural Networks for example, regression trees in combination with a ne models of the control inputs are convex in these inputs and can therefore be used for building thermal control. Jain et al. (2018) use a combination of regression trees and linear regression for peak power reduction in buildings to optimally trade-o peak power reduction against thermal comfort, under the name of Data Pre- dictive Control (DPC). The regression trees are built with the help of historical building measurement data to model the input-output relation of the current state of the system and future disturbances as inputs to the fu- ture state of the system as output. The regression tree is combined with an a ne model that relates the control inputs to the future states of the system. This yields a model that can be used for receding horizon MPC with convex optimization in the same way as a state-space building model. In (Smarra et al., 2018b) the method is extended by using random forests, which are ensembles Preprint submitted to Elsevier July 2, 2019 of regression trees, instead of single regression trees to reduce the variance in prediction. In (Smarra et al., 2018a) the approach is further developed by replacing the ane control input - state relation by a switched state-space model. This allows the analysis of system properties such as stability. All these studies use simulation for validation, where all disturbances are perfectly known and undesired dis- turbances and uncertainties can be excluded. There are a limited amount of studies ((Costanzo et al., 2016; Macarulla et al., 2017; Ferreira et al., 2012; Finck et al., 2019)) that use data-driven modelling techniques for control in the building domain in real life application case studies. However, to the best of the authors’ knowl- edge, there exists no real life demonstration of DPC for room temperature control in buildings to minimize en- ergy consumption, as shown for MPC in (Oldewurtel et al., 2010; ˇSirok ´y et al., 2011; Oldewurtel et al., 2012; Huang et al., 2015), where control inputs are minimized while keeping room temperatures within comfort con- straints. Here, we apply a variation of the DPC approach intro- duced in (Smarra et al., 2018b) to a real life residential apartment. The apartment features two identical bed- rooms, one of which is DPC-controlled and the other one controlled with a standard hysteresis controller. Our results in a six-day experiment show that the room con- trolled with DPC consumes signiﬁcantly less cooling energy than the conventionally controlled room, as well as showing fewer comfort constraint violations. The remaining article is structured as follows. In Sec- tion 2, the DPC approach by Smarra et al. (2018b) is explained and adapted to our setting. In Section 3, the residential apartment for the experiment is introduced and the particular DPC controller is speciﬁed. In Sec- tion 4, the performance of the DPC controller is com- pared to the hysteresis controller in terms of constraint violations and energy usage. Conclusions and future di- rections are provided in Section 5. 2. Methodology 2.1. Splitting of historical data We assume given a historical data set ( X;Y) of mea- surements of a building. Y=fx(k+1);:::;x(k+N)g consists of measurements of room temperatures x.X= fu(k);:::;u(k+N1);d(k);:::;d(k+N1);x(k );:::;x(k)gconsists of measurements of data that poten- tially has an inﬂuence on Y. These are control inputs u(e.g. cooling energy), disturbances d(e.g. ambient temperature and solar radiation forecasts, but also timeof day variables) and autoregressive terms of the room temperature x.Ndenotes the prediction horizon for the predictive controller, denotes the number of autore- gressive terms. We further split Xin two separate sets Xu= fu(k);:::;u(k+N1)g, which includes all measured con- trol inputs (all variables that can be inﬂuenced by the controller), and Xd=fd(k);:::;d(k+N1);x(k );:::;x(k)g, which includes all measured disturbances and autoregressive terms of x(all variables that cannot be inﬂuenced by the controller). 2.2. Training of random forests We train Nrandom forests to approximate the func- tions Xd!Yj, in which j21;:::;Ndenotes the columns of Y(and the steps in the prediction horizon). Random forests are ensembles of regression trees - a form of decision tree to approximate continuous func- tions. A decision tree is built by splitting the input data Xp dinto partitions p, in each of which the output data Yp jis approximated with a constant value ¯ yp j(which is the mean of all elements of Yp j). The splitting variable and splitting point is obtained with the help of a greedy heuristic (see (Smarra et al., 2018b)). A random for- est of Ttrees is built by bootstrapping Tsubsets from (Xd;Yj) and building a tree based on each subset. The function evaluation of the forest for one element (row) xdofXdis then done by evaluating each tree, giving rise to T di erent ¯ yj(xd), and taking the average of these, giving rise to ˆ yj(xd).Tis independent of Nand needs to be chosen heuristically. For more details on the training process please refer to the original source (Smarra et al., 2018b) and to general literature on random forests (e.g (Louppe, 2014)). 2.3. Fitting of a ne functions for control inputs Each tree has a number of leaves li, each based on a partition Xp dofXdto approximate Yp jwith a constant value ¯ yp j(as discussed before). For each set Xp dthere exists a corresponding set of measured control inputs Xp u that has not been used in the model until here. (Smarra et al., 2018b) ﬁt an a ne model to approximate Yp jwith Xp u(to relate the response of the room temperature to the control inputs) with least squares in each leaf li. For the prediction of the future temperature of a single room x(k+j) (which corresponds to yj) in one leaf, this gives x(k+j)= ji;0+jX n=1 ji;nu(k+n1)+e (1) 2 in which ji;0and ji;ndenote the ﬁtted coe cients and ethe model error. The temperature is therefore an a ne function of all control inputs from the time instant k, when the forecast is made, to the forecasted time instant k+j. As each leaf liis based on a di erent partition of Xd, ji;0and ji;nare also di erent for each leaf. Preliminary results suggested that the proposed ap- proach leads to weak prediction performance in the case ofj>3. This can be explained by the high dimension- ality of the ﬁtting process for bigger prediction steps in combination with a limited amount of samples of pairs (xu;yj) in each leaf li. We therefore model the predicted temperature in the jthstep as x(k+j)= ji;0+ ji;1jX n=1u(k+n1)+e;(2) in which the dimension of jiis reduced to 2 for all j. This approach is less realistic than eq. (1), as u(k) will have the same e ect on x(k+j) asu(k+j1) has, whereas one would expect the e ect of earlier time steps to be weaker. However, preliminary experiments suggested that the advantage of better model ﬁts out- weighs the disadvantage of a less realistic model. We can rewrite eq. (2) as x(k+j)= ji[1;u(k);:::;u(k+j1)]T+e;(3) with jibeing a row vector of dimension j+1.1In the case where random forests are used instead of regres- sion trees, the average of all relevant jiis taken, giving rise to j. 2.4. MPC-like use of DPC model The learned jcan be used to perform conventional receding horizon MPC. The corresponding convex opti- mization scheme follows minimize u;N1X j=0uT k+jRuk+j+k+j+1 subject to xk+j= j[1;u(k);:::;u(k+j1)]T xmink+jxk+jxmax+k+j u2U 0 j=1;:::;N(4) 1The dimensions of jiandu(k);:::;u(k+j1) of course change if multiple rooms are considered because in that case also x(k+j) becomes a vector. Figure 1: NEST building with controlled residential unit UMAR marked in white c Zooey Braun, Stuttgart in which Randdenote costs for control inputs and constraint violations, is a slack variable for the com- fort constraint, xminandxmaxdenote the comfort con- straints and Udeﬁnes the set of allowed control inputs. The algorithm for the online phase of the DPC con- troller is shown in 1. Algorithm 1 1:procedure DPC controller (online ) 2: fork in runtime do 3: forj in1;::;Ndo 4: ﬁnd all leaves liin forest jbased on current state and predicted disturbances xd(k) 5: construct jby averaging over all jiin all found li 6: solve optimization problem (4) 7: apply u(k) to the system 3. Case study 3.1. General description The controlled apartment is a residential unit in the NEST demonstrator building at Empa in Switzerland (Richner et al., 2018) and is marked in Figure 1. A schematic of the layout is shown in Figure 2. On the left and right side, the apartment features two nearly identical bedrooms that both have a ﬂoor area of 17.6 m2and a large window front that faces east-southeast. The right room is controlled by the DPC controller pre- sented in this study, the left room is controlled by a hysteresis controller. The whole apartment is equipped with combined heating and cooling ceiling panels that are operated with water. In the cooling case (present in 3 NDPC On/OﬀFigure 2: Layout of the controlled building unit this experiment) the water has a constant supply temper- ature of 18C. The amount of transferred heat is con- trolled by an individual open /closed valve in each room. The hysteresis-controlled room was occupied during the experiment, the DPC-controlled room was unoccupied. (This was switched in the validation experiments in Ap- pendix A.) 3.2. Controller set-up The applied DPC algorithm uses as inputs autoregres- sive terms and the forecast ambient temperature and so- lar radiation from the Federal O ce of Meteorology and Climatology (MeteoSwiss), the time of the day encoded in a sinus and cosinus function and autoregressive terms of the room temperature and neighbouring rooms with =16.2We use a forest of T =200 trees with a mini- mum amount of 200 historical samples in each leaf. The forest is trained on 10 months of historical measurement data, sampled in a 10-minute interval. Instead of abso- lute room temperatures x, we use the approach to model and predict temperature changes x. This does not fun- damentally change the algorithm but led to better pre- diction performance in preliminary experiments. More- over, we use sample weighting in the historical mea- surement data set to train the forests in order to adjust the importance of individual samples based on their lo- cation in the input space. The prediction horizon is N =6 with a sampling time of one hour, the cost per squared unit of cooling is R =1 and the cost per unit of com- fort constraint violation is =100. The comfort con- straints are 22-23C during the night (8.00 pm to 8.00 am) and 22-25C during the day (8.00 am to 8.00 pm).3 2This number might seem excessive, however, additional inputs do not a ect the ﬁtting process of regression trees negatively, as unimpor- tant inputs do not get chosen as splitting /partitioning variables. 3This is done to allow a better assessment of the predictive capabil- ities of the controller and to simulate a situation where the occupants are out-of house (e.g. at work) during the day.Measurements of the autoregressive terms and weather forecasts are queried via a Python-SQL-client from a database, the DPC algorithm is implemented in Python 3 using Scikit-learn (Pedregosa et al., 2011), communi- cation with the actuators in the building is established via a Python-OPC UA client. The hysteresis controller works in the following way: It switches on when the upper DPC constraint is reached, it switches o when the temperature is 1 C below the upper constraint. We do not force the hysteresis controller to cool down until the lower DPC constraint as this would result in a much higher en- ergy consumption for the hysteresis controller and non- comparable average room temperatures. The connec- tion to the database and actuators is established the same way as for the DPC controller. 4. Results and Discussion Figure 3 shows the results for a six-day experiment from 2019-06-20 2.00 pm until 2019-06-26 2.00 pm in the apartment with a cooling demand. The bottom two graphs show the ambient conditions measured at the roof-top of the building. It can be seen that ambi- ent temperatures between 13.7 and 39.5C and solar radiations between 0 and 1310 W /m2(which is unreal- istic due to the use of a non-calibrated sensor, but irrel- evant as the used approach is data-driven) are present during the time of the experiment. The conditions allow a good estimation of the controller performance as the experiment covers the range from mild cooling on 06- 22 with a maximum daily temperature of 22.7C and heavy cooling (to the cooling system’s limit) at the end of the experiment with a maximum daily temperature of 39.5C. The top graph of Figure 3 shows the trajectory of the room temperatures (with a quantisation of 0.15C) for the DPC-controlled room in blue, and the hysteresis- controlled room in dashed orange. The DPC comfort constraints are plotted in grey. First, it should be noted that the rooms indeed show very similar dynamics. For example, in the middle of day 06-24 (marked by the sec- ond grey period in the ﬁgure), where cooling is switched o in both rooms and the constraint jumps to 25C, the temperatures follow the same upwards trend. This ob- servation is conﬁrmed by the validation experiments in Appendix A. It can be seen that the DPC controller shows much less constraint violations than the hysteresis controller. More speciﬁcally, the integral of the constraint viola- tions is 72.0 % smaller in the DPC case. This is to be expected as the hysteresis controller has no predictive 4 2019-06-21 2019-06-22 2019-06-23 2019-06-24 2019-06-25 2019-06-2622232425Room temperature in °Cconstraints DPC OnOFF 2019-06-21 2019-06-22 2019-06-23 2019-06-24 2019-06-25 2019-06-260.00.51.0Relative control inputDPC OnOFF 2019-06-21 2019-06-22 2019-06-23 2019-06-24 2019-06-25 2019-06-260.00.51.0Relative integrated control inputDPC OnOFF 2019-06-21 2019-06-22 2019-06-23 2019-06-24 2019-06-25 2019-06-26203040Ambient temperature in °C 2019-06-21 2019-06-22 2019-06-23 2019-06-24 2019-06-25 2019-06-26 Timestamp05001000Solar radiation in W/m2Figure 3: DPC cooling experiment results capabilities and only starts cooling once it hits a con- straint. But it also shows that the prediction accuracy of the DPC-model is accurate enough to start cooling early during the day in order to not violate the upper comfort constraint during the night: The temperature trajectory in the DPC controlled room exactly meets the lowered temperature constraint at 8.00 pm on all days except 06- 25. On the evening of 06-25 the constraint is not met because the cooling system operated at it’s maximum capacity with a maximum ambient temperature of 39.5 C on that particular day and an ambient temperature of still 34.6C at 8.00 pm (fourth grey period in the ﬁg- ure). This issue could possibly addressed with a longer prediction horizon to allow pre-cooling. During night time, the temperature in the DPC-controlled room staysclose to the upper constraint most of the time. This is desirable for a predictive controller in the cooling case because it minimizes the control input. The second graph of Figure 3 shows the control input (relative between minimum cooling capacity of 0 and maximum of -0.6 kWh /h) during the experiment. It can be seen that the hysteresis controller uses much more cooling energy than the DPC-controller. This is partly due to always cooling until the room temperature is one degree below the upper comfort constraint. However, the average temperature in the DPC-controlled room is only 0.1C above the hysteresis-controlled room, which is in the range of the quantisation error of the tempera- ture sensor. This shows that the cooling energy savings are not due to a higher average room temperature. Over 5 the course of the whole experiment, the DPC-controller saved 24.9 % cooling energy compared to the hysteresis controlled room, as can be seen in the middle graph that shows the relative integral of the control input. Both top graphs show two more areas with grey back- ground. In the ﬁrst period between 06-22 and 06-23 the controllers lost connection to the actuators multiple times, which caused the valves in the cooling system to open and close multiple times - thus the part load in the hysteresis controlled room. In the third period on 06-26, the windows were opened in both rooms for a period of 10 minutes. This automatically switches o cooling and together with an ambient temperature higher than the room temperature resulted in a slight increase in room temperature. 5. Conclusion Data Predictive Control in buildings constitutes an at- tempt to lower the e ort for model development and maintenance for predictive thermal building control. Despite good simulation results there is no practical ex- perience in real life cases for room temperature control between comfort constraints and minimization of cool- ing or heating input with such methods so far. Here, we apply a DPC approach based on Random Forests with ane functions and convex optimization to temperature control in a real life residential apartment and compare the controller to a conventional hysteresis controller. The temperature in the room controlled by DPC shows 72.0 % less integrated comfort constraint violations than in the room controlled with hysteresis-control. More- over, the DPC controller saves 24.9 % of cooling energy. The experiment constitutes a promising ﬁrst real life ap- plication of the algorithm. A comparison to other con- trol approaches and the investigation of di erent pre- diction horizons and sampling rates as well as experi- ments regarding heating are part of ongoing and future research. Acknowledgements We would like to thank Kristina Orehounig, Viktor Dorer and Roy S. Smith for their valuable help and support. We are also grateful to Annika Eichler, Ben- jamin Flamm, Andrea Iannelli, Mohammad Khosravi, Je rey Lungthok, Anil Parsi, Nicolas Schmid, Bratislav Svetozarevic, Christoph Waibel, Joseph Warrington and Suli Zou for fruitful discussions. Moreover, we would like to thank Reto Fricker, Ralf Knechtle and SaschaStoller for sharing their expertise and help with the im- plementation, and Spyros Georgakos for showing pa- tience and engagement with our experiments. This research project is ﬁnancially supported by the Swiss Innovation Agency Innosuisse and is part of the Swiss Competence Center for Energy Research SCCER FEEB&D. Conﬂict of interest None. Appendix A. Validation experiments We have conducted two experiments from 2019-05- 31 0.00 am to 2019-06-06 0.00 am (validation exper- iment 1) and 2019-06-15 0.00 pm to 2019-06-20 0.00 pm (validation experiment 2) before the experiment de- scribed in the main body of this article. The results, shown in Figure A.4 and Figure A.5 respectively, were not used as the main result for this study because both DPC and hysteresis controller were not yet operating totally correct: The DPC controller sometimes saw the lowered upper constraint at 8.00 pm too late because the optimization was performed at 1.59 pm instead of 2.00 pm, resulting in increased constraint violations. The hysteresis controller sometimes started cooling before hitting the upper constraint. However, these results are suitable to conﬁrm 1. that the thermal dynamics of both rooms are indeed very similar: validation experiment 1 and 2 were performed with the DPC controller operating in the left room and the hysteresis controller operating in the right room in contrast to the main experiment; and 2. that the order of magnitude of energy savings is realistic and the pre- sented main result is not a best-case example. In valida- tion experiment 1 the energy saving amounted to 31.9 % and in validation experiment 2 to 29.7 %, both com- pared to the respective hysteresis controller. The di er- ence in average room temperature was less than 0.05C in both experiments. The integrated constraint violation was reduced by 74.8 % and 79.7 % respectively.