Next Article in Journal
The Influence of Structural Design Parameters on the Retention Force and Interference-Fit Reliability of Connecting Rod Bushings
Next Article in Special Issue
Advances in Technologies for Energy Harvesting from Pavements: A Comprehensive Review
Previous Article in Journal
Assessment of Carbon Emission Reduction Benefits of Infrastructure Systems in Urban Underground Space Development
Previous Article in Special Issue
A Study on the Reduction of Light Load Loss in the Standalone Operation of LDC in Integrated Charging System for Electric Vehicles with 2-Transformer
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Practical Considerations for the Development of Two-Stage Deterministic EMS (Cloud–Edge) to Mitigate Forecast Error Impact on the Objective Function

by
Gregorio Fernández
1,*,
J. F. Sanz Osorio
2,
Roberto Rocca
1,2,
Luis Luengo-Baranguan
1 and
Miguel Torres
1
1
Department of Electrical Systems, CIRCE Technology Centre, 50018 Zaragoza, Spain
2
Instituto de Investigación Mixto de la Energía y la Eficiencia de los Recursos de Aragón, ENERGAIA, Universidad de Zaragoza-Fundación CIRCE, 50018 Zaragoza, Spain
*
Author to whom correspondence should be addressed.
Appl. Sci. 2026, 16(4), 1844; https://doi.org/10.3390/app16041844
Submission received: 5 December 2025 / Revised: 3 February 2026 / Accepted: 5 February 2026 / Published: 12 February 2026

Abstract

The growing penetration of Distributed Energy Resources (DERs)—such as photovoltaic generation, battery energy storage, electric vehicles, hydrogen technologies and flexible loads—requires advanced Energy Management Systems (EMS) capable of coordinating their operation and leveraging controllability to optimize microgrid performance and enable flexibility provision to the grid. When the physical, electrical, and economic system model is properly defined, the main sources of performance degradation typically arise from forecast uncertainty and temporal discretization effects, which propagate into sub-optimal schedules and infeasible setpoints. This paper proposes and tests a two-stage deterministic EMS architecture featuring rolling-horizon planning at an upper layer and fast local setpoint adaptation at a lower layer, jointly to reduce the impact of forecast errors and other uncertainties on the objective function. The first stage can be deployed either on the edge or in the cloud, depending on computational requirements, whereas the second stage is executed locally, close to the physical assets, to ensure timely corrective action. In the simulated cloud-executed planning case, moving from hourly to 15 min granularity improves the objective value from −49.39€ to −72.12€, corresponding to an approximate 46% reduction in operating cost. In our case study, the proposed second-stage local adaptation can reduce the mean absolute error (MAE) of the EMS performance loss by approximately 50% compared with applying the first-stage schedule without local correction. Results show that this two-stage hierarchical EMS effectively limits objective-function degradation while preserving operational efficiency and robustness.

1. Introduction

The electric power system is undergoing a profound transformation driven by the fast and widespread penetration of DERs—including photovoltaic (PV) generation, battery energy storage systems (BESS), electric vehicles (EVs), hydrogen-based technologies, and flexible loads—together with the electrification of technologies that were traditionally supplied by thermal processes. This change is pushing distribution grids toward the smart grid concept, with bidirectional flows, active prosumers, local energy communities, and an unprecedented density of manageable devices [1,2]. This creates new opportunities, but it also introduces significant operational challenges: increased variability and uncertainty due to weather-dependent generation, voltage, and congestion problems at the distribution-grid level, more complex interactions between transmission and distribution systems, and the need to coordinate large amounts of small assets, on some occasions in (near) real time. A response to these challenges can be the concept of flexibility, which refers to the capability of different assets to adjust their consumption or generation profiles in response to external signals, such as prices, grid constraints, or system needs [3,4,5]. Flexibility can be leveraged for two complementary objectives: internally, to optimize the operation of the customer’s facilities (e.g., minimizing operating costs, maximizing self-consumption, or reducing pollutant emissions), and externally, to provide support services to grid operators [6].
To unlock this flexibility in a systematic, scalable, and reliable way, modern installations require advanced control and optimization layers that can translate physical, electrical, and economic models into actionable control decisions. In this context, Energy Management Systems (EMS) and Model Predictive Control (MPC) frameworks play a central role as the “brain” of flexible assets [7]. An EMS is generally responsible for supervising and optimizing the operation of a specific energy system—such as a building, microgrid, industrial site, or aggregated portfolio of assets—by scheduling controllable resources over an optimization horizon while enforcing technical and operational constraints. MPC provides a rigorous formulation for EMS operation, solving a finite-horizon optimization problem in a receding-horizon way, using updated measurements and forecasts of demand, renewable generation, or energy prices to compute optimal setpoints that are then applied to the real system [8].
In practical implementations of EMS and MPC, several families of optimization techniques can be used, ranging from deterministic methods—such as linear programming (LP), quadratic programming (QP), convex nonlinear programming and mixed-integer formulations (MILP/MIQP)—to heuristic and metaheuristic approaches, including genetic algorithms, particle swarm optimization, simulated annealing, tabu search, or evolutionary strategies [9]. Exact or deterministic methods exploit the algebraic structure of the problem by operating on a well-defined cost function and constraints to return a proven optimum (for LP/QP/convex problems) or a sub-optimal solution with a certified optimality gap (for MILP/MIQP and many non-convex cases) [10,11]. This approach offers several advantages in the context of EMS/MPC. First, constraint satisfaction is guaranteed by construction, which is critical when constraints represent thermal limits, state-of-charge ranges, or comfort and process quality requirements [12]. Second, deterministic solvers ensure reproducibility of results; re-solving the same problem with the same inputs yields identical solutions. Third, they provide valuable by-products such as dual variables, sensitivities, and reduced costs, which can be used to analyze congestion, marginal values of flexibility, or to derive simplified rules for asset sizing and flexibility assessment. Finally, modern LP/MILP solvers are now fast and robust enough for rolling-horizon execution with granularities of 5–15 min [13]. Notably, when the physical and economic models are well calibrated, research suggests that the primary source of performance degradation in MPC-based EMS is the forecast error in exogenous inputs, such as load or prices [14,15,16].
In contrast, heuristic and metaheuristic methods are advantageous when problems are poorly structured, highly non-convex, or treated as black boxes. Both methods are often easy to implement, relatively tolerant to modelling imperfections, and can explore large combinatorial spaces using stochastic search. However, these methods do not guarantee optimality or feasibility. Their performance is sensitive to tuning parameters (such as population sizes, mutation rates, and cooling schedules) [9], and different executions may yield different solutions even with identical input data or models. These characteristics are problematic in EMS/MPC applications.
Furthermore, research in MPC and hybrid systems shows that, when the dynamics and constraints of the system are correctly modelled, quadratic and mixed-integer formulations can enforce hard operational limits while providing stability and performance guarantees [12]. In the energy domain, compact MILP formulations, initially developed for unit commitment, show that large-scale problems can be solved with certified optimality gaps and practical computation times, provided the model is tightly formulated [17]. This synergy between feasibility, optimal control, and interpretability is challenging to replicate with purely heuristic approaches, whose convergence and solution quality are more difficult to certify in safety-critical and grid-connected environments.
The versatility of deterministic optimization for EMS is demonstrated by its successful deployment across residential, commercial, and industrial sectors, in both grid-connected and islanded configurations, utilizing a broad range of technologies, including PV, batteries, EVs, and hydrogen systems. In the residential sector, mixed-integer formulations have been used to optimize appliance and EV scheduling under real-time prices [15], to implement day-ahead home energy management with PV and batteries, including degradation-aware operation [18], and to extend the same principles to community Energy Management Systems with peer-to-peer energy trading [19]. Similar MILP-based approaches have been demonstrated for off-grid homes with PV/BESS, showing that deterministic scheduling can reduce operating costs while extending battery life [20]. Additionally, they have been applied to multi-objective HEMS that coordinate PV, storage, EVs, and hydrogen production/consumption in vehicle-to-home/grid setups [21]. In commercial buildings, deterministic MILP and QP-based MPC have been shown to optimize HVAC plants and multi-zone climate control while respecting comfort constraints [22,23]. Field studies confirm that MPC with deterministic solvers can reliably deliver demand flexibility and cost savings in large office buildings [24]. At a larger scale, MILP-based distributed energy management has been applied to interconnected microgrids [25], industrial parks and other areas with integrated energy systems [26], district heating [27], industrial facilities [28], and microgrids that combine short-term battery storage with long-term hydrogen storage [29,30]. Collectively, these examples demonstrate that deterministic optimization methods are not only theoretical but a practical and scalable option for EMS/MPC in real DER systems, capable of handling mixed technologies and operating modes while providing the transparency and reliability essential for both internal optimization and external grid-support services.
Deterministic, optimization-based EMS and MPC formulations not only provide high-quality operating schedules but also serve as a powerful analytical framework for deriving simplified design rules and characterizations of flexibility that can be used in planning and market participation. Joint sizing and operation studies for microgrids and integrated energy systems employ MILP techniques that are essentially identical to those used for EMS, extended to include investment variables and long-term horizons [31]. By co-optimizing investment (PV capacity, BESS energy and power ratings, hydrogen storage size) alongside operational decisions, these models reveal marginal values and binding constraints that yield practical sizing guidelines (e.g., BESS energy-to-power ratios or PV-to-load ratios) [32]. Similar HEMS/CEMS formulations have been utilized in both grid-connected and off-grid settings, demonstrating that the same deterministic core can be parameterized to explore alternative technology combinations and obtain techno-economic envelopes for residential and community systems incorporating PV, BESS, EVs, and hydrogen [33]. Regarding flexibility, recent research demonstrates that flexibility “products” (upward/downward capacity, duration, activation limits) can be directly inferred from families of optimal trajectories computed by MPC/EMS under different price and constraint scenarios. This leads to the creation of flexibility envelopes and key performance indicators (KPIs) grounded in the same deterministic optimization framework used in daily operations [34,35,36]. Furthermore, data-driven methods leveraging these optimization outputs can expedite flexibility quantification by training surrogate models on deterministic EMS runs. This approach preserves the physical consistency and interpretability inherent in the underlying optimization framework [37].
The deterministic EMS/MPC framework can be seamlessly integrated with local flexibility markets (LFMs) and peer-to-peer (P2P) energy platforms by incorporating market outcomes—such as accepted bids, activation volumes, and negotiated exchanges—as additional constraints or targets within the optimization horizon. Systematic reviews of European LFMs describe clear information flows from market platforms to aggregators and local controllers, where accepted flexibility offers are translated into activation quantities and time windows that an EMS must satisfy [38,39]. Similarly, in P2P and transactive energy models, the clearing engine determines agreed energy exchanges and prices among peers, which are subsequently embedded as equality or inequality constraints (e.g., scheduled imports/exports, minimum traded volumes) in deterministic EMS/MPC formulations at building, microgrid, or community level [40]. Real-world hierarchical (two-level) implementations, where remote solvers like GAMS 25.0.3/CPLEX 12.8.0.0 compute optimal 24–72 h schedules while local controllers adapt setpoints in real time, demonstrate that deterministic EMS can reliably incorporate market-driven setpoints. By reconciling these signals with local technical constraints, these systems provide a practical blueprint for market-integrated, flexibility-enabled operations [41].
When a complete physical and economic model of the system is available, and optimization is performed using exact deterministic methods (LP/QP/MILP/MIQP), a consistent pattern emerges [15]: the dominant source of performance degradation is not the optimizer itself, but rather the uncertainty in exogenous forecasts and data discretization. In building applications, studies on MPC for climate control explicitly show that, for a well-identified building model, the closed-loop performance is primarily driven by the accuracy of weather and load predictions rather than by limitations of the control algorithm [42]. This is reinforced by recent work that quantifies the value of information for building load forecasts: when the underlying model and MPC formulation are kept fixed, degrading the load forecast directly increases operating cost and distorts storage schedules, clearly identifying the forecast as the primary source of error [43]. Similar conclusions are obtained in simulation campaigns that inject realistic weather forecast errors into predictive controllers while keeping the microgrid model and optimization unchanged, observing significant increases in cost and discomfort compared to the ideal case with perfect forecasts [44]. In systems with large shares of variable renewable generation, wind and PV forecasting studies further confirm that forecast error distributions, especially infrequent but large deviations, are the primary driver of sub-optimal commitment and dispatch decisions when the network and unit models are otherwise accurate [45,46]. In parallel, reviews of electricity price forecasting emphasize that the difficulty of predicting prices translates directly into operational and arbitrage inefficiencies whenever deterministic optimization is used downstream [47].
The same separation between “perfect” optimization and imperfect information is also evident in microgrid and system-level studies. In microgrid EMS, stochastic MPC and stochastic security-constrained planning are introduced precisely because the main source of operational risk is the uncertainty in demand and renewable generation. At the same time, the network and device models are treated as fixed and reliable [48,49]. Rolling-horizon frameworks for joint energy supply and demand planning make this explicit: the deterministic formulation (constraints, cost function, physical model) is held constant, and performance improvements are achieved by periodically updating forecasts and re-optimizing, not by changing the underlying model [16]. Comparative studies on microgrid energy management demonstrate that, with a deterministic model and forecasts updated in a rolling horizon, economic performance can match or even surpass more complex uncertainty-modelling approaches, underscoring that forecast handling is the key lever once the model is well defined [50]. Fitted rolling-horizon control schemes follow a similar logic, utilizing repeated deterministic optimizations to compensate for forecast errors as new measurements become available [51]. Finally, real two-level EMS implementations—where remote deterministic optimization (e.g., GAMS/CPLEX) computes optimal 24–72 h schedules and local controllers adapt setpoints in real time—explicitly rely on updated demand, PV and price forecasts as the main source of variation between the planned and realized operation, while the physical/economic model and optimization method remain unchanged [52]. Together, these results support the claim that, once the system is correctly modelled and a complete deterministic optimizer is used, the principal—and in many practical cases, almost the only—source of operational error is the quality of the forecasts for demand, renewable generation, and energy prices.
Although references in the previous paragraphs have shown that rolling-horizon optimization and frequent forecast updates are effective ways to mitigate the impact of uncertainty in EMS/MPC, most studies focus on reporting improvements in cost, comfort, or reliability without explicitly analyzing how forecast errors degrade the value of the optimal objective compared to an ideal perfect-forecast benchmark [43]. Existing microgrid and building-control studies typically treat the choice of time step and optimization horizon as secondary design parameters; they may observe that finer granularity or shorter horizons improve robustness, but they do not systematically characterize how the combination of step size and horizon length shapes the gap between the theoretical optimum and realized performance under realistic forecast errors [50,51]. Likewise, hierarchical two-level implementations—where a remote optimiser computes day-ahead or multi-day schedules and local controllers adapt setpoints in (near) real time—have primarily aimed to demonstrate operational feasibility or the provision of grid-support services, rather than quantifying their ability to attenuate the degradation of the objective function induced by faulty forecasts [52]. In contrast, the present work explicitly uses the optimal objective value as a primary performance metric. It shows that a two-stage deterministic EMS—with a carefully selected granularity and horizon at the upper level, and a fast local corrective layer at the lower level—can measurably reduce the impact of demand, renewable generation, and price forecast errors on the achievable optimum, thereby providing a quantitatively grounded design guideline for cloud–edge EMS architectures. Another point that differentiates this work from previous ones is that, although the second EMS step is proposed to be located always on the edge, near microgrid manageable assets, the first one is proposed to be executed on the cloud, remotely, or locally on the edge, constantly adapted to the optimal calculation algorithm’s needs.
Although the time-scale mismatch between high-level energy management and fast physical dynamics has been widely acknowledged in the literature, this challenge remains unresolved, mainly in practical microgrid deployments. The root causes are structural: market-based scheduling, forecasting processes, and optimization-based EMS are typically formulated at coarse temporal resolutions to ensure tractability and robustness, while real-world generation, storage, and loads evolve at much faster time scales. Fully addressing this mismatch through multi-level or high-frequency optimization often leads to prohibitive computational complexity, increased modelling requirements, and limited feasibility for real-time or edge implementation. As a result, most operational EMS frameworks implicitly accept this mismatch and rely on simplified assumptions, leaving residual tracking errors and inefficiencies unaddressed. This work builds upon this observation and proposes a minimal yet practical two-stage architecture that explicitly targets the consequences of time-scale mismatch, rather than attempting to eliminate it, thereby improving robustness and operational performance under realistic constraints.
The rest of this paper is organized as follows. Section 2 presents the proposed two-stage deterministic EMS architecture, detailing the upper-level rolling-horizon optimization model, the local corrective control layer, and the simulation framework used to evaluate different granularities and execution platforms (cloud, edge, and mixed configurations). Section 3 presents the numerical results, divided into two parts: first, the effect of temporal granularity, forecast uncertainty, and execution platform on the objective function obtained by the upper-level optimization; second, a quantitative assessment of discretization error and its compensation through fast local adaptation using real high-resolution PV data. Section 4 provides a comprehensive discussion of the results, highlighting the trade-off between granularity, computational needs, and local corrective capability, and analyzing the implications for practical cloud–edge EMS deployments. Finally, Section 5 summarizes the main conclusions and outlines future research directions regarding adaptive temporal resolution and the co-design of forecasting, optimization, and edge-level control.

