Demand Flexibility Management for Buildings-to-Grid Integration with Uncertain Generation

: We present a Buildings-to-Grid (BtG) integration framework with intermittent wind-power generation and demand flexibility management provided by buildings. First, we extend the existing BtG models by introducing uncertain wind-power generation and reformulating the interactions between the Transmission System Operator (TSO), Distribution System Operators (DSO), and buildings. We then develop a uniﬁed BtG control framework to deal with forecast errors in the wind power, by considering ancillary services from both reserves and demand-side ﬂexibility. The resulting framework is formulated as a ﬁnite-horizon stochastic model predictive control (MPC) problem, which is generally hard to solve due to the unknown distribution of the wind-power generation. To overcome this limitation, we present a tractable robust reformulation, together with probabilistic feasibility guarantees. We demonstrate that the proposed demand ﬂexibility management can substitute the traditional reserve scheduling services in power systems with high levels of uncertain generation. Moreover, we show that this change does not jeopardize the stability of the grid or violate thermal comfort constraints of buildings. We ﬁnally provide a large-scale Monte Carlo simulation study to conﬁrm the impact of achievements.


Introduction
An essential requirement of power grids with high wind-power penetration is the ancillary reserve power service, which can reduce unwanted power curtailment and enable higher integration of renewable generation. The reserve scheduling task of the Transmission System Operator (TSO) in power grids deals with day-ahead scheduling of the generator reserve power, in order to compensate for mismatches between the forecast and actual wind power [1]. Due to the growing penetration levels of wind-power generation, TSOs need to deal with increasing levels of uncertainty, thus imposing novel challenges and responsibilities for TSOs to avoid blackouts and other contingencies. This trend highlights the necessity for TSOs to introduce new types of ancillary services by enabling end-users (buildings) demand-side flexibility.
Approximately 40% of the global energy is consumed by buildings, with half of this being directly related to Heating, Ventilation, and Air Conditioning (HVAC) [2,3]. Buildings control decisions are typically only optimized locally to minimize energy consumption, but not in the wider scope of optimal control of the electricity grid. Demand-side flexibility of buildings represents the capability to In this paper, we propose a unified dynamical BtG framework by modeling the building demand-side flexibility, while also explicitly formulating the hierarchical interactions between the TSO, DSOs, and buildings. Such a demand-side flexibility asset can be considered to be a short-term operating reserve, which may yield an economic benefit in a robust fashion. The main novelty of this paper is that the proposed demand-side flexibility model in the BtG framework with uncertain generation can substitute the traditional reserve scheduling service in power systems with wind farms, without losing stability properties of the power grid and violating the buildings desired thermal comfort. This paper extends our previous work in [21,22], by presenting explicit expressions to quantify the available building demand-side flexibility from specific assets, and by providing more detailed insights in both the theoretical and experimental results.
The remaining part of this paper is organized as follows. In Section 2, we present the BtG model dynamics, and ancillary service deployment via traditional reserves and demand-side flexibility is discussed in Section 3. Using the proposed BtG model dynamics, we provide a stochastic MPC formulation in Section 4, and then a robust tractable reformulation in Section 5 to achieve a desired level of constraints fulfillment with a-priori probabilistic certificates. We simulate an extended version of an IEEE benchmark case study in Section 6, to demonstrate the functionality of our proposed hierarchical integrated energy system model and control technique. Finally, our main conclusions are summarized in Section 7.

Buildings-to-Grid System Modeling
Consider a hierarchical electrical energy network consisting of one TSO network together with a wind farm production unit connected to multiple DSO networks, to which individual buildings are connected.

