Model Predictive Control: From forecasts to real-time optimization

This article explains how LEGOFIT is turning energy forecasts into real-time building optimization through Model Predictive Control (MPC). METU, IES and R2M Solution Spain are developing electrical and thermal MPC systems that use forecasted data to continuously optimize energy use, battery storage, heating and cooling performance, reducing costs while maintaining comfort and resilience. Together with the forecasting engine, these controllers form LEGOFIT’s intelligent layer for self-learning buildings, enabling residential pilots to become more efficient, more flexible, and potentially energy-positive.

Forecasting alone is not enough; it must be translated into optimal actions. This is the purpose of this task, where METU, IES, and R2M Solution Spain develop Model Predictive Control (MPC) strategies that use forecasted data to continuously optimize building performance.

Electrical MPC – led by METU and IES

The electrical MPC focuses on minimizing the building’s electricity bill and optimizing the use of Battery Energy Storage Systems (BESS) and other controllable assets such as heat pumps and boilers.
By using forecasts of load, PV generation, and energy prices, the controller dynamically calculates power setpoints for each device. It determines the optimal charge/discharge plan for the next horizon, ensuring energy efficiency, lower costs, and higher resilience.

This strategy operates in a closed control loop: forecasts feed the MPC every few minutes, the controller evaluates multiple actions, applies the best one, and re-optimizes as new data arrives. During disturbances or grid outages, the controller ensures continuity of service by supporting critical loads with the BESS.

“The MPC operates like a digital brain of the building. It continuously learns from new data and finds the optimal way to use energy assets, improving flexibility and self-consumption.”
Murat Göl, METU

Thermal MPC – developed by R2M Solution Spain

In parallel, R2M is developing the thermal MPC, which ensures indoor comfort while reducing heating and cooling energy use.
This controller uses a grey-box model of the building —combining physical and data-based parameters— to simulate thermal dynamics through Resistance–Capacitance (RC) equivalent networks. The MPC determines the optimal setpoints for HVAC operation (on/off, modulation level, or temperature targets) while respecting user-defined comfort limits and equipment constraints.

Key features include:

  • Moving Horizon Estimation (MHE) for real-time recalibration of the building model using measured data and occupancy patterns.
  • Closed-loop optimization that adjusts thermal setpoints based on weather forecasts, indoor/outdoor temperatures, and occupancy profiles.
  • Adaptive control that learns over time to reduce energy consumption without compromising comfort.

This approach also enables demand response actions, such as shifting or shaving heating and cooling loads, thereby supporting grid flexibility and reducing energy bills.

Towards intelligent, energy-positive homes

Together, the forecasting engine and the MPC controllers represent LEGOFIT’s intelligent layer for predictive and self-learning building operation.
By combining accurate forecasting with continuous optimization, LEGOFIT pilots will demonstrate how residential buildings can become energy-positive—producing more energy than they consume—while ensuring comfort and resilience.

These tools will be integrated into the pilot-s Building Management System (BMS), forming a closed data loop that links real-time monitoring, predictive control, and continuous improvement.

Ultimately, the innovations developed in WP4 pave the way for a new generation of smart, responsive buildings that play an active role in the clean energy transition.