2. Methodology

In this work, a hierarchical two-stage EMS architecture is proposed to coordinate the operation of complex microgrids with multiple DERs (see Figure 1). The upper or first stage is devoted to calculating optimal set-points over a multi-day optimization horizon (three days in the case study, but can be adapted to every case), typically with an economic objective such as minimizing operating costs, maximizing self-consumption, or reducing emissions under technical and operational constraints. This stage aggregates forecasts of demand, PV generation, EV availability, energy prices, and other variables, and applies them to detailed models of PV, BESS, hydrogen systems, and grid interaction, forming a deterministic optimization problem (e.g., LP/QP/MILP/MIQP) that is solved in a rolling-horizon framework. From a functional point of view, Stage 1 acts as the planner: it produces a time-stamped schedule (set-points) for the main controllable assets (e.g., BESS charge/discharge, EV charging power, H2-related set-points, and grid exchange where applicable), to be followed during the next control interval until the next re-optimization. In the rolling-horizon implementation, this planning step is periodically repeated using updated measurements and refreshed forecasts, so that forecast mismatches do not accumulate over long horizons. The second or lower stage acts as a corrective layer that adapts these scheduled set-points (calculated in the first stage) to the actual state of the microgrid and applies them to the physical devices, compensating for forecast errors, discretization effects, and device-level anomalies while preserving the main optimization objectives. Functionally, Stage 2 is a fast tracking and feasibility layer: it runs at a higher refresh rate than Stage 1, uses local measurements to compute the deviation between scheduled and real operation, and updates the real-time set-points sent to the devices to (i) enforce hard constraints (e.g., SoC and power limits) and (ii) keep the operation as close as possible to the planned objective. In this way, uncertainty is turned into small local corrective actions rather than objective-function degradation or constraint violations. Main uncertainty sources in deterministic EMS deployments include: (i) forecast errors in exogenous inputs (load, PV generation, energy prices and EV availability/demand), (ii) structural discretization error introduced by coarse time steps, and (iii) unexpected device-level events (e.g., unavailability, communication/actuation issues, or model/parameter mismatch). The proposed two-level EMS compensates these uncertainties through two complementary principles: (1) rolling-horizon recurrent re-optimization at the upper layer to continuously refresh the plan as new data arrive, and (2) fast local closed-loop setpoint adaptation at the lower layer to correct residual mismatches between re-optimizations and preserve feasibility.
Unlike many existing hierarchical EMS implementations, where the computation platform of each control layer is fixed a priori (for example, day-ahead optimization always in the cloud and local control always at the edge), the present architecture explicitly decouples the functional role of the first stage from its execution platform. The second stage is assumed to run on local edge controllers, as close as possible to the microgrid assets, to guarantee fast reaction, high availability, and independence from external communication links. In practice, this lower-layer placement is critical (and effectively mandatory) because it operates on sub-minute time scales, directly interfaces with measurements and actuators, and must remain available to enforce hard constraints even under communication delays or cloud connectivity loss. By contrast, the first stage is designed to be deployable either remotely in the cloud or locally on an edge or on-premise server. The choice between cloud, edge, or hybrid cloud–edge execution depends on the complexity of the optimization problem (system model, granularity, horizon, and number of assets) and the available computational resources on each platform [53]. Cloud execution typically offers higher computational power and more effortless scalability at the expense of additional communication latency and dependence on connectivity, while edge execution reduces latency and increases resilience but must respect more strict constraints on CPU, memory, and execution time; hybrid arrangements seek to combine both advantages by placing heavy optimization tasks in the cloud and fast corrective control at the edge. Overall, the combined use of both stages mitigates uncertainty through two complementary mechanisms: Stage 1 reduces the planning error via rolling-horizon re-optimization with updated data, while Stage 2 reduces the tracking error by closing the loop locally and compensating residual mismatches between re-optimizations.

2.1. Stage 1—Microgrid Optimization

To carry out the tests shown in Section 3.1, a general microgrid model was developed, featuring solar photovoltaic installations for energy generation (or other renewable energy sources, such as wind or hydro), BESS, EV charging points, hydrogen systems, and energy consumption points, both manageable and non-manageable (Figure 2). This general microgrid model is tailored to the target installation through a configuration file that specifies the existing devices, as well as the grid’s connected or isolated operation, the integration of DC or AC elements, and other operational aspects, such as the possibility of feeding energy back into the grid.
The main operational characteristics of the microgrid components (power, storage capacity, efficiency, etc.) are incorporated through another configuration file. Forecasts (such as solar generation, energy prices, and energy demand) that largely determine the system’s performance are integrated through a forecasts file. This file also includes forecasts of equipment availability, enabling the calculation and generation of setpoints to adapt to the microgrid’s state from the first level of the EMS, a function not all examples seen in the literature incorporate.
This optimization algorithm has been programmed in the PYTHON environment, using the following main libraries:
  • PYTHON, version 3.9;
  • PANDAS, version 2.3.3;
  • NUMPY, version 2.0.2;
  • ORTOOLS, version 9.14.6206, and SCIP as backend solver.
It is worth noting that this optimization code has been successfully tested in various execution environments, including cloud and edge environments, as well as in different real-world microgrids [54,55].
The following paragraphs summarize the mathematical model implemented, and Appendix A lists all the parameters and variables used in this model.
  • Objective function:
In this case, the objective function (1) minimizes the operating and maintenance costs of the system components, including electric batteries, EV charging, the H2 system, and grid connection.
min C o s t b a t + C o s t e v + C o s t h 2 + C o s t g r i d
where Costbat represents the costs associated with battery operation and management (2), Costev are the costs associated with charging electric vehicles (3), Costh2 are the costs associated with the hydrogen system (4), and finally Costgrid are the costs of buying and selling electricity from the grid (5).
The first term of the sum in Equation (2) allows for the imputation of the usage cost of batteries. The second term is a mathematical artifice to penalize highly variable charges or discharges. The alpha term is minimal, so it has no decisive effect on the result, but it does prevent peaks in charging or discharging due to non-homogeneous or time-varying processes.
C o s t b a t = t = 0 n b a t c o s t · T · b a t p o w e r d i s c h a r g e t + α b a t · b a t p o s c h a r g e t + b a t p o s d i s c h a r g e t + b a t n e g c h a r g e t + b a t n e g d i s c h a r g e t
The first term of Equation (3) allows for the imputation of the usage cost of EV batteries, which is essential in V2G operation modes. The second term provides for imputing incomes from the sale of energy to EVs at charging stations, for example, in the case of private or domestic facilities, this cost would be zero. The last term, as in the case of the BESS, is a mathematical artifice to avoid an irregular or peaky charging or discharging process.
In this work, battery and electric vehicle operational costs are modelled as an equivalent cost per unit of energy throughput, derived from the asset investment cost, nominal capacity, and expected lifetime, to account for degradation effects within an operational optimization framework.
The first term of the sum in Equation (4) allows us to calculate the cost of using the hydrogen facility, both for the electrolyser and the fuel cell. The second term provides for calculating the costs of charging the hydrogen storage facility using external means, specifically a truck. The last term allows us to calculate the revenue from supplying hydrogen to vehicles.
Equation (5) represents the costs associated with the interaction between the microgrid and the external electricity network. The first term represents the contracted power charge, while the second term accounts for the variable cost of energy imported from or exported to the grid. Although the contracted power charge can be fixed and therefore does not affect the optimization result, it is retained to preserve the generality of the model, as contracted power may become a decision variable in demand-side management, flexibility-oriented, or system sizing applications.
C o s t e v = t = 0 n e v c o s t · T · e v p o w e r c h a r g e t e v i n c o m e · T · e v p o w e r c h a r g e t + α e v · e v p o s c h a r g e t + e v p o s d i s c h a r g e t + e v n e g c h a r g e t + e v n e g d i s c h a r g e t
C o s t h 2 = t = 0 n h 2 c o s t · e l z p o w e r t + f c p o w e r t · T + t r u c k h 2 c o s t · t r u c k h 2 a v a i l a b i l i t y t f c e v m a s s t · h 2 i n c o m e
C o s t g r i d = t = 0 n g r i d p o w e r c o s t · g r i d p o w e r m a x + g r i d c o s t t · g r i d p o w e r b u y t g r i d i n c o m e t · g r i d p o w e r s e l l t · T
  • Assets DC interconnection:
The main constraint of the system, in this example, is the energy balance in the DC grid of the system. Equation (6) has been established based on Kirchhoff’s law, considering the efficiencies of the different system elements and their connections to the DC grid. In the equation, it can be seen that power flows are affected by the converter’s efficiency.
g r i d p o w e r b u y t · a c c o n v e f f i g r i d p o w e r s e l l t A C c o n v e f f i l o a d s ( t ) · d c c o n v e f f i = p v p o w e r u s e d t · p v c o n v e f f i b a t p o w e r d c h g t · b a t c o n v e f f i + b a t p o w e r c h g t b a t c o n v e f f i + E V p o w e r c h g t E V c o n v e f f i f c p o w e r t · h 2 c o n v e f f i + e l z p o w e r t h 2 c o n v e f f i
  • Solar PV generation:
Equation (7) determines the maximum and minimum power that can be extracted from the photovoltaic installation at any given time ( P V p o w e r u s e d t ), while Equation (8) determines the power that can be extracted at each moment of the simulation, which is always less than or equal to the estimated prediction ( P o w e r P V ( t ) ).
0 P V p o w e r u s e d t P V p o w e r m a x
P V p o w e r u s e d t P o w e r P V ( t )
  • BESS:
Equation (9) indicates that the initial charge state of the batteries is entered as input data into the optimization process.
Equation (10) represents the maximum and minimum operating capacity of the battery. If a minimum capacity is set (e.g., 10% of SoC), this is reflected in the batsoc_min parameter.
On the other hand, Equations (11) and (12) determine the maximum and minimum charging power of the battery. Equation (13) prevents the battery from being charged and discharged simultaneously, and Equation (14) sets the battery’s state of charge for the following period, considering the state of charge associated with the charging and discharging power for that period.
Finally, Equations (15)–(18) add up the power difference between the different periods. The variables b a t p o s c h a r g e t and b a t p o s d i s c h a r g e (t) count the positive difference, and b a t n e g c h a r g e (t) and b a t n e g d i s c h a r g e (t) count the negative difference. In all cases, the variables are binary. These values are used in (2) to avoid an irregular or peaky charging or discharging process.
b a t S o C 0 = b a t S o C i n i t
b a t S o C m i n b a t S o C t b a t c a p a c i t y
0 b a t p o w e r c h g t b a t P o w e r c h g _ m a x · b a t c h a r g i n g ( t )
0 b a t P O W E R d c h g ( t ) b a t P o w e r d c h g _ m a x · b a t d i s c h a r g i n g ( t )
b a t c h a r g i n g ( t ) + b a t d i s c h a r g i n g ( t ) 1
b a t S o C t + 1 = b a t S o C t + b a t p o w e r c h g t · b a t e f f i c h g b a t p o w e r d c h g t b a t e f f i d c h g · T
b a t p o s c h a r g e t b a t p o w e r c h a r g e t b a t p o w e r c h a r g e t + 1
b a t p o s d i s c h a r g e t b a t p o w e r d i s c h a r g e t b a t p o w e r d i s c h a r g e ( t + 1 )
b a t n e g c h a r g e t b a t p o w e r c h a r g e t + 1 b a t p o w e r c h a r g e ( t )
b a t n e g d i s c h a r g e t b a t p o w e r d i s c h a r g e t + 1 b a t p o w e r d i s c h a r g e ( t )
  • EV charging facilities:
Equation (19) indicates that the initial charge state of the EV batteries will be zero if no vehicle is connected to the charging station. Equation (20) limits the minimum and maximum state of charge of the EV battery. In this case, if there is no vehicle connected, as indicated by evavailability(t), the minimum value is 0; otherwise, it is the established minimum value. Equation (21) limits the maximum and minimum charging power.
Equation (22) determines the state of charge of the vehicle battery, taking into account the previous state, the vehicle’s availability, the state of charge upon arrival if a new vehicle has been connected, and the energy managed during charging in the previous period.
Finally, Equations (23) and (24) calculate the power difference between the different periods. The variable e v p o s c h a r g e t counts the positive difference, and e v n e g c h a r g e (t) counts the negative difference. In both cases, the two variables are always positive, equal to or greater than zero. These values are used in the irregular or peaky charging or discharging process described in (3).
E v S o C 0 = a v e v · e v S o C a r r i v a l 0
e v d i s p o n i b i l i t y t · e v S o C m i n e v S o C ( t ) e v d i s p o n i b i l i t y t · e v c a p a c i t y
0 e v p o w e r c h g t e v d i s p o n i b i l i t y t · e v p o w e r m a x
e v S o C t + 1 = e v d i s p o n i b i l i t y ( t + 1 ) · e v S o C A r r i v a l t + 1 + e v S o C t + e v p o w e r c h g t · e v e f f i c h g · T
e v p o s c h a r g e t e v p o w e r c h a r g e t e v p o w e r c h a r g e ( t + 1 )
e v n e g c h a r g e t e v p o w e r c h a r g e t + 1 e v p o w e r c h a r g e ( t )
  • Hydrogen systems:
The first two equations determine the operating power limits of both the fuel cell (25) and the electrolyser (26). Equations (27)–(30) define the characteristics of hydrogen storage. Following a similar pattern to electric batteries, the initial state of charge (27), the minimum and maximum storage capacity (28), the impossibility of charging and discharging simultaneously (29), and the state of charge at the next instant (30) are determined. To do this, the hydrogen inputs from either the electrolyser or the auxiliary truck, as well as the hydrogen output for the fuel cell or vehicle recharging, are considered. Equations (31) and (32) correspond to the fuel cell and electrolyser models, which determine the amount of hydrogen required to consume or generate a certain amount of electrical power, respectively.
Finally, Equations (33) and (34) associate the hydrogen generated by the electrolyser and consumed by the fuel cell with the system’s hydrogen storage, limiting the amount that can be consumed and/or generated.
f c p o w e r m i n · h 2 d i s c h a r g i n g t f c p o w e r t f c p o w e r m a x · h 2 d i s c h a r g i n g ( t )
e l z p o w e r m i n · h 2 c h a r g i n g t e l z p o w e r t a v h 2 · e l z p o w e r m a x · h 2 c h a r g i n g ( t )
h 2 S o H 0 = a v H 2 · h 2 S o H i n i t
h 2 S o H m i n h 2 S o H ( t ) h 2 S o H m a x
h 2 c h a r g i n g t + h 2 d i s c h a r g i n g t 1
h 2 S o H t + 1 = h 2 S o H t + a u x m a s s + e l z m a s s t f c m a s s t + f c e v m a s s t
f c m a s s = f c p o w e r t f c e f f i · L H V · T
e l z m a s s = e l z p o w e r t · e l z e f f i H H V · T
f c m a s s t + 1 h 2 S o H t
e l z m a s s t + 1 h 2 S o H m a x h 2 S o H ( t )
  • Grid connection:
The power extracted from the grid must be less than or equal to the contracted power ( g r i d p o w e r m a x ), both for purchasing energy ( g r i d p o w e r b u y , (35)) and selling energy ( g r i d p o w e r s e l l , (36)).
0 g r i d p o w e r b u y ( t ) g r i d p o w e r m a x
0 g r i d p o w e r s e l l ( t ) g r i d p o w e r m a x

2.2. Stage 2—Set-Points Adaptation to the Actual State of the Microgrid

Several studies have shown that discretizing high-frequency energy time series with coarser temporal resolutions introduces a structural error that increases with the granularity of the sampling interval. This effect has been documented for PV generation, household demand, and hybrid PV–storage systems, where increasing the time step leads to significant distortions in peak power, energy balance, self-consumption indices, and optimal sizing decisions [54,55,56,57,58,59]. For example, ref. [53] demonstrated that time-averaging domestic loads smooths peaks and alters key statistics relevant for on-site generation assessments. At the same time, ref. [57] showed that PV–load matching errors increase systematically with the simulation time step. Similar behaviours have been observed in real PV facilities, where transitioning from sub-minute to hourly data introduces non-negligible deviations in self-consumption and self-sufficiency calculations [58]. Additionally, in hybrid PV–battery assessments, averaging windows of up to one hour can bias energetic and economic indicators by several percent [59]. These findings confirm that the first-stage EMS, which necessarily operates on discretized and forecast-based signals, inevitably injects an aggregation error into the control chain. Consequently, a fast second-stage EMS is required to correct these set points at the edge, adapting them to the actual microgrid state and mitigating both discretization-induced deviations and the associated degradation of the objective function.
A two-stage EMS structure with a fast local adaptation layer is established as essential in the literature for reliable and high-performance microgrid operation under uncertainty. Numerous studies have demonstrated that upper-level optimization, typically performed with PV production, demand, EV availability, or market price forecasts, inevitably diverges from real-time conditions due to prediction errors, discretization errors, and device-level anomalies. To mitigate these mismatches, a second, local control layer is commonly introduced to adjust set-points to the measured state of the microgrid, ensuring feasibility and maintaining the economic or technical objective despite forecasting imperfections [60,61]. Some sources highlight that this local layer not only compensates forecast uncertainty but also corrects the effect of temporal resolution or sample-time mismatch between the upper-level schedule and fast system dynamics. Authors in [53] show that their real-time controller compensates for both “forecast uncertainties and sample-time resolution” when tracking the reference trajectory in a home microgrid, while [62] emphasizes that coarse day-ahead or half-hourly set-points require intra-hour local adjustment to maintain system stability and minimize deviations. This hierarchical structure is further supported in stochastic MPC frameworks, where the first stage provides a robust schedule and the second stage operates at a finer resolution to correct realization-specific deviations [63,64].
Beyond uncertainty, the local adaptation layer is also the only mechanism capable of reacting to unexpected device-level events, such as temporary disconnection or derating of PV inverters, BESS units, or EV chargers, without recomputing the whole optimization problem. By relying on real-time measurements rather than forecasts, the second stage absorbs such anomalies, preserving the continuity of operation and preventing constraint violations.
This paper extends this line of research by quantitatively analyzing the propagation of discretization error from the first-stage EMS to the real system, using real 5 s PV generation data. Whereas previous studies primarily focus on the qualitative need for a second stage, this study explicitly measures how the discretization of set-points at 1 min, 5 min, 15 min, and 1 h resolutions affects tracking accuracy and how this error accumulates in practice. Furthermore, the amount of local flexibility required—expressed as nominal power Pnom and needed energy capacity Ecap of a BESS—to fully absorb the mismatch induced by each granularity is computed. This provides, to our knowledge, one of the first empirical quantifications of the flexibility required to counteract the combined effects of discretization error, forecasting uncertainty, and measurement delay using a simple local controller at the edge. These results complement the existing literature by demonstrating not only that a second stage is necessary, as recognized, but also the extent of local corrective capability required to ensure the microgrid operates as intended while respecting hardware limits and maintaining the EMS objective.
Hierarchical control architectures consistently emphasize that the lowest layer must operate at short cycle times—typically seconds or sub-seconds—to ensure stability, enforce operational limits and track set-points that may deviate from upper-level forecasts due to uncertainty or disturbances [65,66]. For these time scales, only fast-responding resources, such as BESS, supercapacitors, or inverter-interfaced DER, are suitable; traditional large-scale storage technologies, like pumped-hydro or compressed-air systems, exhibit response times of minutes and are incapable of performing such rapid corrections [67,68]. Numerous studies have shown that BESS units, in particular, can absorb short-term PV fluctuations, regulate grid exchange, or maintain EV charging profiles thanks to their millisecond-scale response and high controllability [69,70,71]. Because these fast corrections must be performed close to the hardware and within strict timing constraints, the local controller is typically implemented with simple, robust, low-complexity rules rather than computationally intensive optimization, a design principle validated in several real EMS deployments and rule-based architectures [72,73]. This is also the approach followed in CIRCE’s multi-technology DSM control structure, where 15 min set-points derived from an upper-level optimiser are converted locally into 5 s commands through a lightweight decision matrix executed in an embedded industrial device, ensuring real-time correction of deviations and the ability to react to unexpected behaviour such as a sudden disconnection or derating of batteries, PV inverters or local loads (see the Energy Box control logic on page 2 and Table I in [42]). According to this, this paper evaluates a second stage of the EMS that applies a fast and rule-based corrective layer.
While previous works demonstrate the conceptual need for such fast local adaptation, the contribution presented in this paper goes further by quantifying the magnitude of discretization error, its propagation across several temporal granularities (1 min, 5 min, 15 min, and 1 h), and the concrete BESS flexibility needs required to absorb those deviations under realistic measurement delays and forecast errors. This analysis, therefore, complements existing hierarchical EMS designs by providing empirical evidence of the corrective capability required from the second stage and demonstrating that even simple rule-based controllers, when supported by appropriately sized BESS units, are sufficient to maintain high-quality tracking at the edge despite the combined effects of discretization, forecasting uncertainty, and local disturbances.