Wind Integrated TSO Model Dynamics
Consider T = {1, . . . , n t } to be the set of TSO buses (nodes), G = {1, . . . , n g } to be the set of TSO generators, and D = {1, . . . , n d } to be the set of DSOs connected to the TSO network. Define also Γ ∈ R n t ×n g to be an incidence matrix such that the entries, Γ k,m , relate generators to the TSO buses, respectively. The set of neighboring nodes of TSO bus k is defined by T n k . The TSO network is modeled using the existing swing equation model, e.g., [21,23], where we extend the active power swing equation for bus k by integrating wind-power production in the following form: where δ k (t),δ k (t) andδ k (t) are the voltage angle, angular velocity (frequency), and angular acceleration of bus k, and m k and d k are inertia and damping coefficients, respectively. The power flow between buses is considered to be purely reactive, and is characterized by the line susceptance, b kj = b jk , and the difference in voltage angle, δ k (t) − δ j (t). The susceptance is the imaginary part of admittance, which is a measure of how easily a circuit will allow a current to flow through a line [24]. P GR m denotes the power dispatch of generator m, P w k is the wind farm power injection at bus k, and P LD k is the load of any DSO network connected to bus k. Furthermore, R m and S LD k are generator reserve and demand-side flexibility power contributions, respectively, which are defined formally in Section 3, and are used to compensate for errors in the wind-power forecast. Without loss of generality, it is assumed that P w k is a realization of an unknown stochastic process defined on some probability space (W, B(W ), P). It is important to note that we do not require the sample space W and the probability measure P to be known explicitly, as will be explained later. We only need a finite number of realizations of the uncertain variable P w k , and it is sufficient to consider that they are independent and identically distributed (i.i.d). The second order differential equation for TSO bus k in Equation (1) can be rewritten as two first-order equations, by defining the angular frequency deviation ω k = ω true k − ω 0 , where ω true k is the absolute frequency of bus k, and ω 0 is the synchronous frequency. Using this notation, the complete TSO network dynamics are captured in the following state-space model: with state variable x t (t) = [δ 1 , . . . , δ n t , ω 1 , . . . , ω n t ] , and appropriate matrices A t , B GR , and B LD . For the full derivation of the system parameters for a similar model without wind-power integration, the reader is referred to [17,21,25]. The element of vector Ψ(δ(t)) ∈ R n t for bus k is defined as ψ k = ∑ j∈T n k b kj sin(δ k (t) − δ j (t)). P LD (t) ∈ R n t and S LD (t) ∈ R n t represent the power demand and flexibility from all DSO networks connected to the TSO, respectively, and are obtained as follows: where P i LD , S i LD ∈ R n t represent the load and flexibility of DSO i on each TSO bus, respectively. P i IMP ∈ R n t ×n i d with entries P i IMP,kl denotes the active power flow from TSO bus k to bus l of DSO i, and is nonzero only for border buses (i.e., buses that are physically connected via a line). Similarly, S i IMP represents the flexibility power flow between the TSO and DSO i.

Remark 1.
To determine the power flow across the TSO and DSO networks, we follow a DC power approximation and follow the small-angle approximation to assume that sin(δ k (t) − δ j (t)) ≈ (δ k (t) − δ j (t)). Using such an approximation and letting L t be the set of lines in the TSO network, we can define the Laplacian matrix L TSO ∈ R |L t |×n t for the TSO network with entries defined by We can now construct the following augmented matrix which can be used to obtain the power flow in the TSO network lines:L TSO = L TSO 0 n t ×n t 0 n t ×n t 0 n t ×n t . (

3)
A similar expression can be written for DSO network to obtainL DSO,i for DSO i.

