## 4 HVAC Control
### Design of the MPC  
The proposal is to implement a control system, with a dedicated unit for each room, based on an MPC approach. The controller is nonlinear, and the constraints are explicitly handled [58]. According to the receding horizon principle, at each time step, the MPC algorithm computes the optimal temperatures solving a finite horizon optimization problem. For the formulation of the MPC, a prediction horizon \(\big{[}t,t+N_{p}\big{]}\) is considered at time \(t\). The notation \(x_{t+k|t}\) represents the state vector at time \(t+k\), predicted at time \(t\), obtained by starting from the current state \(x_{t|t}=x(t)\equiv x_{t}\), and where \(u_{.|t}=\big{[}u_{t|t},\ldots,u_{t+N_{p}-1|t}\big{]}\) denotes the unknown input variables to be optimized. The control system aims to achieve the target comfort temperature in each room, while satisfying the state and input constraints. So, for a particular room \(i\), the state variable is the temperature \(T^{i}_{k|t}\) and the unknown input variable to be optimized is the thermal load introduced by the HVAC system \(\dot{Q}^{i}_{k|t}\). Therefore, the optimization problem for the temperature controller can be formulated in (11):  
\[\underset{\dot{Q}_{.|t}}{\min}J\bigg{(}T^{i}_{k|t},\dot{Q}^{i}_{k|t},\Delta T^ {i}_{k|t}\bigg{)} \tag{11}\]  
subject to:  
\[T^{i}_{t|t}=T^{i}_{t} \forall i=1,\ldots,N_{e} \tag{12}\] \[T^{i}_{k+1|t}=T^{i}_{k|t}+\sum_{j=1}^{K}\omega_{j}\Delta tf \bigg{(}T^{i}_{k,j|t},\dot{Q}^{i}_{k,j|t}\bigg{)} \forall k\in\big{[}t,t+N_{p}-1\big{]}\ \forall i=1,\ldots,N_{e}\] (13) \[f\bigg{(}T^{i}_{k|t},\dot{Q}^{i}_{k|t}\bigg{)}=\bigg{(}A^{i}+B^{ i}T^{i}_{k|t}+\dot{Q}^{i}_{k|t}\bigg{)}/M^{i} \forall k\in\big{[}t,t+N_{p}-1\big{]}\ \forall i=1,\ldots,N_{e}\] (14) \[\dot{Q}^{i}_{ref}\leq\dot{Q}^{i}_{k|t}\leq\dot{Q}^{i}_{heat} \forall k\in\big{[}t,t+N_{p}-1\big{]}\ \forall i=1,\ldots,N_{e}\] (15) \[T^{i}_{k|t}-\Delta T^{i}_{t}\leq T^{i}_{ref}\ with\ \Delta T^{i}_{t}\geq 0 \forall k\in\big{[}t,t+N_{p}-1\big{]}\ \forall i=1,\ldots,N_{e}\] (16) \[T^{i}_{N_{p}|t}-\Delta T^{i}_{t}\leq T^{i}_{ref} \forall i=1,\ldots,N_{e} \tag{17}\]\[(1-\alpha)M^{i}\leq M^{i}\leq(1+\alpha)M^{i} \forall i=1,\ldots,N_{e} \tag{18}\] \[-\delta\mathrm{T}\leq w_{T_{ext}}\leq\delta\mathrm{T} \tag{19}\]  
In this optimization problem, \(N_{e}\) is the number of air-conditioned rooms in the dwelling, and \(N_{p}\) is the prediction horizon. The state \(T^{i}_{i|t}\) at time \(t\) is initialized with the actual temperature of the room \(T^{i}_{t}\), as seen in Equation (12). Then, future states are obtained with Equation (13), which follows a linear discretization approach of Equation (10). It should be noted that hard constraints are used for the input variables in this optimization problem; whereas, soft constraints are used for the state variables. A hard constraint from Equation (15) limits the input variable \(\dot{Q}^{i}_{k|t}\), between the maximum refrigeration \(\dot{Q}^{i}_{ref}\) and heat \(\dot{Q}^{i}_{heat}\) thermal loads. Moreover, Equation (16) bound the temperature of the room, where \(T^{i}_{k|t}\) (K) is the estimated temperature of the controlled room at instant k calculated at time \(t\), and \(T^{i}_{ref}\) is the temperature objective to be reached. This is a soft constraint where Equation (16) penalizes, exceeding the maximum speed through the positive slack variable \(\Delta T^{i}_{t}\). The terminal constraint in Equation (17) serves as an operational constraint. In addition, for the real-time MPC, as it is designed in a robust scenario-based MPC that considers uncertainties in the design parameters and disturbances in the inputs, the following constraints are added. Equation (18) includes the uncertain in the design parameters considered in the model. In this way, an uncertainty has been considered in the evaluation of the thermal inertia of the building (18), where \(\alpha\) is the deviation from the nominal value of thermal inertia expressed as a percent of one.