3. Results

In this section, the main research results are presented in two main subsections, each related to a specific EMS stage: Stage 1, which involves the optimal scheduling of microgrid operations, and Stage 2, which involves set-point adaptation to the actual grid state. Although the analyzed scenarios adopt a simple structure, all simulations are based on real facilities and real high-resolution operational data, ensuring that the observed behaviours and conclusions are representative of practical EMS deployments rather than synthetic or idealized scenarios.

3.1. Stage 1—Microgrid Optimization and Error Effect Evaluation

As previously justified in this work, a two-stage EMS architecture is particularly suitable for coordinating complex microgrids, with the upper level responsible for optimal resource scheduling and the lower level for fast corrective control. The upper stage computes optimal operating schedules based on a detailed physical and economic model. In contrast, the lower stage adapts set-points in (near) real time to cope with measurement deviations, unforeseen events, and equipment behaviour. In addition to forecast errors, another relevant source of mismatch between the planned and the realized operation is the discretization of inherently continuous signals (e.g., solar PV generation or energy demand) when they are represented with a finite temporal resolution in the optimization problem; this discretization effect is partly analyzed in a separate section, but it is ultimately absorbed at local level by the second stage. Depending on the size and complexity of the optimization problem, as well as on the available computational capabilities, the upper stage can be executed either locally on an edge device or remotely in the cloud. Temporal granularity and rolling-horizon execution play a central role in this context: shorter time steps and frequent re-optimization reduce both forecast and discretization errors and allow the EMS to react to changes in the microgrid configuration, such as the disconnection of assets, unexpected variations in demand or generation, or equipment operating outside its nominal regime.
To analyze these trade-offs, a set of numerical experiments is conducted on a real test microgrid, whose main characteristics are summarized in Table 1, and the schema is shown in Figure 3. The system, isolated from the grid, includes a photovoltaic plant, a controllable electric vehicle charging point, a hydrogen refuelling station, and a battery energy storage system. Hydrogen is supplied by external trucks, and the optimization model is designed to determine when to import hydrogen as well. In this case, hydrogen is supplied to the system via external trucks, as there is no electrolyser; however, a fuel cell is present to produce electricity from the stored hydrogen.
Two series of simulations are performed over one month for several temporal granularities and execution platforms: in the first series, each optimization execution starts from a fixed state of charge for the BESS and hydrogen storage; in the second series, the initial state of charge is set equal to the final SoC of the storage systems state the end of the first step resulting from the previous execution, emulating continuous operation in real life and propagating the impact of past decisions.
The first set of tests is used to evaluate the effect on the objective function of the granularity in different platforms, cloud/edge execution. The objective function is to minimize operative costs, so negative values in the objective function imply incomes, in this case derived from vehicle charges.
As shown in Table 2, reducing granularity in execution improves the objective function on both platforms. However, the results are very similar, confirming that lower granularity in the first stage of EMS yields better results.
The results in Table 3 indicate that smaller granularities yield better results, albeit at the cost of increased calculation requirements. For granularities of 10 min executed on the server and for both cases of execution on the edge, maximum execution times of 300 s are observed, equivalent to 5 min, which leaves little time for other processes necessary for EMS execution, such as communication with external platforms, data collection, calculation of forecasts and, in the case of the cloud, communication with the second level of the EMS. In the case of edge execution, this effect is accentuated by the fact that the maximum execution time was limited to 300 s.
These results confirm that higher granularities yield better results and a more effective objective function, but also require enhanced execution platforms. Additionally, some granularities may become invalid solutions as execution time approaches the granularity.
The effect of forecast error, specifically in the case of solar PV generation, on the optimization process has also been evaluated. Table 4 and Table 5 show the effect of adding an error in solar forecasts on the performance of the optimization system with granularities of 15 min and 1 h. In both cases, the error was introduced as normal noise with a mean of zero and standard deviations of 5%, 15%, and 25%.
As can be seen, when the error increases, the maximum, minimum, and average values observed for the objective function also change erratically, with no clear trend apparent. This may be due to the random nature and regular distribution of the error introduced, which modifies solar production values both upwards and downwards. Other systematic forecasting errors, which systematically underestimate or overestimate the prediction, would lead to different results.
When comparing 15 min and hourly executions, it is confirmed that the objective function yields better results in cases of lower granularity.
Overall, the deviation from the perfect-forecast benchmark (Error = 0%) increases as the injected prediction error grows, and finer granularity generally reduces this degradation compared with hourly discretization. A limited non-monotonic effect may appear in the 15 min case at the highest error level, where the objective happens to be closer to the benchmark than for intermediate errors; this should not be interpreted as a systematic benefit of higher uncertainty, but as the outcome of a particular error realization combined with rolling-horizon re-optimization.
These observations suggest that reducing granularity, along with more frequent forecast updates, will improve the results of the optimization process. The disadvantage of this strategy is that it requires more computing power or longer execution time, so a balance must be found between these objectives: accuracy and execution time.

3.2. Stage 2—Set-Points Adaptation to the Actual State of the Microgrid and Error Effect

In a deterministic two-stage EMS, a local corrective layer is required for several reasons. First, upper-level optimization utilizes, for example, forecasts of demand, renewable generation, EV availability, and energy needs and prices. Even with accurate physical and economic models, these forecasts are imperfect, and as a consequence, the operation set-points calculated will deviate from the perfect and optimal schedule. A fast local controller can partially compensate for these deviations in real time to preserve the original objective (e.g., minimize operational costs, maximize self-consumption, or reduce pollutant emissions). Second, the simple fact of discretizing continuous-time signals into finite time steps or granularity (1 min, 5 min, 15 min, 1 h, etc.) introduces a structural “sampling error” between the continuous underlying trajectories and the step-constant setpoints used in the first stage. This discretization error can also be absorbed at the local level by adjusting setpoints at a higher frequency. Third, local adaptation is essential and the only way to accommodate device-level anomalies or unmodelled behaviour (e.g., a BESS or inverter temporarily out of service or an electric vehicle connected unexpectedly to the charging point) without recalculating the whole optimization problem (it would be calculated using these unexpected phenomena in the following calculation step in the rolling horizon). In this section, a simple yet representative PV/BESS example—similar to implementations already deployed in real-world projects and operational edge environments—is used to illustrate how a second-stage EMS can mitigate these effects through a straightforward, rapid, and effective local correction mechanism.
The numerical analysis is based on real power measurements from a single PV inverter over two consecutive days in a real solar PV facility (see Figure 4). The raw data consist of active power values sampled every 5 s, which serve as the reference data. From this 5 s series, four block-wise discretizations are constructed with time steps of 1 min, 5 min, 15 min, and 1 h, respectively. These discretized profiles emulate the setpoints that would be produced by a first-stage EMS operating at different temporal granularities. All subsequent calculations—errors, corrective actions, and equivalent BESS requirements—are performed at the original 5 s resolution to capture the fast dynamics of the inverter.
As a first evaluation, the pure tracking error between the 5 s reference and each discretized profile is quantified, without any local correction. Considering only solar hours (non-zero PV output), the mean absolute error (MAE) and root mean square error (RMSE) grow significantly with longer granularity, see Table 6.
As can be seen, the use of 15 min granularities at level 1 introduces an RMSE of ~260 W compared to the actual 5 s for this inverter; therefore, level 2 must be capable of assuming at least that correction range. On the other hand, when lowering the granularity to 1 min, the error decreases significantly (RMSE ~85 W), but the size of the optimization problem and the communication requirements at the initial EMS level increase.
Assuming a “perfect” second stage that knows the 5 s trajectory in advance and can act instantaneously, a BESS could theoretically cancel this tracking error entirely. In that idealized case, the corrective power needs and capacity using different BESS to avoid 95%, 99%, or all deviations are shown in Table 7.
For this case study, the use of hourly set-points at the first level introduces errors of up to ~380 W RMSE. It requires the second level to have approximately 2.6 kW/0.3 kWh of local flexibility per inverter to compensate for the time mismatch between planning resolution (1 h) and control resolution (5 s). By reducing the granularity to 15 min, these requirements are relaxed.
As indicated, a fast and straightforward rule-based correction is proposed for application at this second level of the EMS. The local corrective mechanism focuses on compensating for the mismatch between the discretized PV generation set-points produced by the first stage and the actual high-frequency PV output. This compensation is implemented through the controlled charging or discharging of the BESS: when the discretized set-point is lower than the actual PV generation, the battery is charged to absorb the excess power; conversely, when the discretized value is higher than the actual generation, the battery is discharged to compensate for the deficit. In this way, the local stage counteracts the discretization and forecast-induced error while preserving the operating objective of the upper-level EMS.
In reality, the second stage operates with a delay of at least one sampling delay: the local controller only observes the deviation once a new measurement arrives and can react within the next 5 s interval. To account for this, a proportional compensation mechanism with gain K has been evaluated, applied to the action calculated to compensate for the deviation observed in the previous time step. Values of K < 1 correspond to partial compensation, whereas K = 1 applies the full corrective action computed from the last observed error. In this study, the values K = 0, 0.5, and 1 are intentionally selected as representative limiting cases (no correction, partial correction, and total correction) to provide a clear first assessment of whether applying none/part/all the corrective action is beneficial in general. It is acknowledged that, in real deployments, the optimal K may be site- and data-dependent and should be tuned over a finer set of values (or even made adaptive) using longer time series and broader simulation campaigns. The objective here is not to identify the optimal K for a specific situation, but to identify the overall trend and quantify the potential benefit of a partial corrective action versus a complete one.
Therefore, the analysis is repeated assuming a one-step delay and a simple proportional correction (K) based on the last observed deviation. Table 8 and Table 9 show the effect of the proposed compensation procedure for 1 min and 1h discretizations.
The effect of a 5 s delay in signal compensation and the total application of compensation, K = 1, or partial application, K = 0.5 and K = 0, has been evaluated. It can be seen that, in this case, the one-second delay and the total application of the compensation calculated for a previous step reduce the tracking error. This phenomenon is also observed at higher granularities (5 min, 15 min, and 1 h). Therefore, it can be seen that total error compensation, even with a delay, is a suitable solution for mitigating the effect of data discretization at the first level of the EMS.
The effects of a forecasting error and the local correction have also been evaluated. To achieve this, a file with a normally distributed forecasting error was generated, using a mean of μ = 0 and a standard deviation of σ = 5%, see the effect in Table 10 and Table 11.
To complete the analysis of the correction effect, tests were conducted with greater errors in prediction (see Table 12, Table 13, Table 14, Table 15, Table 16 and Table 17). The reference errors have been extracted from the SOLCAST web [74] (Table 12). Solar PV generation forecast error (MAPE = 10%), 5 s delay effect, and 1 min discretization.
As shown in Figure 5, in environments with high error, solutions with full gain (K = 1) are still superior to those with partial compensation (K = 0.5) or no compensation (K = 0). However, it can be observed that the effect of error dilutes the difference between full and partial compensation. In environments with coarser granularity, such as hourly versus minute-by-minute discretizations, full compensation remains superior to partial compensation or no compensation, although in this case, full compensation is clearly more effective than other types of compensation.