DSO Model Dynamics
Consider D i = {1, . . . , n i d } to be the set of buses (nodes) of DSO i. Denote by D n,i l the neighborhood set of node l of DSO i. Each DSO network is connected to the parent TSO through one or multiple border buses. DSO network dynamics are the same as in Equation (1), but with the additional assumption that no generators are connected to DSO buses, leading to m = 0 and d = 0 in the DSO swing equations. Please note that this is not a restrictive assumption, as the model can easily be extended to include generation in the DSO network as well. The dynamics at bus l of DSO i are described aŝ where the subscript in [·] l denotes element l of the respective vector,d i lδ i l (t) is the frequency-sensitive portion of the uncontrollable load at bus l, and P i BD l (t), S i BD l (t) denote the total building demand and flexibility at bus l of DSO i. The resulting state-space model for DSO i is given by: is the state vector, and A i d and B i d are system matrices. The parameter Ψ i (δ i (t)) ∈ R n i d and its element for bus l are defined as ψ i l = ∑ j∈D n,i ). The total building demand P i BD (t) and flexibility S i BD (t) at node l can be determined as follows: , where incidence matrix Π i ∈ R n i d ×n b relates the buses of DSO i to the n b buildings in the network. Each building is assumed to be connected to exactly one DSO bus, and thus, ∑ i∈D (Π i ) 1 n i d = 1 n b . P stor (t), P hvac (t), P misc (t) ∈ R n b are the power storage, HVAC power demand, and uncontrollable miscellaneous power consumption of all buildings, respectively. Finally, S stor (t), S hvac (t) ∈ R n b represent the total storage and the total building HVAC flexibility, respectively.

Building Thermal Comfort Model
The framework developed in this paper explicitly couples building decision variables to the power grid. Traditional resistance and capacitor (RC) networks are widely used to model thermodynamics of building envelopes [15]. Both highly detailed models with variables for many zones, e.g., [26][27][28], and low order models with a single lumped zone, e.g., [17,18], have been proposed in the literature. As the envisioned purpose of the framework is to integrate large clusters of buildings into the grid, a low order thermal building model is most appropriate, considering the resulting computational complexity. Using the 3R-2C circuits model for each building adopted from [17], consider the thermal dynamics:Ṫ where T wall (t) and T zone (t) are the wall and zone (interior room) temperatures, respectively, and T amb (t) is the ambient temperature. The resistance of the external walls, internal walls, and windows are given by the resistance parameters R 1 , R 2 and R win . The lumped thermal capacities of the building exterior walls and the zone are denoted by C wall and C zone , respectively. Moreover, Q sol (t) represents the sum of the solar radiation absorbed on the external walls, andQ int (t) is the total heat gain from internal sources. The room temperature is controlled by the cooling loadQ hvac (t), which is proportional to the HVAC power consumption viaQ hvac (t) = µ hvac (P hvac (t) + S hvac (t)). The thermal dynamics in Equation (5) for an individual building are written as the following state-space model:ẋ is an uncertain vector. Please note that for the buildings model, we considerw l b to be equivalent to the forecast value of the uncertain parameters. For the explicit derivation of system matrices A l b , B l , andB l , we refer the reader to [21]. Since we aim to describe the dynamics of clusters of buildings, let n b be the total number of buildings, and denote by B = {1, . . . , n b } the full set of buildings connected to the grid. In the absence of communication between buildings, the dynamics of all buildings combined are described by the following state-space model with block diagonal system matrices (full matrix definitions are omitted for brevity):ẋ

Electrical Energy Storage Model
Define x j s (t) ∈ R to be the energy state variable (state of charge, or SoC) and P j stor (t), S j stor (t) ∈ R the normal and flexibility power input rate variable, respectively, for a dedicated electrical storage unit j of building j ∈ B. Consider now the discrete-time dynamical model of storage unit j as: where x j s (0) = x j,0 s is the given initial SoC, h is the discretization step size, and ξ and η are efficiency coefficients of the storage unit. Although the current equation models energy loss proportionally, higher order equations for losses can be modeled as well. Denote by Ξ and Ω the diagonal matrices composed of ξ l and η l for all buildings l ∈ B, respectively. (1), (4), and (6), respectively, are continuous-time. To formulate a discrete optimal control problem in the MPC paradigm, the dynamics are discretized using the first-order backward Euler implicit method proposed in [29]. The discretized dynamics in the three distinct model areas are then denoted by the following functions:

Remark 2. The proposed models for the TSO, DSO, and building thermal comfort dynamics in Equations
for all time steps k = 1, 2, . . . , N sim , such that N sim is the finite-time step of the simulation study.

Ancillary Service Deployment
In this section, we first describe common practice in the TSO network to deal with highly fluctuating wind-power integration, the so-called reserve scheduling service, and then present a novel formulation for building demand flexibility to be deployed as an ancillary service to handle uncertain wind power in the energy network.

Reserve Scheduling Formulation
Wind-power generation suffers from uncertainty and limited predictability [30]. Consider P f w ∈ R n w to be the forecast value of the wind power for every wind farm in the set F = {1, . . . , n w }, and denote the error between forecast and actual power by ∆P w = P w − P f w . When ∆P w = 0, the power balance in the TSO network between production and demand is not satisfied anymore. To restore power balance, the common practice is to deploy so-called reserve power such that by adjusting the generator power output, forecast errors are compensated with altered generation (denoted by R ∈ R n g ). Increasing the generator output is called up-spinning reserve (R us ≥ 0), and decreasing the output is down-spinning reserve (R ds ≥ 0). To schedule the reserve power, one can define the reserve power as follows: and consider −R ds (k) ≤ R(k) ≤ R us (k), to determine R ds (k) and R us (k) at each time step k. Please note that the new scheduled power should also satisfy the generation limits, i.e., P min GR ≤ P GR (k) + R(k) ≤ P max GR , where P min GR and P max GR are the minimum and maximum limits of power generation units, respectively.

Building Flexibility Formulation
Define S ∈ R n b to be the building flexibility and consider the capability to increase energy consumption as increased-demand flexibility (S id ≥ 0) and the capability to decrease energy consumption as decreased-demand flexibility (S dd ≥ 0). If instead of generator reserve power, demand flexibility is used to mitigate the wind-power forecast error, one can schedule the flexibility as follows: and consider −S dd (k) ≤ S(k) ≤ S id (k), to determine S dd (k) and S id (k) at each time step k.
Consider now the flexibility contribution of individual buildings in the network via two sources: (1) building storage systems, and (2) building HVAC loads, which yields the following bounds on the building flexibility at time step k: where S id stor , S id hvac , S dd stor , and S dd hvac represent the increased-and decreased-demand flexibility using the storage unit and HVAC load, respectively. The available storage flexibility of building l ∈ B can be formulated as: where h is the discretization step size, and x min s , x max s , P min stor , and P max stor are the SoC limits and storage power limits, respectively. Storage flexibility is defined as the margin between the current storage power P stor (k) and the upper and lower bounds, respectively, constrained by the SoC limits on x s (k). As indicated in Figure 1, increased-demand storage flexibility (S id stor ) is the maximum amount of power with which P stor (k) can be increased for one time step width h, such that both the maximum storage power injection constraint (Figure 1a) and the storage energy limit (Figure 1b) are still satisfied. A similar expression is derived for the available HVAC flexibility of building l ∈ B, such that both HVAC power limits and building comfort levels are still satisfied: where P min hvac , P max hvac are the minimum and maximum limits of HVAC power usage, respectively. P dd,l hvac (k) and P id,l hvac (k) are the minimum and maximum HVAC power such that the comfort level constraints are still satisfied: where T max zone (k) and T min zone (k) represent the thermal comfort level limits at time k. Positive HVAC flexibility is visualized in Figure 2, showing that the limiting term is either the HVAC power (Figure 2a) or the thermal comfort level (Figure 2b).
(a) P max hvac as limiting term Time steps h (b) T min zone as limiting term Figure 2. Visualization of positive HVAC flexibility.

Reserve Scheduling Together with Building Flexibility
Including both reserve and flexibility in the grid power balance yields where the sum of reserve and flexibility mitigates the total wind-power forecast error: Based on Equation (12), the following constraint encodes that the scheduled reserve and flexibility is always sufficient to compensate the wind-power error:

Stochastic MPC Formulation
Model predictive control (MPC) is a flexible paradigm that defines receding-horizon-based optimization problems, enabling the specification of time-domain objectives together with the ability to explicitly enforce constraints on system dynamics. Two extensions to MPC exist when the system dynamics and/or constraints are subject to uncertainties, namely robust and stochastic MPC. Robust MPC is able to handle the uncertainties using the so-called worst-case approach while still ensuring that the state constraints are met. Alternatively, stochastic MPC has attractive features, due to its ability to handle uncertain systems in a less conservative way. Stochastic MPC considers the stochastic characteristics of the uncertainties and treats system constraints in a probabilistic manner, i.e., using chance constraints. In this section, we formulate a receding horizon stochastic optimization problem to compute an optimal decisions sequence that minimizes a given objective function, subject to the uncertain BtG model dynamics and chance constraints.
Given the set of prediction time steps N h = {0, 1, ..., N h } such that N h is the length of the prediction horizon, consider the concatenated vector of control decision variables to be U k = [P GR ( |k), P hvac ( |k), P stor ( |k), R us ( |k), R ds ( |k), S id hvac ( |k), S dd hvac ( |k), S id stor ( |k), S dd stor ( |k)] ∈N h .
The objective function consists of two parts. The first part penalizes TSO and DSO grid frequency deviations, while part two accounts for the operating costs, e.g., power generation, etc. The initial grid state variables are given by x k := [x t (0|k), [x i d (0|k)] ∀i∈D ] , the vector of uncertainty is P w k := [P w ( |k) ∈N h ], and Q t , {Q i d } i∈D , Q GR , and Q hvac are diagonal cost matrices associated with the TSO and DSO states, generation, and HVAC power usage respectively. Finally, q id S , q dd S , q us R , and q ds R are the cost vectors related to increased-and decreased-demand, up-and down-spinning reserves, respectively. Using these definitions, the cost function can be formulated as follows: The cost function in Equation (18) is a random variable, since it depends on the uncertain TSO and DSO state variables. Therefore, we consider J(x k , U k ) := E[J(x k , U k , P w k )] to obtain a deterministic cost function, which can be approximated empirically following the approach in [31] by averaging the value of its argument for some number S 0 of different realizations of the uncertain variable, which plays a tuning parameter role, i.e., J(x k , U k ) : ]. The discretized dynamics in Equation (9) are non-deterministic, due to the uncertainty in the wind, reserve, and flexibility power. To obtain a set of deterministic dynamics, consider now the special case when P w = P f w , and denote the corresponding TSO, DSO, building, and storage dynamics by In this case, ∆P w = 0, which means that the optimal reserve and flexibility contributions as determined in Equation (16) are both zero. Using this notation, we are in a position to formulate a finite-horizon stochastic control problem for each sampling time k using the following optimization program: • TSO deterministic frequency model dynamics: • TSO generation, ramping, line, and balance constraints: where P down GR and P up GR are ramping limits of power generation units,L TSO is defined in Remark 1, and L min and L max are the TSO power flow limits.
• DSO deterministic frequency dynamics, ∀i ∈ D: • DSO power line and balance constraints, ∀i ∈ D: whereL DSO,i is defined in Remark 1, and L i,min and L i,max are the DSO power flow limits. • Buildings deterministic thermal comfort dynamics: • Buildings thermal comfort, power balance, and HVAC usage constraints: are the minimum and maximum bounds for the desired thermal comfort of buildings. • Buildings electrical storage unit dynamics: • Buildings storage capacity and power usage constraints: • Probabilistic constraint: where x t (·) and x i d (·) are given by Equation (9), ε ∈ (0, 1) is the level of admissible constraint violation, a = ∑ i∈G R us ( |k) + ∑ l∈B (S dd,l hvac ( |k) + S dd,l stor ( |k)), b = ∑ m∈F (P w ( |k) − P f w ( |k)), and c = ∑ i∈G R ds ( |k) + ∑ l∈B (S id,l hvac ( |k) + S id,l stor ( |k)), such that the formulation for S id hvac ( |k), S dd hvac ( |k), S id stor ( |k), and S dd stor ( |k) are given in Section 3.2.
The constraint Equation (19i) is a chance constraint, which ensures that the feasibility probability for the constraint is above the specified level. Using the proposed chance constraint Equation (19i), stochastic MPC offers an alternative approach to robust MPC. Since stochastic MPC directly incorporates the trade-off between constraint feasibility and control performance, the corresponding solutions are generally less conservative.
Please note that Equations (19a)-(19h) are all based on the deterministic BtG dynamics for the special case when no ancillary services are required, i.e., ∆P w , R, S LD , S IMP , S BD , S hvac , and S stor are all zero. On the contrary, the probabilistic constraint Equation (19i) depends on the non-deterministic dynamics. Hence, the optimization problem in Equation (19) is a finite-horizon, chance-constrained quadratic program, whose stages are coupled by the dynamics of the TSO, DSO, buildings thermal comfort, and storage systems at each sampling time k. We note that the proposed optimization program in Equation (19) is in general a non-convex problem which is hard to solve. The feasible set of Equation (19) is non-convex and hard to determine explicitly in the presence of chance constraints Equation (19i). In the following section, we will develop a tractable framework to obtain a probabilistically feasible solution