4. Discussion

In this section, the previous theoretical analysis and main research results are analyzed and discussed. This discussion has been conducted in the same manner as in the other sections for the two-stage EMS levels.

4.1. Stage 1—Microgrid Optimization to Reduce Forecast Error Effect

In the first stage of the EMS, the numerical results clearly illustrate the classical trade-off between temporal granularity, objective function, and computational burden. For both cloud and edge executions, reducing the time step from 1 h to 15 or 10 min improves the objective function systematically, leads to more favourable operating costs (more negative values in this case, as the objective aggregates costs and revenues from EV charging, grid exchanges, BESS operation, and the hydrogen system). In the fixed-SoC and chained-SoC experiments over one month, average objective values at 10–15 min remain close to the “ideal” perfect-forecast case. In contrast, hourly optimization shows a significantly degraded average, reflecting a poorer exploitation of PV generation, storage, and EV charging flexibility. At the same time, execution times grow noticeably as granularity is reduced: cloud runs move from average times around 1 s at 1 h resolution to tens of seconds at 10–15 min intervals, and edge executions frequently hit the imposed 300 s cap for the most demanding configurations. This confirms that finer granularity is an effective way to reduce both forecast and discretization impact on the objective function, but only at the cost of significantly higher computational requirements and longer solver runtimes.
The sensitivity tests with synthetic PV forecast errors further reinforce this picture. Forecasts were perturbed with zero-mean Gaussian noise with increasing standard deviation (e.g., σ ≈ 5–25% of nominal PV power), representing typical day-ahead and intraday PV prediction uncertainty. For each configuration, the degradation of the objective function was quantified by comparing against the perfect-forecast baseline using normalized error metrics (NMAE and NRMSE). At 1 h granularity, these indicators grow from small values. For low forecast error to substantially higher levels for large forecast deviations, whereas at 15 min, the relative degradation is consistently smaller. This shows that reduced granularity not only yields a better optimum but also makes that optimum more robust to forecast noise. Shorter time steps limit the temporal aggregation of errors, allowing the rolling-horizon EMS to react earlier to deviations and effectively constrain how much a given forecast error can distort the achievable objective value. However, the same reduction in granularity amplifies the number of decision variables and constraints. It increases the dependency on high-resolution input data, which must be taken into account when designing real EMS deployments.
From an architectural standpoint, the results highlight that the choice of execution platform for the first stage of the EMS is not intrinsically “cloud vs. edge”, but rather a design decision driven by computational capabilities and timing constraints. For moderate granularities (e.g., 15 min) and problem sizes, both cloud and edge executions achieve similar objective values, and average runtimes remain compatible with a 15 min rolling horizon; in such cases, an edge–edge deployment (both stages local) is technically viable provided the on-site hardware can sustain the required worst-case execution time. For more aggressive granularities (e.g., 10 min with complex models), the observed maximum runtimes close to 300 s leave very little slack within each optimization interval for data acquisition, forecast generation, communication, and synchronization with the second stage, making those configurations impractical on constrained edge devices and better suited to cloud or high-end on-premise servers. Reduced granularity and frequent rolling-horizon updates are powerful levers to limit the impact of forecast and discretization errors on the objective function. Still, they must be co-designed with the available computing platform: cloud, edge, or hybrid arrangements are all valid options, as long as the first stage can systematically deliver solutions within the allocated time budget dictated by the chosen granularity.

4.2. Stage 2—Set-Points Adaptation to the Actual State of the Microgrid to Reduce the Forecast Error Effect

The results obtained in Section 3.2 confirm that a fast local adaptation layer is structurally necessary in a deterministic two-stage EMS. Even when the upper level employs a well-calibrated physical and economic model and a deterministic optimization method, the combination of forecast errors and temporal discretization inevitably creates a gap between the scheduled set points and feasible operation. The second stage acts as a safety and performance filter, projecting these coarse, forecast-based set-points onto the real microgrid state while preserving the objective function as much as possible, ensuring that device and system limits are respected.
The example shows that the local stage of an EMS can effectively absorb different error types simultaneously. First, it compensates for the structural error introduced by coarse temporal granularity at the upper level. Without local correction, the tracking error increases significantly as the step size grows from 1 min to 1 h; however, a simple proportional compensator with a one-sample delay can reduce the residual MAE. Second, it mitigates the impact of forecast uncertainty. When a realistic, normally distributed forecast error is added on top of discretization, the local controller still reduces MAE and RMSE compared with a “no-action” baseline. Third, the same mechanism would naturally react to unmodelled local events (e.g., temporary disconnection or derating of a PV inverter or BESS, unexpected EV connection), since it acts on the measured deviation rather than on the forecast itself.
At the same time, the results highlight an essential design balance between temporal granularity at the upper level and the burden placed on the local stage. Finer granularity (e.g., 1 min set-points) reduces the intrinsic discretization error and, consequently, the range of corrections that the local controller must provide; however, it also increases the size of the optimization problem, the dependence on high-resolution forecasts, and the communication requirements. Coarser granularity (e.g., 15 min or 1 h) makes the upper-level optimization more manageable and scalable. Still, it pushes more variability onto the second stage and requires sufficient local flexibility (in this case, a BESS of the order of a few kilowatts and several kilowatt-hours per inverter) to compensate for the mismatch.
From an implementation perspective, the second stage must also respect the practical constraints of edge devices. Local controllers typically run on hardware with limited computational resources compared to cloud or server-based platforms, and they must operate under strict timing constraints. In this work, a deliberately simple strategy is proposed and tested: a proportional correction based on the deviation observed in the previous 5 s interval and applied with a one-cycle delay. Despite its simplicity, this scheme proves to be fast, robust, and effective in reducing the impact of both discretization and forecast errors. In practical applications, K should be calibrated using site-specific data; here, we restrict K to three representative values to highlight the general behaviour and the benefit of applying partial versus full correction. More sophisticated local controllers could, in principle, further improve performance; however, they must be carefully designed to fit within the sensing, actuation, and computation cycles of edge devices. The achievable cycle time will depend on sensor sampling rates, actuator response times, communication latencies, and the processing capabilities of the embedded platform.

5. Conclusions

The work confirms that adopting a two-stage deterministic EMS architecture is a robust and safe choice for microgrid operation. Once the physical, electrical and economic models are correctly defined, the upper stage can rely on well-established optimization formulations to compute the operating schedule with transparent feasibility handling and sensitivity to constraints and parameters. The results show that temporal granularity is a decisive design variable: finer time steps generally improve the objective value and reduce structural tracking errors, but they increase the problem size and may become impractical for large systems or frequent re-optimization. In this context, rolling-horizon operation mitigates part of the mismatch by periodically updating predictions and measurements, naturally adapting to changing operating conditions and unexpected events.
Beyond validating the approach, the paper provides quantitative evidence on the trade-off between modelling granularity, computational effort, and local corrective capability in a cloud–edge EMS setting. It demonstrates that a fast and lightweight second stage is fundamental under real-world uncertainty: forecast errors, discretization effects, and device-level events create deviations between planned and feasible operation that, without local correction, directly degrade the objective function and may lead to constraint violations. The evaluation across different granularities and operating conditions shows that simple proportional local adaptations—especially exploiting fast assets such as batteries—can absorb a broad spectrum of deviations with minimal computational effort at the edge, and it helps dimension the extent of local flexibility (power and energy capacity) required to preserve the intended EMS objective.
Future work will extend the analysis toward more realistic uncertainty characterizations and broader validation campaigns. This includes non-Gaussian and time-correlated forecast errors, regime changes and extreme events, longer datasets, and larger Monte Carlo studies to better separate systematic trends from single-realization effects. Further research will also address the systematic (or adaptive) tuning of local corrective gains and the co-design of planning horizon and (block-wise/adaptive) time granularity under compute budgets, with the goal of producing transferable guidelines for deploying two-stage deterministic EMS in diverse microgrid configurations.

Author Contributions

Conceptualization, G.F. and J.F.S.O.; methodology, G.F. and J.F.S.O.; software, G.F.; validation, G.F. and J.F.S.O.; formal analysis, G.F. and J.F.S.O.; investigation, G.F.; resources, G.F.; data curation, G.F.; writing—original draft preparation, G.F.; writing—review and editing, G.F., J.F.S.O., R.R., L.L.-B. and M.T.; visualization, G.F., J.F.S.O., R.R., L.L.-B. and M.T.; supervision, J.F.S.O.; project administration, G.F. All authors have read and agreed to the published version of the manuscript.

Funding

REEFLEX has received funding from the European Union’s Horizon Europe Research and Innovation program under Grant Agreement No. 101096192.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The raw data supporting the conclusions of this article will be made available by the authors on request.

Acknowledgments

During the preparation of this manuscript/study, the author(s) used [Chat GPT 5.1] for the purposes of checking the correct wording of some parts of the text, reviewing, and modifying some time series used in this work. The authors have reviewed and edited the output and take full responsibility for the content of this publication.

Conflicts of Interest

The authors declare that they have no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
DERsDistributed Energy Resources
EMSEnergy Management System
HVACHeating, Ventilation, and Air Conditioning
MPCModel Predictive Control
PVPhotovoltaic
BESSBattery Energy Storage System
EVElectric Vehicle
LPLinear Programming
QPQuadratic Programming
MIPMixed-Integer Programming
MILPMixed-Integer Linear Programming
MIQPMixed-Integer Quadratic Programming
HEMSHome Energy Management System
CEMSCommunity Energy Management System

Appendix A