Tractable Robust MPC Reformulation
Using a more compact notation, the chance constraints Equation (19i) can be written as To this end, we approximate the proposed probabilistic constraints in Equation (20) using the following robust reformulation: where W is a bounded uncertainty set compared to W which is an unbounded and unknown uncertainty set in Equation (20). In the perspective of power systems, the proposed tractable reformulation Equation (21) translates the unbounded set of wind-power scenarios W to a bounded set W which contains the more probable scenarios of wind power with a high level of confidence. Please note that the proposed constraint Equation (21) is a robust constraint, since it should be satisfied for all P w k ∈ W. Obviously, for any feasible solution for Equation (21), P w k ∈ W implies g(x k , U k , P w k ) ≤ 0, P w k ∈ W. Therefore, by choosing W that covers at least a (1 − ε) content of P w k , i.e., W satisfies P{P w k ∈ W} ≥ 1 − ε, any feasible solution for Equation (21) must satisfy implying that it is also feasible for Equation (20) (see [32] for more detailed descriptions). In other words, Proof. The proof is straightforward, and we omit it for the sake of brevity.
Let us now introduce W ⊆ R n w =1 as a bounded set. We assume for simplicity that W is an axis-aligned hyper-rectangular set. Please note that this is not a restrictive assumption and any convex set, e.g., ellipsoids and polytopes, could have been chosen instead as described in [31]. We can define W := [−ω, ω] as an interval, where the vector ω ∈ R n w defines the hyper-rectangle bounds.
Consider now the following optimization problem that aims to determine the set W with minimal volume: where S is a finite number of i.i.d samples P l w k ∈ W needed to be available from either a known distribution W or through historical observations. If we denote by W = [−ω,ω] the optimal solution of Equation (22), then the following proposition provides an explicit relation between the number of required samples S and the (1 − ε)-content set W. Proposition 1. Fix ε ∈ (0, 1), β ∈ (0, 1), determine S ≥ 2 ε (n w + ln 1 β ) , and solve Equation (22) to obtain its optimal solution [−ω,ω] = W. Then, with probability of at least 1 − β, Proof. The proof is based on the results in [33] by noting that the proposed optimization problem Equation (22) is a convex program with the number of decision variables equivalent to the number of uncertain variables n w = 1. We therefore omit the proof for the sake of brevity.
Using the proposed robust reformulation in Equation (21), one can obtain a tractable formulation similar to (Proposition 1, [34]). The obtained solution of the optimization program in Equation (19), where Equation (19i) is replaced with Equation (21), is the optimal input sequence U * k . Following the MPC paradigm, only the first element of the optimal control input is implemented at time k, and we proceed based on the receding horizon principle. This means that at every time step k, the robust reformulation of Equation (19) is solved using the current measurement of the state variables {x t (k), x d (k), x b (k), x s (k)}.

Numerical Case Study
To demonstrate the grid regulative capacity of (a) reserve scheduling and (b) building HVAC and storage flexibility on the BtG system under wind-power penetration, we consider the following three cases in the simulation study: (1) BtG system with only reserve power enabled, (2) BtG system with only flexibility power enabled, (3) BtG system with both reserve and flexibility power enabled. Please note that we consider the same cost coefficients for both reserve and flexibility deployments in the cost function Equation (18). Throughout the simulation horizon, the wind-power penetration is around 10-15% of the total electricity generation in all cases.

Simulation Setup
Consider a network of 1 TSO with 3 generators (GRs), 2 DSOs, 13 buildings, and 1 wind farm (WF), as visualized in Figure 3. The case studies are simulated for N sim = 24 hours with the prediction horizon of an hour and time resolution h = 5 minutes. Thus, the length of the prediction horizon is N h = 60 5 = 12 steps. To generate the number of required scenarios of wind power, we use the Markov chain model in [30]. Following Proposition 1, we choose ε = 0.05, β = 10 −4 , and S = 1328 ≥ 2 (2 × 12 + ln 1 β ) , and then solve Equation (22) to obtain the bounded set W at each sampling time k. The associated cost parameters are Q t = Q d = 1000 rad −2 , power generation and consumption are valued at Q GR = Q hvac = 0.1 MW −2 , and reserve and flexibility scheduling at q R = q S = 1000 MW −1 . Please note that to have a fair comparison, we assumed the same cost coefficients for both reserve and flexibility. Since our simulation study considers large-scale buildings, the limits for each storage unit are set equivalent to four Tesla Model S batteries [35], i.e., P min stor = −2 MW, P max stor = 2 MW, x min s = 2 kW h, and x max s = 400 kW h. Simulations were implemented in MATLAB, with Yalmip as interface [36] and Gurobi as solver [37]. Building parameters and miscellaneous (uncontrollable) load profiles for the large-scale, commercial buildings were adopted from [17]. Grid parameters (line length, cable type, line susceptance, etc.) were obtained from the MatPower IEEE 5-bus power system [38], with some parameters (e.g., power line limits) scaled appropriately for the current simulation studies. For further details on the building and grid parameters, we refer the reader to the sources above. We also carried out Monte Carlo simulations with the system under optimal control input simulated for 10,000 different wind-power scenarios. We obtain a-posteriori the violation probability (empirical violation level), by means of counting the number of trajectories that violate any of the constraints, to check if the theoretical maximum violation level is indeed satisfied.