This appendix lists the parameters and variables used in the optimization algorithm.
Table A1. General and solar PV model parameters and variables.
Table A1. General and solar PV model parameters and variables.
SymbolDescriptionUnit
∆TTime steph
loads(t)Consumption profile of non-manageable loadskW
P V p o w e r m a x Installed solar powerkW
p v c o n v e f f i PV converter efficiency%
P o w e r P V ( t ) Production profile of the photovoltaic installationkW
p v p o w e r u s e d t Used power from the photovoltaic installationkW
Table A2. Grid model parameters and variables.
Table A2. Grid model parameters and variables.
SymbolDescriptionUnit
g r i d p o w e r c o s t Cost of contracted grid power€/kW
g r i d p o w e r m a x Maximum contracted powerkW
d c c o n v e f f i DC grid converter efficiency%
a c c o n v e f f i AC grid converter efficiency%
g r i d c o s t t Energy cost over 24 h€/kWh
g r i d i n c o m e t Income from selling energy to the grid€/kWh
g r i d p o w e r b u y t Power purchased from the gridkW
g r i d p o w e r s e l l t Power sold to the gridkW
C o s t g r i d Total grid cost
Table A3. BESS model parameters and variables.
Table A3. BESS model parameters and variables.
SymbolDescriptionUnit
b a t c a p a c i t y Battery capacitykWh
b a t S o C m i n Minimum battery capacity%
b a t S o C i n i t Initial battery capacity%
b a t c o s t Battery cost€/kW
b a t P o w e r c h g _ m a x Maximum battery charging powerkW
b a t P o w e r d c h g _ m a x Maximum battery discharging powerkW
b a t e f f i c h g Battery charging efficiency%
b a t e f f i d c h g Battery discharging efficiency%
b a t c o n v e f f i Battery converter efficiency%
b a t c h a r g i n g ( t ) Battery charging activation1/0
b a t d i s c h a r g i n g ( t ) Battery discharging activation1/0
b a t p o w e r c h g t Battery discharging powerkW
b a t p o w e r d c h g t Battery charging powerkW
b a t S o C t Instantaneous battery capacitykWh
b a t p o s c h a r g e t Positive difference between battery charging periodskW
b a t p o s d i s c h a r g e t Positive difference between battery discharging periodskW
b a t n e g c h a r g e t Negative difference between battery charging periodskW
b a t n e g d i s c h a r g e t Negative difference between battery discharging periodskW
α b a t Cost for controlling battery charge/discharge irregularity
C o s t b a t Total battery system cost
Table A4. EV parameters and variables.
Table A4. EV parameters and variables.
SymbolDescriptionUnit
e v c a p a c i t y Maximum EV capacitykWh
e v p o w e r m a x Maximum EV charging powerkW
e v e f f i c h g EV charging efficiency%
e v i n c o m e Income from EV charging€/kWh
E V c o n v e f f i EV converter efficiency%
e v S o C m i n (t)Minimum EV capacity (V2G cases only)%
e v S o C d e p a r t u r e t Minimum departure state at the end of EV charging%
e v S o C a r r i v a l 0 Initial EV SoC%
e v d i s p o n i b i l i t y t EV availability1/0
e v p o w e r c h g t EV charging powerkW
e v S o C t Instantaneous EV capacitykWh
e v p o s c h a r g e t Positive difference between EV charging periodskW
e v n e g c h a r g e t Negative difference between EV charging periodskW
α e v Cost for controlling EV battery charge/discharge irregularity
C o s t e v Total EV charging system cost
Table A5. Hydrogen model parameters and variables.
Table A5. Hydrogen model parameters and variables.
SymbolDescriptionUnit
L H V Low heating valuekWh/kg
H H V High heating valuekWh/kg
e l z e f f i Electrolyzer efficiency%
f c e f f i Fuel cell efficiency%
h 2 S o H m a x Maximum hydrogen storagekg
h 2 S o H m i n Minimum hydrogen storage%
h 2 S o H i n i t Initial hydrogen storage%
e l z p o w e r m a x Maximum electrolyzer powerkW
e l z p o w e r m i n Minimum electrolyzer powerkW
f c p o w e r m a x Maximum fuel cell powerkW
f c p o w e r m i n Minimum fuel cell powerkW
h 2 c o s t Hydrogen system cost€/kWh
h 2 i n c o m e Hydrogen charging income€/kg
t r u c k h 2 m a s s Auxiliary truck hydrogen capacitykg
t r u c k h 2 c o s t Auxiliary hydrogen truck cost€/unit
h 2 c o n v e f f i Hydrogen converter efficiency%
f c e v m a s s t Hydrogen consumption profilekg
t r u c k h 2 a v a i l a b i l i t y t Days available for auxiliary H2 refill1/0
h 2 c h a r g i n g t H2 charging activation1/0
h 2 d i s c h a r g i n g ( t ) H2 discharging activation1/0
t r u c k h 2 d i s c h a r g i n g ( t ) Auxiliary H2 truck activation1/0
e l z p o w e r t Electrolyzer powerkW
f c p o w e r t Fuel cell powerkW
h 2 S o H t Instantaneous H2 capacitykWh
e l z m a s s Mass generated by the electrolyzerkg
f c m a s s Mass consumed by a fuel cellkg
a u x m a s s (t)Auxiliary hydrogen truck masskg
C o s t h 2 Total hydrogen system cost

References

  1. Drgoňa, J.; Arroyo, J.; Figueroa, I.C.; Blum, D.; Arendt, K.; Kim, D.; Ollé, E.P.; Oravec, J.; Wetter, M.; Vrabie, D.L.; et al. All you need to know about model predictive control for buildings. Annu. Rev. Control 2020, 50, 190–232. [Google Scholar] [CrossRef]
  2. Zhou, E.; Hale, E.; Stephen, G.; Radhakrishnan, N. Reducing Grid Costs while Abating Emissions: Opportunities for Flexible Building Loads; National Renewable Energy Laboratory (NREL): Golden, CO, USA, 2023; NREL/TP-6A40-84828. [Google Scholar]
  3. Strezoski, L. Distributed energy resource management systems—DERMS: State of the art and how to move forward. In Wiley Interdisciplinary Reviews: Energy and Environment; John Wiley and Sons Ltd.: Hoboken, NJ, USA, 2023; Volume 12. [Google Scholar] [CrossRef]
  4. ENTSO-E. System Flexibility Needs for the Energy Transition: Executive Summary; ENTSO-E—European Network of Transmission System Operators for Electricity: Brussels, Belgium, 2024. [Google Scholar]
  5. Agency for the Cooperation of Energy Regulators (ACER). Decision on the Flexibility Needs Assessment (FNA) Methodolo-gy—Annex I: Type and Format of Data and the Methodology for TSOs’ and DSOs’ Flexibility Needs Analysis in Accordance with Article 19e(4) of Regulation (EU) 2019/943; ACER: Ljubljana, Slovenia, 2025. [Google Scholar]
  6. Striani, S.; Unterluggauer, T.; Andersen, P.B.; Marinelli, M. Flexibility potential quantification of electric vehicle charging clusters. Sustain. Energy Grids Netw. 2024, 40, 101547. [Google Scholar] [CrossRef]
  7. Hu, J.; Shan, Y.; Guerrero, J.M.; Ioinovici, A.; Chan, K.W.; Rodriguez, J. Model predictive control of microgrids—An overview. Renew. Sustain. Energy Rev. 2021, 136, 110422. [Google Scholar] [CrossRef]
  8. Satchwell, A.; Piette, M.A.; Khandekar, A.; Granderson, J.; Frick, N.M.; Hledik, R.; Faruqui, A.; Lam, L.; Ross, S.; Cohen, J.; et al. A National Roadmap for Grid-Interactive Efficient Buildings; U.S. Department of Energy: Washington, DC, USA, 2021. [Google Scholar]
  9. Agha Kassab, F.; Rodriguez, R.; Celik, B.; Locment, F.; Sechilariu, M. A Comprehensive Review of Sizing and Energy Management Strategies for Optimal Planning of Microgrids with PV and Other Renewable Integration. Appl. Sci. 2024, 14, 10479. [Google Scholar] [CrossRef]
  10. Carrión, M.; Arroyo, J.M. A computationally efficient mixed-integer linear formulation for the thermal unit commitment problem. IEEE Trans. Power Syst. 2006, 21, 1371–1378. [Google Scholar] [CrossRef]
  11. Espana, M.; Latorre, J.M.; Ramos, A. Tight and Compact MILP Formulation for the Thermal Unit Commitment Problem. IEEE Trans. Power Syst. 2013, 28, 4897–4908. [Google Scholar] [CrossRef]
  12. Rawlings, J.B.; Mayne, D.Q.; Diehl, M.M. Model Predictive Control: Theory, Computation, and Design, 2nd ed.; Nob Hill Publishing: Madison, WI, USA, 2020; Available online: http://www.nobhillpublishing.com (accessed on 2 December 2025).
  13. Achterberg, T. SCIP: Solving constraint integer programs. Math. Program. Comput. 2009, 1, 1–41. [Google Scholar] [CrossRef]
  14. Prívara, S.; Široký, J.; Ferkl, L.; Cigler, J. Model predictive control of a building heating system: The first experience. Energy Build. 2011, 43, 564–572. [Google Scholar] [CrossRef]
  15. Li, L.; Ju, Y.; Wang, Z. Quantifying the impact of building load forecasts on optimizing energy storage systems. Energy Build. 2024, 307, 113913. [Google Scholar] [CrossRef]
  16. Silvente, J.; Kopanos, G.M.; Pistikopoulos, E.N.; Espuña, A. A rolling horizon optimization framework for the simultaneous energy supply and demand planning in microgrids. Appl. Energy 2015, 155, 485–501. [Google Scholar] [CrossRef]
  17. Bemporad, A.; Morari, M. Control of systems integrating logic, dynamics, and constraints. Automatica 1999, 35, 407–427. [Google Scholar] [CrossRef]
  18. Mohsenian-Rad, A.-H.; Leon-Garci, A. Optimal residential load control with price prediction in real-time electricity pricing environments. IEEE Trans. Smart Grid 2010, 1, 120–133. [Google Scholar] [CrossRef]
  19. Dinh, H.T.; Kim, D.; Kim, D. MILP-based optimal day-ahead scheduling for a system-centric community energy management system supporting different types of homes and energy trading. Sci. Rep. 2022, 12, 18305. [Google Scholar] [CrossRef]
  20. Javaid, S.; Lim, Y.; Tan, Y. Optimized Energy Management and Storage Sizing in Smart Homes with Renewable Energy Sources Under Safe Operating Conditions. Designs 2025, 9, 22. [Google Scholar] [CrossRef]
  21. Dehghani, M.; Bornapour, S.M.; Ruiz, F.; Rodriguez, J. Multi-Objective Energy Management System in Smart Homes with Inverter-Based Air Conditioner Considering Costs, Peak-Average Ratio, and Battery Discharging Cycles of ESS and EV. Energies 2025, 18, 5298. [Google Scholar] [CrossRef]
  22. Dinh, H.T.; Kim, D. MILP-Based Imitation Learning for HVAC Control. IEEE Internet Things J. 2022, 9, 6107–6120. [Google Scholar] [CrossRef]
  23. Kelman, R.; Borrelli, F. Bilinear model predictive control for HVAC systems. In Proceedings of the 18th IFAC World Congress, Milano, Italy, 28 August–2 September 2011; pp. 9867–9872. [Google Scholar] [CrossRef]
  24. Langner, F.; Kovačević, J.; Spatafora, L.; Dietze, S.; Waczowicz, S.; Çakmak, H.K.; Matthes, J.; Hagenmeyer, V. Experimental evaluation of model predictive control and fuzzy logic control for demand response in buildings. Appl. Energy 2025, 401, 126666. [Google Scholar] [CrossRef]
  25. Liu, G.; Ferrari, M.F.; Ollis, T.B.; Tomsovic, K. An MILP-Based Distributed Energy Management for Coordination of Networked Microgrids. Energies 2022, 15, 6971. [Google Scholar] [CrossRef]
  26. Mao, Y.; Lin, X.; Zhang, S.; Wang, J.; Zhong, W.; Liu, B.; Xia, G. Optimal scheduling of industrial park integrated energy systems considering dynamics of multiple fluid networks. J. Clean. Prod. 2025, 514, 145743. [Google Scholar] [CrossRef]
  27. Rocca, R.; Leonori, S.; Fernández Aznar, G.; Toffanin, R.; Luengo-Baranguan, L. Optimal scheduling of district heat pumps conceived for implementation in Energy Management Systems to participate in demand response. Energy Convers. Manag. 2025, 27, 101074. [Google Scholar] [CrossRef]
  28. Gómez, J.; Framiñán, J.M.; Escaño, J.M.; Bordons, C. An Energy Management System for Industrial Manufacturing with demand response based on a Hybrid Robust MPC. IFAC-PapersOnLine 2025, 59, 218–223. [Google Scholar] [CrossRef]
  29. Diabate, M.; Krishnamoorthy, H.S.; Shi, J. Optimal Energy Management of A Hydrogen and Battery-Based Energy Storage System (ESS) for Future DC Microgrids. In Proceedings of the 2023 IEEE International Conference on Power Electronics, Smart Grid, and Renewable Energy (PESGRE), Trivandrum, India, 17–20 December 2023; pp. 1–6. [Google Scholar] [CrossRef]
  30. Kassab, F.A.; Celik, B.; Locment, F.; Sechilariu, M.; Liaquat, S.; Hansen, T.M. Optimal sizing and energy management of a microgrid: A joint MILP approach for minimization of energy cost and carbon emission. Renew. Energy 2024, 224, 120186. [Google Scholar] [CrossRef]
  31. Castelli, A.F.; Pilotti, L.; Monchieri, A.; Martelli, E. Optimal design of aggregated energy systems with (N-1) reliability: MILP models and decomposition algorithms. Appl. Energy 2024, 356, 122002. [Google Scholar] [CrossRef]
  32. Luengo-Baranguan, L.; Remiro-Cinca, M.; Rivas-Ascaso, D.; Rocca, R.; Fernández, G.; Elorza-Uriarte, L. Optimal Sizing Algorithm of PV-BESS Systems Considering a Price-Driven Rule-Based Energy Management Strategy. In Proceedings of the 2024 IEEE International Conference on Environment and Electrical Engineering and 2024 IEEE Industrial and Commercial Power Systems Europe (EEEIC/I&CPS Europe), Rome, Italy, 17–20 June 2024; pp. 1–6. Available online: https://ieeexplore.ieee.org/document/10751250 (accessed on 2 December 2025).
  33. Gomes, I.; Ruano, M.; Ruano, A. MILP-based model predictive control for home energy management systems: A real case study in Algarve, Portugal. Energy Build. 2023, 281, 112774. [Google Scholar] [CrossRef]
  34. Ahmed, B.; Ahmed, A.; Zhang, H.N.; Li, X.B.; Qu, K.Y.; Li, F.C. Characterization, quantification and application of energy flexibility in office building: A comprehensive review. Energy Build. 2025, 347, 116306. [Google Scholar] [CrossRef]
  35. Li, H.; Wang, Z.; Hong, T.; Piette, M.A. Energy flexibility of residential buildings: A systematic review of characterization and quantification methods and applications. Adv. Appl. Energy 2021, 3, 100054. [Google Scholar] [CrossRef]
  36. Gasser, J.; Cai, H.; Karagiannopoulos, S.; Heer, P.; Hug, G. Predictive energy management of residential buildings while self-reporting flexibility envelope. Appl. Energy 2021, 288, 116653. [Google Scholar] [CrossRef]
  37. Hekmat, N.; Cai, H.; Zufferey, T.; Hug, G.; Heer, P. Data-Driven Demand-Side Flexibility Quantification: Prediction and Approximation of Flexibility Envelopes. In Proceedings of the 2023 IEEE Belgrade PowerTech, Belgrade, Serbia, 25–29 June 2023; pp. 1–6. [Google Scholar] [CrossRef]
  38. Chondrogiannis, S.; Vasiljevska, J.; Marinopoulos, A.; Papaioannou, I.; Flego, G. Local Electricity Flexibility Markets in Europe; EUR 31194 EN; Publications Office of the European Union: Luxembourg, 2022. [Google Scholar] [CrossRef]
  39. Olivella-Rosell, P.; Lloret-Gallego, P.; Munné-Collado, Í.; Villafafila-Robles, R.; Sumper, A.; Ottessen, S.Ø.; Rajasekharan, J.; Bremdal, B.A. Local flexibility market design for aggregators providing multiple services at the distribution level. Energies 2018, 11, 822. [Google Scholar] [CrossRef]
  40. Capper, T.; Gorbatcheva, A.; Mustafa, M.A.; Bahloul, M.; Schwidtal, J.M.; Chitchyan, R.; Andoni, M.; Robu, V.; Montakhabi, M.; Scott, I.J.; et al. Peer-to-peer, community self-consumption, and transactive energy: A systematic literature review of local energy market models. Renew. Sustain. Energy Rev. 2022, 162, 112403. [Google Scholar] [CrossRef]
  41. Mokaramian, E.; Calderaro, V.; Galdi, V.; Graber, G.; Ippolito, L.; Siano, P. Sustainable local energy communities: The role of peer-to-peer trading, EVs, and RECs on social welfare and emissions. Sustain. Energy Grids Netw. 2025, 42, 101715. [Google Scholar] [CrossRef]
  42. Fernandez, G.; Almajano, J.; Garcia, E.; Bludszuweit, H.; Machin, S.; Sanz, J.F. Control structure for optimal demand-side management with a multi-technology BESS. In Proceedings of the ETFA 2019, Zaragoza, Spain, 10–13 September 2019. [Google Scholar]
  43. Oldewurtel, F.; Sturzenegger, D.; Gyalistras, P.; Jones, C.N.; Morari, M.; Gwerder, M. Use of model predictive control and weather forecasts for energy efficient building climate control. Energy Build. 2012, 45, 15–27. [Google Scholar] [CrossRef]
  44. Grant, P.; Gehbauer, C. Evaluating the impacts of weather forecast inaccuracy on performance of model predictive control for dynamic facades. In Proceedings of the 2022 Building Performance Modeling Conference and SimBuild, Chicago, IL, USA, 14–16 September 2022; pp. 217–224. [Google Scholar]
  45. Hodge, B.-M.; Lew, D.; Milligan, M. Wind Power Forecasting Error Distributions: An International Comparison; NREL/CP-5500-56130; National Renewable Energy Laboratory: Golden, CO, USA, 2012. [Google Scholar]
  46. Antonanzas, J.; Osorio, N.; Escobar, R.; Urraca, R.; Martínez-de-Pison, F.J.; Antonanzas-Torres, F. Review of photovoltaic power forecasting. Sol. Energy 2016, 136, 78–111. [Google Scholar] [CrossRef]
  47. Weron, R. Electricity price forecasting: A review of the state-of-the-art with a look into the future. Int. J. Forecast. 2014, 30, 1030–1081. [Google Scholar] [CrossRef]
  48. Parisio, A.; Rikos, E.; Glielmo, L. Stochastic model predictive control for economic/environmental operation management of microgrids: An experimental case study. J. Process Control 2016, 43, 24–37. [Google Scholar] [CrossRef]
  49. Bouffard, F.J.; Galiana, F.D. Stochastic security for operations planning with significant wind power generation. IEEE Trans. Power Syst. 2008, 23, 306–316. [Google Scholar] [CrossRef]
  50. Alipour, M.; Chitsaz, H.; Zareipour, H.; Wood, D. Microgrid energy management: How uncertainty modelling impacts economic performance. IET Gener. Transm. Distrib. 2019, 13, 5504–5510. [Google Scholar] [CrossRef]
  51. Das, A.; Ni, Z. A novel fitted rolling horizon control approach for real-time policy making in microgrid. IEEE Trans. Smart Grid 2020, 11, 3535–3544. [Google Scholar] [CrossRef]
  52. Fernández, G.; Oliván Monge, M.Á.; Sediles Ortiz, J.; Muñoz Zuara, A.; Bruna Romero, J.; Bludszuweit, H.; Prieto Borrero, I. Transformation of a microgrid into a distribution-grid support asset: UC-7 Málaga. In Proceedings of the 25th International Conference Electricity Distribution (CIRED 2019), Madrid, Spain, 3–6 June 2019; pp. 1–5. [Google Scholar]
  53. Elkazaz, M.; Sumner, M.; Thomas, D. A hierarchical two-stage energy management for a home microgrid using model predictive and real-time controllers. Appl. Energy 2020, 269, 115118. [Google Scholar] [CrossRef]
  54. REEFLEX Project. Available online: https://reeflexhe.eu/ (accessed on 2 December 2025).
  55. ECOASIS Project. Available online: https://circutor.com/empresa/innovacion/ecoasis/?gad_source=1&gad_campaignid=22781287628&gbraid=0AAAAADlsprZKzu86ZAzqt0eLRAi05E8Rz&gclid=CjwKCAiA3L_JBhAlEiwAlcWO55Zk_cXd4AvIZybtuSe6eSRH9kNGbGPvVpXuv0yTQbQYvqN-5mfwIhoCjl0QAvD_BwE (accessed on 2 December 2025).
  56. Wright, A.J.; Firth, S.K. The nature of domestic electricity-loads and effects of time averaging on statistics and on-site generation calculations. Appl. Energy 2007, 84, 389–403. [Google Scholar] [CrossRef]
  57. Cao, S.; Sirén, K. Impact of simulation time-resolution on the matching of PV production and household electric demand. Appl. Energy 2014, 128, 192–208. [Google Scholar] [CrossRef]
  58. Ayala-Gilardón, A.; Sidrach-de-Cardona, M.; Mora-López, L. Influence of time resolution in the estimation of self-consumption and self-sufficiency of photovoltaic facilities. Appl. Energy 2018, 229, 990–997. [Google Scholar] [CrossRef]
  59. Burgio, A.; Menniti, D.; Sorrentino, N.; Pinnarelli, A.; Leonowicz, Z. Influence and Impact of Data Averaging and Temporal Resolution on the Assessment of Energetic, Economic and Technical Issues of Hybrid Photovoltaic-Battery Systems. Energies 2020, 13, 354. [Google Scholar] [CrossRef]
  60. Marín, L.G.; Sumner, M.; Muñoz-Carpintero, D.; Köbrich, D.; Pholboon, S.; Sáez, D.; Núñez, A. Hierarchical Energy Management System for Microgrid Operation Based on Robust Model Predictive Control. Energies 2019, 12, 4453. [Google Scholar] [CrossRef]
  61. Polimeni, S.; Meraldi, L.; Moretti, L.; Leva, S.; Manzolini, G. Development and experimental validation of hierarchical energy management system based on stochastic model predictive control for Off-grid Microgrids. Adv. Appl. Energy 2021, 2, 100028. [Google Scholar] [CrossRef]
  62. Jin, X.; Wu, J.; Mu, Y.; Wang, M.; Xu, X.; Jia, H. Hierarchical microgrid energy management in an office building. Appl. Energy 2017, 208, 480–494. [Google Scholar] [CrossRef]
  63. Luo, F.; Ranzi, G.; Wang, S.; Dong, Z.Y. Hierarchical Energy Management System for Home Microgrids. IEEE Trans. Smart Grid 2019, 10, 5536–5546. [Google Scholar] [CrossRef]
  64. Lu, J.; Hu, J.; Yu, J.; Cao, J. Two-stage robust scheduling and real-time load control of community microgrid with multiple uncertainties. Int. J. Electr. Power Energy Syst. 2024, 155, 109684. [Google Scholar] [CrossRef]
  65. Guerrero, J.M.; Vasquez, J.C.; Matas, J.; de Vicuna, L.G.; Castilla, M. Hierarchical Control of Droop-Controlled AC and DC Microgrids—A General Approach Toward Standardization. IEEE Trans. Ind. Electron. 2011, 58, 158–172. [Google Scholar] [CrossRef]
  66. Cárdenas, P.A.; Martínez, M.; Molina, M.G.; Mercado, P.E. Development of Control Techniques for AC Microgrids: A Critical Assessment. Sustainability 2023, 15, 15195. [Google Scholar] [CrossRef]
  67. Oliveira, D.Q.; Saavedra, O.R.; Santos-Pereira, K.; Pereira, J.D.F.; Cosme, D.S.; Veras, L.S.; Bento, R.G.; Riboldi, V.B. A critical review of energy storage technologies for microgrids. Energy Syst. 2025, 16, 1063–1092. [Google Scholar] [CrossRef]
  68. Chatzigeorgiou, N.G.; Theocharides, S.; Makrides, G.; Georghiou, G.E. A review on battery energy storage systems: Applications, developments, and research trends of hybrid installations in the end-user sector. J. Energy Storage 2024, 86, 111192. [Google Scholar] [CrossRef]
  69. Marcos, J.; Storkël, O.; Marroyo, L.; Garcia, M.; Lorenzo, E. Storage requirements for PV power ramp-rate control. Sol. Energy 2014, 99, 28–35. [Google Scholar] [CrossRef]
  70. de la Parra, I.; Marcos, J.; García, M.; Marroyo, L. Control strategies to use the minimum energy storage requirement for PV power ramp-rate control. Sol. Energy 2015, 111, 332–343. [Google Scholar] [CrossRef]
  71. Akram, U.; Nadarajah, M.; Shah, R.; Milano, F. A review on rapid responsive energy storage technologies for frequency regulation in modern power systems. Renew. Sustain. Energy Rev. 2020, 120, 109626. [Google Scholar] [CrossRef]
  72. Becchi, L.; Belloni, E.; Bindi, M.; Intravaia, M.; Grasso, F.; Lozito, G.M.; Piccirilli, M.C.A. Computationally Efficient Rule-Based Scheduling Algorithm for Battery Energy Storage Systems. Sustainability 2024, 16, 10313. [Google Scholar] [CrossRef]
  73. Camblong, H.; Zapirain, I.; Curea, O.; Ugartemendia, J.; Boussaada, Z.; Zamora, R. Rule-Based Energy Management System to Enhance PV Self-Consumption in a Building: A Real Case. Energies 2024, 17, 6099. [Google Scholar] [CrossRef]
  74. Solar Cast, Live and Forecast Accuracy. Available online: https://solcast.com/forecast-accuracy (accessed on 5 January 2026).