Simulation Results
The power balance in the TSO network for all cases is presented in Figure 4, showing a reduced production for Case 2 and 3, compared to Case 1. In particular, Case 2 yields a total reduction in conventional generation of 2.7% compared to Case 1, whereas for Case 3, this reduction is 12.8%. The solid black line shows the forecast wind power, and the dark green bars show the actual wind power. As shown in both Figures 4 and 6, between 3:00-11:00 and 15:00-17:00, the wind-power error is negative, ∆P w ≤ 0, and from 12:00-14:00 and 18:00-24:00, the error is positive, ∆P w ≥ 0. To restore the power balance, when ∆P w ≤ 0, Case 2 employs the decreased-demand flexibility and on the contrary, Case 1 uses the up-spinning reserve power to reduce output power dispatch. Similarly, when ∆P w ≥ 0, Case 2 employs the increased-demand flexibility and on the contrary, Case 1 uses the down-spinning reserve power to reduce output power dispatch. Figure 5 depicts the frequency deviations in the TSO and DSO networks for Case 3. Frequency deviations for all the cases are kept well below allowable limits. Enabling building-side flexibility results in a reduction of 5.3% in cumulative squared frequency deviation for the total network, and a reduction of 32.5% in the DSO network only.
The wind-power error together with the reserve and flexibility dispatch for Case 3 is presented in Figure 6. As reserve and flexibility are valued at the same cost in the objective function, the distribution between the two indicates that both mechanisms are cooperating well to meet the power balance. The total flexibility dispatch accounts for 44.37% of the total compensation for the wind-power error over the 24h simulation time. It is shown that in the case of a positive wind-power error, flexibility dispatch is promoted over reserve, while for a negative wind-power error, the opposite is observed. Finally, Figure 6 also shows that the wind-power error is perfectly compensated throughout the full day, by the sum of flexibility and reserve deployment.
The reserve and flexibility scheduling is compared to the actual dispatch in more detail in Figure 7. In line with Figure 6, up-spinning reserve is promoted over decreased-demand flexibility, while increased-demand is favored over down-spinning reserve. Although total power demand differs by less than 10% between all cases, this motivates why the power dispatch of the cases is of different shape, as observed in Figure 4. As shown in Figure 6, it is important to note that the reserve and flexibility scheduling capacity is always significantly higher than the actual reserve or flexibility dispatch (i.e., the portion of the capacity that is deployed in the operational decision-making). This suggests that the current reserve and flexibility scheduling capacity is also sufficient for dealing with higher wind-power penetration levels than the current 10%.    The results of our Monte Carlo simulation to determine the empirical constraint violation level are presented in Figure 8 for all 3 cases along with a case in which no reserve or flexibility is used. As the majority of violations are observed during peak load hours, only this portion of the simulation horizon is presented. For the case with no reserve or flexibility, empirical violation levels are extremely high, as any deviation of the wind power from the forecast trajectory almost exclusively results in violation of the power line limits. For Case 1 and 3, maximum empirical violation levels are around 0.1%, whereas for Case 2, no violations were observed in any of the 10,000 iterations. In all three cases, the empirical violation level is well below the theoretical limit of ε = 0.05.

Conclusions
In this paper, we have presented two new developments for the BtG integration framework. First, we extended the existing models by introducing uncertain wind-power generation and by explicitly formulating the interactions between TSO, DSOs, and buildings. Second, we developed a unified BtG framework to handle uncertain generation, by integrating demand-side flexibility provided by individual buildings into the traditional process of reserve scheduling. We provided explicit expressions to determine the available amount of building demand-side flexibility from HVAC and electrical storage units. Using the unified BtG model, we formulated a finite-horizon stochastic control problem and provided a tractable robust reformulation with probabilistic feasibility guarantees. As the main outcome of our proposed BtG framework, we conclude that the demand-side flexibility can substitute the traditional reserve scheduling services in power systems in the presence of wind-power generation, without losing stability properties of the power grid and violating the buildings thermal comfort of occupants.
At the same time, the proposed framework is still rather idealistic, and relies on multiple major assumptions. As a final note, we discuss some of these assumptions, and provide possible directions for future research: • First of all, we did not consider the impact of imperfect communication between the TSO, DSOs, and buildings, and other sources of uncertainty than the wind power, such as demand uncertainty, were left out of scope. Hence, in a more sophisticated BtG integration framework, multiple sources of uncertainty should be incorporated. • Second, the BtG framework in the current work is formulated as a centralized MPC framework. Although the current centralized implementation runs in reasonable time for hundreds of buildings, we believe that it is worth exploring decentralized control frameworks, e.g., [39], in order to reduce the computational complexity of the problem. • Finally, part of our current work focuses on integrating the psychological impact of end-users for participating in the ancillary service market, by providing demand-side flexibility to the grid. We are interested in constructing models to simulate the willingness of end-users to participate in the ancillary service market, in order to study how different stimuli can influence the psychological behavior of consumers.