Figure 1. Adaptable Two-Stage Deterministic EMS schema.
Figure 1. Adaptable Two-Stage Deterministic EMS schema.
Applsci 16 01844 g001
Figure 2. Example of a generic microgrid schema.
Figure 2. Example of a generic microgrid schema.
Applsci 16 01844 g002
Figure 3. Test site schema (part of Figure 2) in an isolated mode.
Figure 3. Test site schema (part of Figure 2) in an isolated mode.
Applsci 16 01844 g003
Figure 4. Solar PV inverter data: real 5 s data (P_5s line) and discretized 1 min (P_1min line), 5 min (P_5min line), 15 min (P_15min line), and hourly data (P_1h line).
Figure 4. Solar PV inverter data: real 5 s data (P_5s line) and discretized 1 min (P_1min line), 5 min (P_5min line), 15 min (P_15min line), and hourly data (P_1h line).
Applsci 16 01844 g004
Figure 5. Error vs. discretization effect comparison, data from Table 10, Table 11, Table 12, Table 13, Table 14, Table 15, Table 16 and Table 17.
Figure 5. Error vs. discretization effect comparison, data from Table 10, Table 11, Table 12, Table 13, Table 14, Table 15, Table 16 and Table 17.
Applsci 16 01844 g005
Table 1. Test site assets parameters.
Table 1. Test site assets parameters.
AssetParameterValue
Test site microgridGrid connectionIsolated
Solar PV systemRated power12 kW
Power range0–12 kW
BESSTechnologyLithium ion
Total capacity53.9 kWh
Minimum SoC10%, 5.39 kWh
Max charging power26.6 kW
Max discharging power53.9 kW
Bus connectionDirect connection/no converter
Estimated life5000 cycles
Batt cost500 €/kWh
EV chargerRated power50 kW
Efficiency95%
Hydrogen system/fuel cellMax power100 kW
Min power10 kW
Efficiency50–60%
Hydrogen storageCapacity41 kg
200 bar
Hydrogen system/electrolyserNo electrolyserHydrogen refuelling from external sources
Table 2. Granularity and platform effect on the objective function in the first set of tests.
Table 2. Granularity and platform effect on the objective function in the first set of tests.
Objective Function ComparisonCloud Execution
10 min Granularity
Cloud Execution
15 min Granularity
Cloud Execution
1 h Granularity
Edge Execution (500 MB Limit)
10 min Granularity
Edge Execution (500 MB Limit)
15 min Granularity
Max value [€]−24.59−26.68−26.47−26.56−26.51
Min value [€]−119.34−119.22−99.88−119.33−119.32
Average value [€]−80.22−80.12−57.86−80.23−80.15
Table 3. Granularity and platform effect on the objective function in the second set of tests.
Table 3. Granularity and platform effect on the objective function in the second set of tests.
Objective Function ComparisonCloud Execution
10 min Granularity
Cloud Execution
15 min Granularity
Cloud Execution
1 h Granularity
Edge Execution (500 MB Limit)
10 min Granularity
Edge Execution (500 MB Limit)
15 min Granularity
Max of [€]−25.49−25.55−22.3−25.43−25.38
Min of [€]−109.37−105.34−84.7−108−105.99
Average of [€]−72.07−72.12−49.39−72.1−72.1
Execution Time ComparisonCloud Execution
10 min Granularity
Cloud Execution
15 min Granularity
Cloud Execution
1 h Granularity
Edge Execution (500 MB Limit)
10 min Granularity
Edge Execution (500 MB Limit)
15 min Granularity
Max execution time [seg]3011496300300
Min execution time [seg]21<1<1<1
Average execution time [seg]15818735
Table 4. Granularity and forecast error effects on the objective function for 15 min granular tests.
Table 4. Granularity and forecast error effects on the objective function for 15 min granular tests.
Objective Function ComparisonCloud Execution
15 min Granularity
Error: 0%
Cloud Execution
15 min Granularity
Error: 5%
Cloud Execution
15 min Granularity
Error: 15%
Cloud Execution
15 min Granularity
Error: 25%
Max value [€]−26.6784−26.5168−26.4801−26.6742
Min value [€]−119.3277−119.3305−119.3286−119.3213
Average value [€]−80.1535−80.2699−80.2374−80.131
Difference from no error
(NMAE y NRMSE)
- - -1.49%1.538%0.58%
2.36%2.37%1.47%
Table 5. Granularity and forecast error effect on the objective function for 1 h granular tests.
Table 5. Granularity and forecast error effect on the objective function for 1 h granular tests.
Objective Function ComparisonCloud Execution
1 h Granularity
Error: 0%
Cloud Execution
1 h Granularity
Error: 5%
Cloud Execution
1 h Granularity
Error: 15%
Cloud Execution
1 h Granularity
Error: 25%
Max value [€]−26.4703−26.4694−26.4672−26.4663
Min value [€]−100.2547−100.2320−100.3963−100.3817
Average value [€]−55.3253−54.8228−56.1315−56.5652
Difference from no error
(NMAE y NRMSE)
- - -1.34%2.95%4.42%
2.37%4.75%6.78%
Table 6. Error associated with discretization in solar PV inverter generation.
Table 6. Error associated with discretization in solar PV inverter generation.
Granularity DataMAE (W)RMSE (W)
1 min24.3285.38
5 min57.90163.50
15 min108.19261.37
1 h180.53382.09
Table 7. BESS needs to adapt set points and maintain the objective function according to discretization errors.
Table 7. BESS needs to adapt set points and maintain the objective function according to discretization errors.
Granularity DataP_95 abs (W)P_99 abs (W)P_max abs (W)E_cap (Wh)
1 min128.3396.71884.411.3
5 min323.3757.02678.740.3
15 min630.31192.32321.5101.4
1 h875.61637.62615.8314.6
Table 8. 5 s delay effect 1 min discretization.
Table 8. 5 s delay effect 1 min discretization.
Delay and K ValueMAE (W)RMSE (W)
1 min discretization
(reference error)
24.3285.38
5 s delay, K = 112.6858.01
5 s delay, K = 0.515.6758.51
5 s delay, K = 024.3285.375
Table 9. 5 s delay effect 1 h discretization.
Table 9. 5 s delay effect 1 h discretization.
Delay and K ValueMAE (W)RMSE (W)
1 h discretization
(reference error)
180.53382.09
5 s delay, K = 112.6858.01
5 s delay, K = 0.591.46195.38
5 s delay, K = 0180.53382.09
Table 10. Solar PV generation forecast error (normally distributed forecasting error, μ = 0 and σ = 5%), 5 s delay effect, and 1 min discretization.
Table 10. Solar PV generation forecast error (normally distributed forecasting error, μ = 0 and σ = 5%), 5 s delay effect, and 1 min discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 139.2299.55
5 s delay, K = 0.540.4199.03
5 s delay, K = 045.74116.24
Table 11. Solar PV generation forecast error (normally distributed forecasting error, μ = 0 and σ = 5%), 5 s delay effect, and 1 h discretization.
Table 11. Solar PV generation forecast error (normally distributed forecasting error, μ = 0 and σ = 5%), 5 s delay effect, and 1 h discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 139.2299.55
5 s delay, K = 0.599.10212.73
5 s delay, K = 0184.95391.93
Table 12. Solar PV generation forecast error (MAPE = 10%), 5 s delay effect, and 1 min discretization.
Table 12. Solar PV generation forecast error (MAPE = 10%), 5 s delay effect, and 1 min discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1181.45425.51
5 s delay, K = 0.5181.75425.79
5 s delay, K = 0183.96430.51
Table 13. Solar PV generation forecast error (MAPE = 10%), 5 s delay effect, and 1 h discretization.
Table 13. Solar PV generation forecast error (MAPE = 10%), 5 s delay effect, and 1 h discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1181.45425.51
5 s delay, K = 0.5205.75466.46
5 s delay, K = 0260.82571.93
Table 14. Solar PV generation forecast error (MAPE = 15%), 5 s delay effect, and 1 min discretization.
Table 14. Solar PV generation forecast error (MAPE = 15%), 5 s delay effect, and 1 min discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1270.95633.09
5 s delay, K = 0.5271.13633.35
5 s delay, K = 0272.74636.61
Table 15. Solar PV generation forecast error (MAPE = 15%), 5 s delay effect, and 1 h discretization.
Table 15. Solar PV generation forecast error (MAPE = 15%), 5 s delay effect, and 1 h discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1270.95633.09
5 s delay, K = 0.5288.78661.96
5 s delay, K = 0331.74740.67
Table 16. Solar PV generation forecast error (MAPE = 10% first day and 15% second day), 5 s delay effect, and 1 min discretization.
Table 16. Solar PV generation forecast error (MAPE = 10% first day and 15% second day), 5 s delay effect, and 1 min discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1164.28429.43
5 s delay, K = 0.5164.98429.68
5 s delay, K = 0168.02434.35
Table 17. Solar PV generation forecast error (MAPE = 10% first day and 15% second day), 5 s delay effect, and 1 h discretization.
Table 17. Solar PV generation forecast error (MAPE = 10% first day and 15% second day), 5 s delay effect, and 1 h discretization.
Forecast Error/Delay and Correction EffectMAE (W)RMSE (W)
5 s delay, K = 1164.28429.43
5 s delay, K = 0.5197.24470.46
5 s delay, K = 0259.70575.55
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Fernández, G.; Sanz Osorio, J.F.; Rocca, R.; Luengo-Baranguan, L.; Torres, M. Practical Considerations for the Development of Two-Stage Deterministic EMS (Cloud–Edge) to Mitigate Forecast Error Impact on the Objective Function. Appl. Sci. 2026, 16, 1844. https://doi.org/10.3390/app16041844

AMA Style

Fernández G, Sanz Osorio JF, Rocca R, Luengo-Baranguan L, Torres M. Practical Considerations for the Development of Two-Stage Deterministic EMS (Cloud–Edge) to Mitigate Forecast Error Impact on the Objective Function. Applied Sciences. 2026; 16(4):1844. https://doi.org/10.3390/app16041844

Chicago/Turabian Style

Fernández, Gregorio, J. F. Sanz Osorio, Roberto Rocca, Luis Luengo-Baranguan, and Miguel Torres. 2026. "Practical Considerations for the Development of Two-Stage Deterministic EMS (Cloud–Edge) to Mitigate Forecast Error Impact on the Objective Function" Applied Sciences 16, no. 4: 1844. https://doi.org/10.3390/app16041844

APA Style

Fernández, G., Sanz Osorio, J. F., Rocca, R., Luengo-Baranguan, L., & Torres, M. (2026). Practical Considerations for the Development of Two-Stage Deterministic EMS (Cloud–Edge) to Mitigate Forecast Error Impact on the Objective Function. Applied Sciences, 16(4), 1844. https://doi.org/10.3390/app16041844

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop