Experimental implementation of an emission-aware prosumer with online flexibility quantification and provision

Active building energy management holds potential to reduce global energy-related emissions and support flexible operations of future low-carbon systems. This requires to integrate diverse objectives and engage multiple stakeholders. However, there remains a gap in comprehensive field insights into emission reduction, flexibility provision, and user impacts. This study examined how a real occupied building, with all its energy assets, could function as an emission-aware flexible prosumer. An existing building energy management system was enhanced by integrating a model predictive control strategy. The enhanced setup minimized the equivalent carbon emission due to electricity imports and provided flexibility to the energy system. The experimental results indicated an emission reduction of 12.5% compared to a rule-based controller that maximized PV self-consumption. In addition, a minimal flexibility provision experiment was demonstrated with a locally emulated distribution system operator. The results suggested that flexibility was provided without the risk of rebound effects. This is due to the flexibility envelope that was self-reported in advance. The study concluded by highlighting technical challenges in realizing emission reduction and flexibility in practice.

As the share of intermittent Renewable Energy Sources (RES) increases and conventional power plants are being phased out, there is an increasing need for flexible demand to maintain security of supply [1].Meanwhile, buildings account for 28% of the global energy-related CO 2 emissions attributed to their operations [2].Hence, active building energy management, falling under the umbrella of Demand Side Management (DSM) [3], can play a critical role in transitioning toward net zero targets.For example, Olivella et al. [4] show that actively utilizing buildings' flexibility is a cost-efficient alternative to traditional distribution network expansions when addressing voltage stability issues.
nature of building energy flexibility utilization places occupants in the central stage [5,6].However, many existing studies examine the topic with limited flexibility resource types, concentrate solely on simulation studies and address just one of the mentioned aspects.

Critical literature review
Bolzoni et al. [7] develop a Model Predictive Control (MPC) to manage the flexible assets of a microgrid, reporting considerable emission and cost reductions.Although their work includes experimental testing, most control targets are emulated using a Real-Time Digital Simulator (RTDS).Such emulation omits potential disturbances from occupants, which can impact emission reduction and flexibility potentials.Nonetheless, [7] demonstrates MPC's capability of handling complex tasks.
Reference [8] provides a retrospective analysis of the flexibility provision in an island-scale experiment, where flexibility is delivered in an open-loop fashion.In addition, Munankarmi et al. [9] examines the flexibility of all behindthe-meter resources of a residential building.This flexibility is further quantified to facilitate interactions between buildings and Distribution System Operators (DSOs).However, the study relies on perfect knowledge of baseline power and observed rebound effects.Reference [10] proposes to represent flexibility with a cost curve, comprising sub-optimality gaps due to set-point tracking.Maasoumy et al. [11] propose a scheme that allows utilities to contract buildings for power flexibility provision, and feasible power levels are calculated accounting for operational limits.
Although an experiment is reported, its main purpose is to verify that the high-frequency components of utility's flexibility signal can be tracked.Additionally, both [10] and [11] assume that flexibility provision duration is known a priori.
This study focuses on self-reported flexibility, characterized as the capability of modifying energy usage patterns without violating appliance operation limits or compromising end-user preferences and thermal comfort.To this end, the flexibility envelope concept presented in [12] is adopted.It captures time dependency, the impacts of anticipated weather conditions, and end users' energy usage patterns without assuming knowledge of flexibility provision duration.From this perspective, the flexibility quantification in [10,11] can be seen as special cases of the flexibility envelope.However, [12] only analyzes flexibility quantification in an open-loop fashion and in a pure simulation-based environment.

Unique contribution and paper organization
Based on the papers reviewed, there remains a gap in comprehensive experimental insights covering three aspects: 1) emission-aware operation, 2) flexibility quantification and provision to DSO, and 3) the impacts on/from occupants.
The main contributions of this paper are threefold.Firstly, we present an emission-aware MPC as the base strategy for a prosumer.The emission reduction and occupants' thermal comfort levels are quantified in real-life operation.Secondly, online flexibility quantification and provision are formulated as optimization problems that can be automated to ease the practical deployment.The framework is experimentally demonstrated with an emulated DSO and risk of rebound effects is assessed.Lastly, qualitative and quantitative insights into impacts on/from occupants are reported.While ensuring thermal comfort is incorporated in the control strategy, impacts from occupants are assessed in ex-post analysis.
The remainder of the paper is organized as follows: Section 2 presents the methodological framework of controller design, flexibility quantification and provision.Section 3 describes the experimental setup and Section 4 presents the results of a week-long experiment, whose real-world implications are critically discussed in Section 5. Finally, Section 6 gives a brief summary and areas for further research are identified.

Methodology
This section first presents control-oriented models and operating constraints of all the assets, followed by the process of parameter identification.Then the Optimal Control Problem (OCP) formulation of the MPC controller is provided using the obtained models.Following this, the flexibility envelope calculation and an interaction scheme between the building and the DSO are unified with the mentioned MPC in one mathematical framework.

Control-oriented model structures for experiments
The considered behind-the-meter assets include Heat Pumps (HPs) for Space Heating (SH) and Domestic Hot Water (DHW), a stationary battery, an Electric Vehicle (EV) with bidirectional charging, uncontrolled loads and a rooftop Photovoltaics (PV) installation.The model structures are chosen based on a trade-off among computational complexity, required measurements and interpretability.
Throughout the paper, we use (•) to denote forecast values and use t as the time index.We focus on controlling the active power of behind-the-meter assets while neglecting the reactive power that is in general not available to control for residential loads.Power consumption is treated as positive, leading to PV power output and battery/EV discharging power being negative.Lastly, we use R + and R − to refer to the set of non-negative and non-positive real values respectively.

Space heating
In general, thermal dynamics are highly nonlinear processes.However, when the room temperature in buildings is actively controlled within a limited range, the dynamics of each zone can be approximated with an affine model for closed-loop control.Preliminary experimental studies also show that high-order models tend to perform worse than low-order models [13].The current study considers each room i ∈ I as one zone, with the indoor temperature is given by: where T sh i,t is the room temperature, ϕ sh i,t is the thermal power input, T amb t , φirrd t are the ambient temperature and the solar irradiance forecast respectively, H is the time horizon, i is the room index and I is the set of rooms.Since only weather forecast is available in real-time control, T amb t and φirrd t are used directly.In addition, we consider continuous thermal power to the rooms and the equivalent thermal power output can be obtained by modulating an HP operating in an ON/OFF mode with a pulse width modulation strategy.The corresponding electrical power consumption of the HP is given by: where COP m denotes the COP of the HP for SH.The corresponding constraints are given by: ϵ sh- i,t ≥ 0, ϵ sh+ i,t ≥ 0, ∀t ∈ H, ∀i ∈ I (4) where T sh,max i,t and T sh,min i,t are the predefined time-varying upper and lower indoor temperature limits respectively, ϵ sh- i,t and ϵ sh+ i,t are the slack variables introducing soft constraints to ensure feasible solutions, and P sh,max is the electrical power capacity of the HP.

Domestic hot water heating
DHW is supplied by a fixed-speed HP operating on ON/OFF mode with a buffer tank.Stratification effects within the tank are neglected, and the average tank temperature is given by: where T dhw, avg t is the volume-weighted average tank temperature, ϕ dhw t is the thermal power input and m draw t is the amount of water draw.The corresponding electrical power consumption of the HP can be given by: where COP h is used to differentiate from the above-mentioned SH HP.This distinction is made because SH and DHW typically have different inlet temperatures.Average tank temperature constraints are given by: where T dhw,max t and T dhw,min t are the predefined time-varying upper and lower average tank temperature limits respectively, ϵ dhw- t and ϵ dhw+ t are the slack variables enforcing soft constraints.The ON/OFF operating mode is modeled with a binary variable z dhw t : P dhw t = P dhw,max z dhw t , ∀t ∈ H (10) where P dhw,max is the electric power capacity of the DHW HPs.

Stationary electric battery
A model that captures battery self-losses, charging/discharging efficiencies is given by: SOC where ϵ ebat t is the slack variables introducing soft constraints to ensure feasible solutions and SOC ebat,min is the minimum SOC.

Electric vehicle
Similar to the stationary battery model, the EV battery is modeled as follows: where SOC ev t is the EV battery SOC, P ev, ch t ∈ R + and P ev, ds t ∈ R − are the battery charging and discharging power respectively.The limits on SOC is given by: SOC ev,min − ϵ ev t ≤ SOC ev t ≤ 100, ∀t ∈ H where ϵ ev t is the slack variable introducing soft constraints and SOC where C is the set of time steps when the EV is connected to the charger at home.Constraint (21) indicates EV is not available for control when absent.Constraint (22) ensures minimum departure state-of-charge SOC ev,min sup C with sup C being the departure time instant or supremum of the set C.

Photovoltaic
PV power output is predicted based on weather forecast and the formulation is given by: where P pv t ∈ R − is the predicted PV output.Such numerical weather condition-based forecasting is effective for horizons exceeding 4 hours [14], whereas persistence forecast is popular for short-term PV forecasting.Hence, PV power forecast { P pv t |t ∈ H} within the prediction horizon H is additionally combined with a persistence forecast.Since PV output forecasting is not the focus of this work, the combination of both forecast is determined empirically.The result is used in the predictive controller.Coefficients (β pv 0 , β pv 1 , β pv 2 ) are re-identified every day accounting for the impact of potential coverings on the installation, such as leaves and snow.The coefficients are updated if the re-identification is satisfactory.

Uncontrolled loads
Uncontrolled loads refer to lighting, cooking and wet appliances.This study aggregates the power P fix t ∈ R + of these appliances to account for their electricity consumption.The forecast is a combination of a 15-minute ahead persistence forecast and a 24-hour ahead persistence forecast.

Entire building
The energy balance of the entire building is given by: where P btg t ∈ R − and P gtb t ∈ R + are the electricity export and import respectively.They are differentiated because the total equivalent carbon emission is calculated according to the carbon intensity of electricity imported from the grid, and it is assumed that electricity export does not offset building's carbon footprint.To ensure the mutual exclusiveness of P btg t and P gtb t , a binary variable z grid t is introduced.
where M ∈ R + is a sufficiently large constant.

Parameter identification
A prediction error method is used, which can be described as minimizing the differences between the observed outputs and the predicted outputs based on the model and the historical data [15].For conciseness, a formulation is given as follows: where Â, B denote the system dynamics-related parameters that need to be identified.Eq. ( 27) assumes a state-space representation with an identity matrix as its output matrix and a zero matrix as its feed-through matrix.The k-step ahead prediction based on the historical data and the model structure is formulated as follows: where ŷt is the k-step ahead prediction based on the historical inputs and the boundary conditions described by the set The unknown parameters are obtained by optimizing the cost function consisting of accumulated prediction errors as follows: where N denotes the number of prediction error terms and y t is the observed output.Notably, the Huber function L δ (•) to compute losses instead of a square function to reduce the impacts of outliers.The optimal parameters Â * and B * minimizes the cost J.For this study, a prediction horizon of 24 hours is chosen.

Optimal control problem formulation
The full OCP formulation of the MPC is given by: subject to Eq. (1) to Eq. ( 26) where 2 ) denotes the cost associated with soft constraints, Huber function L δ (•) is used to formulate the penalties of constraint violations instead of quadratic penalties to be robust to outliers., w In addition, a set of inequidistant sampling time is used to reduce the number of decision variables as shown in Figure 1.Larger sampling time are assumed for the time instants further in the optimization horizon, as forecast and modeling errors increase as well.The horizon is chosen to be 24 hours to include future knowledge such as PV power output and EV usage patterns.

Flexibility envelope
The flexibility envelope, introduced qualitatively in a previous study [12], is formulated as optimization problems and extended to consider the flexibility from batteries, EVs with bidirectional charging, and curtailable PV.
The flexibility envelope identification starts with identifying the energy bounds by energizing flexible appliances to their extremes.The upper energy bound is identified by maximizing device consumption as early as possible, coupled with full PV output curtailment.To identify the lower energy bound, all the loads are set to consume as late and as little as possible.Simultaneously, the stationary and EV batteries are set to discharge as early and as much as possible without curtailment of PV output.The upper and lower energy bounds are illustrated as the red and blue curves in Figure 2. Formally, the above-mentioned notion can be formulated as optimization problems by modifying the OCP formulation in Eq. (30).Initially, solving the original OCP gives { Xt , Ũt , Ṽt |∀t ∈ H}, in which { Xt |∀t ∈ H} are the optimal state trajectories.The cost functions for deriving the upper and the lower energy bounds are defined as J ↑ := t∈H L t − e − t ρ U t and J ↓ := t∈H L t + e − t ρ U t respectively, in which e − t δ is an exponentially decaying weighting factor.Moreover, these optimization problems are initialized using the optimal state trajectories Xt .Solving the OCP with the new cost functions, we have in which H ′ is the optimization horizon for energy bounds identification and it might be different from H. Denote the aggregate power of all assets except uncontrolled loads as P t ∈ R and we further have P ↑ t and P ↓ t as the aggregated power calculated from U ↑ t and U ↓ t respectively.With {P ↓ t , P ↑ t |∀t ∈ H ′ }, the upper and lower energy bounds can be obtained as The energy bounds of the PV installation are calculated differently as there is no inter-temporal correlation.For a curtailable PV, the upper and the lower energy bounds are given by Finally, we can obtain the energy bounds of the entire building combining the above-mentioned bounds.To ease the computational efforts, power of all assets is approximated as continuous variables, at the example of introducing biases.In essence, system dynamics and operational limits dictate the energy bounds, which encapsulate all feasible energy trajectories.
which is an infinite set due to continuously controllable set points of the components.To ease representation, we consider only power trajectories with invariant power levels as the dashed line in Figure 2 shows with the slope indicating the power.The corresponding available duration is limited by the second endpoint of the line.Denote a future time instant as τ ∈ T + and feasible power level as P ∈ P τ .The mentioned available duration is represented as an implicit function of power level and time f : R × T + − → R + .To summarize, the flexibility envelope is a three-dimensional surface, comprised of points in the set {(τ , P , f (τ, P ))|τ ∈ T + , P ∈ P τ }.

Interaction between buildings and a DSO
The proposed flexibility envelope captures the thermal inertia of a building, the storage of a domestic hot water tank, the bidirectional charging of a stationary electric battery and/or an EV, and the curtailable PV power.When this envelope is self-reported in advance, a DSO obtains a comprehensive overview of the available flexibility at a given building.Upon receiving the flexibility envelope, the DSO sends a flexibility provision message (τ s , τ e , P ) to the building, where τ s and τ e denote the starting time and the ending time of flexibility provision respectively, and P ∈ P τ denotes the power level that needs to be tracked.By definition, there is τ e − τ s ≤ f (τ, P ).Upon receiving (τ s , τ e , P ), the cost function of the OCP is extended.It now includes the cost of tracking errors with the weighting factor ω 4 and the resultant is J := t∈H c emi t P gtb t ∆τ t + L t ∆τ t + ω 4 (P gtb t + P btg t − P fix t − P ) 2 ∆τ t .Moreover, the overall two-stage framework is illustrated in Figure 3.This framework allows the DSO to address local network issues using local flexibility resources.When there is a sufficient number of buildings supporting this framework, the DSO can even adjust the load to follow the expected supply of the system.An implementation example is given in Section 3 to complement the conceptual schematic.3 Experimental case study

Hardware specification
All assets, except the EV, were real components in the experiment.The EV with bidirectional charging was simulated with an identical model for both the emulator and the controller.This assumes perfect modeling of the EV battery and charging/discharging process.Physical components are from the NEST demonstrator at Empa in Switzerland [16], as Figure 4 shows.The hardware was distributed around the research infrastructure.The time-stamped measurements allowed emulating the actual operation of a prosumer equipped with all the aforementioned assets.The total power of the emulated building combined all power measurements and the simulated EV power.
The SH and DHW under control came from the residential unit marked with a red box in Figure 4.The UMAR unit is equipped with water-based ceiling panels for space heating.The room temperature comfort zone of the whole unit was set as [22 For domestic hot water heating, the tank's average temperature was maintained between [45 • C, 60 • C].The lower limit was boosted to [59 • C, 60 • C] at least once a week to avoid Legionella contamination [17].In our experiment, this timing was manually chosen to be Sunday morning between 4 am and 6 am.Regarding future water draw, a persistence forecast was used assuming that the future water draw will be the same as the day one week earlier.Preliminary studies employed a recurrent neural network and a Markov chains-based approach with one-year data.However, these did not enhance the forecast accuracy.This was due to the highly stochastic nature of human behaviour at the household level.Uncontrolled loads such as the cooking stove and the dishwasher were also located at the same unit.Therefore, consistent occupancy patterns for all the assets were observed.
A Lithium-ion battery of 17.5 kWh with bi-directional charging/discharging power of ±5 kW was operated1 .Conversely, an EV of 50 kWh with bi-directional charging/discharging power of ±7 kW was included as a simulated system component in the experiment.EV arrival and departure times were assumed to be known due to driver's input, which aligned with the large-scale field trial in [18].PV electricity output was considered emission-free, but the power exported to the grid did not offset the building's carbon footprint.Interested readers are referred to [19] for comprehensive description of test specifications and experiment plans.The bi-directional charging EV is a simulated entity and is not visible here.All pictures are taken from [20].The spatially distributed hardware are virtually coupled via their timestamped measurements as shown in (b).Such a virtual coupling is seen as a billing point for the DSO.

Communication architecture
The interactions in the proposed system are illustrated in Figure 5. Measurements were obtained from the Microsoft SQL database every 15 minutes [20].The forecast for ambient temperature and global solar irradiation was provided by the Federal Office of Meteorology and Climatology (MeteoSwiss) [21] every 12 hours.Actuation setpoints were communicated through TwinCAT PLCs, which interacted with the hardware using ModBus or analog signals.The controller and PLCs are connected via an OPC server [22].For a detailed description, see [19].The electricity carbon intensity data for Switzerland came from external sources [23], using data from the ENTSO-E Transparency Platform [24].Communication between the controller and the emulated DSO was achieved using local csv files.For more details, see [19] and [23].

Results and analyses
This section delves into closed-loop control results, the controller's performance, and flexibility quantification and provision.

Closed-loop control results
The MPC controller solved the OCP from Section 2.3 every 15 minutes.The OCP was formulated with CVXPY [25] in Python 3 and solved using MOSEK [26].The control variables' optimal values were obtained over a 24h horizon.Only the next time step's decision values are relayed to the actuators via the Python-OPC UA client.All the hardware is equipped with dedicated meters, and all the measurements are stored in a Microsoft SQL database [20].Since the actuators cannot perfectly execute the set points, a distinction is made between the measured power and the power set point planned by the controller in the following results.
Model parameters were identified from 2019 data using the prediction error method [27].The models are then resampled according to the set of inequidistant sampling time intervals shown in Figure 1.The strategy assumes the same power set point during a sample time interval.The accuracy of each individual appliance is not presented here.However, additional experiments were carried out, where energy input for SH and DHW was minimized and their temperature were found to stay close to their lower limits [23].It is worth noting that this is a common experimental design for validating modeling accuracy, as demonstrated in [28] and [29].Additionally, the following experimental results further confirm modeling accuracy, as both SH and DHW temperatures stay within predefined limits while optimizing according to carbon intensity, except for dramatic disturbances.
In the week-long experiment, power set points of all controllable assets were obtained by solving the OCP formulated in Eq. ( 30) and the OCP with a modified objective function during flexibility provision.This section presents the controller decisions, realized power input and responses of all the assets, first detailing results for individual appliance.The net power exchange with the grid follows, as illustrated in Figure 9.

Space heating
The temperatures of all three rooms are shown to approach their upper temperature limits in Figure 6(a).This reflects the controller's strategy: maximizing electricity use when carbon intensity was low, and minimizing it when high.Significant temperature drops in Room 273 (marked by the grey periods 1 -5 in the figure) were due to extend window openings for hygiene, related to Covid.Excluding these instances, indoor temperature generally remained within the comfort zone.
Comparison between Figure 6(b) and Figure 6(c) indicate that actuators mostly follow the controller decisions even though there are mismatches.Figure 6(d) shows that temperatures within Room 272 and Room 274 are mostly within the limits, whereas the accumulated temperature deviation reached around 4 Kh in Room 273 by the end of the experiment due to dramatic disturbances.We can also observe from Figure 6(a) that indoor temperature occasionally exceeds the upper temperature limit such as the grey period 7 .In general, such behaviour can be attributed to factors such as high solar irradiance, modeling errors, and internal gains that are not entirely captured.Notably, the solar irradiance as shown in the grey period 10 in Figure 6(e) is not substantially higher than other days.Additionally, the measurements of the grey period 8 in Figure 6(b) and the grey period 9 in Figure 6(c) show that the controller decision and actual power input to Room 272 and Room 273 were close to 0 kW during the same period.Hence, the overshoot is more likely caused by dramatic internal gains.

Domestic hot water
We can observe from Figure 7(a) that the temperature is always within the predefined limits, indicating adequate hot water supply.Right before the boost of the lower temperature limit, energy is actively used during the low carbon intensity period.However, Figure 7(b) reveals that power consumption doesn't always inversely correlate with carbon intensity.For instance, unexpected high-energy demands, possibly from substantial water usage, caused power surges during peak carbon intensity periods (marked by the grey period 1 in Figure 7).Additionally, the net power exchange with the grid shown in Figure 9 does not show a peak at this time (marked by the grey period 1 in Figure 9), implying that the power was supplied internally.We can also observe that the measured power input mostly follows control decisions, with exceptions such as that marked by the grey period 2 in Figure 7, which is a result of actuation errors.Additionally, thermal power inputs are dependent on the difference between tank temperature and inlet temperature.Hence, the measured power input varies over time.

Other assets and grid connection point
For brevity, the results of all non-thermal loads are summarized in Figure 8.Note that the bidirectional-charging EV was absent; results in Figure 8(b) and (c) represent simulated SOC and charging/discharging power.
The net electric power exchange with the grid aggregating all the assets is summarized in Figure 9 alongside the electricity carbon intensity.Interestingly, the net power often inversely correlates with the carbon intensity profile.One notable grid export, during the grey period 2 , can be traced back to an uncontrolled load profile's forecast error.

Impact evaluation
To gauge the controller's efficacy in reducing emissions, this work contrasts the presented results with a simulation on a virtual testbed.Although a simplified model is used in the closed-loop control, it is not accurate enough as a virtual testbed to emulate the physical system over one week.Hence, the digital twin developed in [30], is used.This digital twin is calibrated using the data of entire 2019 at 1-minute intervals with a CV-RMSE of 0.09, making it a suitable choice for the virtual experiment.Compared with other frequently used methods such as reference day, the proposed virtual experiment captures the high-resolution variation of carbon intensity profile.
The virtual experiment employs a hysteresis controller for both SH and DHW, which is common in the current industry.More specifically, the average water tank temperature limits are [55 • C, 60 • C] and the comfort zone of SH is the same as the physical experiment.DHW is treated differently to ensure a sufficient temperature level to eliminate Legionella,   The planned and realized thermal power input into the tank are summarized in (b), in which the thermal power is normalized with a thermal power capacity inferred from historical data.which also replicates the existing industry practice.The EV is charged at full power right after being connected to the charger, and a hysteresis controller is applied afterward to ensure the minimum SOC level.Currently, there are no standard industrial practices as to design energy management systems covering all flexible devices.A selfconsumption-oriented strategy is considered for the battery in addition to the hysteresis controllers mentioned above.It stores all PV production; for the rest of the time, it only discharges to cover the demand of other appliances.Note that the same carbon intensity profile is used in both the control and the impact evaluation.This assumes a perfect carbon intensity forecast.Interested readers are referred to [23] for the forecast accuracy.
We can observe that the total emission and the average carbon footprint of the consumed electricity are reduced by 12.5% and 16.5%, respectively.The reduction is realized by avoiding electricity imports during high carbon intensity periods.An example is marked by the grey period 1 in Figure 10 and Figure 7.The reduction is not pronounced, which indicates that the benchmark control strategy mentioned above already reduce carbon footprint by promoting self-consumption.

Flexibility quantification and provision
An example of online flexibility envelope quantification is provided in Figure 11, which shows that flexibility potential considerably vary within the 24 hour horizon.Results of the flexibility provision with an emulated DSO are in Figure 12.We consider a scenario in which the DSO experiences network congestion due to low ambient temperature.More specifically, load peaks may be exacerbated due to simultaneous consumption from newly adopted HPs, which the distribution system may not be planned for.Thus, additional flexibility from buildings is needed to mitigate the issue.As per industry practice, ripple control [31] has been used for decades for direct load control by broadcasting radio signals to cease operation of devices such as HPs within a target group.However, ripple control represents unidirectional communication and addresses limited types of flexible devices.In the rest of this section, we demonstrate the proposed framework with an emulated DSO.More importantly, we show similar performance, namely keeping total power exchange with the grid close to 0 kW, can be achieved from the perspective of the DSO, while comfort levels and preferences of end users are shown to be respected.
In the experiment, a building self-reports its flexibility envelope to the DSO, who in turn remains idle until flexibility needs are foreseen according to the weather forecast.The DSO examines the reported flexibility envelope shown in Figure 11 and notifies flexibility provision to the building via (τ s , τ e , P ) := (2020-11-21 21:00:00+01:00, 2020-11-22 06:30:00+01:00, 0 kW) at the time marked by the vertical line 1 in Figure 12.Importantly, (τ s , τ e , P ) needs to match the self-reported flexibility envelope (marked by the red box in Figure 11).Within the flexibility provision period (marked by the period between vertical lines 2 and 3 ), the building tracks the set point.The results show that the     total power exchange with the grid is reduced to a marginal level, although not strictly zero.This can be attributed to the actuation errors as observed in , Figure 7 and Figure 8. Besides, we can observe that the energy states of all devices are comfortably away from their lower limits (as seen at the end of the grey area 11 in the first plot of Figure 6, and the end of the grey area 3 in the first plot of Figure 7).This indicates that there are no immediate needs for electricity imports from the grid.Therefore, there is no risk of rebound effects.While the building activates its flexibility, the DSO continuously monitors the building and remunerates the service provider afterwards.A full discussion of the remuneration scheme lies beyond the scope of this study, but this remains an important issue for future research.

Discussion
Overall, the presented results demonstrate that the controller operates with emission-aware MPC as base strategy and can deviate from the optimal trajectory to provide flexibility upon request.In the experiments, simplified SH models, which were extracted from historical data, yielded satisfactory results both in terms of emission reduction and maintaining thermal comfort.This might be attributed to the unit being heated with water-based ceiling panels, which have slower dynamics than forced air heating [32].Additionally, the temperature is controlled within a small range.
Apart from the quantitative data, qualitative feedback on thermal comfort was also collected via an online feedback form during the experiments [19].For DHW, all feedback indicated "very satisfied".As for the bedrooms, 37.5% of the time, the occupants indicated slightly cool indoor temperature in the 7-scale rating (cold, cool, slightly cool, neutral, slightly warm, warm, hot) matching low comfort violations.At other times, occupants expressed neutral opinions about the indoor temperature.We observed fatigue among users responding to survey requests, limiting the current survey.This suggests that the feedback strategy in the future needs to take a different form, especially for real-time control.Since the bi-directional EV was emulated, no feedback was gathered.
Compared to traditional ripple control [31], the presented framework offers a significant advantage.It allows DSOs to obtain a comprehensive overview of available flexibility, effectively combining all flexibility resources.The highresolution flexibility supports precisely resolve potential network issues.However, reliability might be a concern.This is because reliability decreases as the element count increases in any series system.The proposed prosumer is an example of such series systems.Additionally, ripple control is implemented in an open-loop fashion and the response can be expected within 7s [31], whereas the proposed framework would take longer to quantify flexibility envelope and establish flexibility provision agreements.Moreover, communicating the flexibility envelope requires significant bandwidth, necessitating further simplification.All in all, the existing ripple control scheme excels in simplicity and responsiveness.In contrast, the presented framework is favorable for DSOs that require automation and an optimization-based approach due to the complexity of handling numerous resources.

Conclusion
Despite buildings' promising active role in supporting the energy transition, challenges arise due to the involvement of diverse operational objectives and stakeholders.This work addresses gaps in experimental insights, focusing on emission-aware operation, flexibility quantification and provision to Distribution System Operator (DSO), and the impacts on/from occupants.
During a week-long experiment, a 12.5% reduction in equivalent emissions was achieved compared to a benchmark controller maximizing PV self-consumption.Meanwhile, measurements indicate that end users' comfort levels are improved.The proposed flexibility provision framework, demonstrated with an emulated distribution system operator, considers a scenario where flexibility is requested to mitigate network congestion.All behind-the-meter flexible resources are effectively coordinated to provide flexibility upon notification.The experimental results suggest flexibility can be offered without rebound effects, while still maintaining user comfort levels and preferences.
Nonetheless, there are several limitations to note.Firstly, this work does not explicitly account for uncertainties associated with forecast and model errors in the optimization problem.The inclusion of uncertainties can enhance reliability.However, practical deployment costs must be balanced against this.Secondly, challenges may arise if the maximum duration of flexibility provision is requested or when a DSO requires flexibility with a different lead time.It remained to be assessed whether flexibility can be reliably provided and comfort guaranteed.Future research should assess more scenarios for robust flexibility quantification and provision.To better account for uncertainties, an alternative approach could be a probabilistic flexibility representation.

Figure 2 :
Figure 2: Illustration of the workflow to obtain one slice of a flexibility envelope at t 0 .The left figure depicts upper and lower energy bounds derived from extreme scenarios.The bounds indicate flexible power and the corresponding available duration.The right figure maps the power levels and duration onto a three-dimensional space and illustrates one slice of flexibility envelope.All slices at each time step within the horizon constitute a full flexibility envelope.

Figure 3 :
Figure3: Illustration of the information flow among the building, the controller and the system operator.At each time step, updated building state measurements are retrieved by the controller to solve the emission-aware OCP.The resultant state trajectories are used to quantify the flexibility envelope, which is self-reported to the DSO.Upon receipt, the DSO may request the prosumer to provide flexibility depending on the condition of the network.

Figure 4 :
Figure 4: Physical layer of the experimental setup (a) and its single-line representation (b).The physical layer shown in (a) includes SH with ceiling heating panels, DHW with a buffer tank, fixed loads of an apartment unit marked in the red box, a PV installation and a battery.The PV installation is placed on the roof and the battery is located in the basement, which are not directly visible in the figure.The bi-directional charging EV is a simulated entity and is not visible here.All pictures are taken from[20].The spatially distributed hardware are virtually coupled via their timestamped measurements as shown in (b).Such a virtual coupling is seen as a billing point for the DSO.

Figure 5 :
Figure 5: Information exchange among the controller, the external information sources (e.g., MeteoSwiss), an emulated system operator and the hardware in the experiments.

Figure 6 :
Figure 6: Field experiment results of SH.(a) shows the measured temperatures of all three rooms.(b) shows the measured thermal power input into each room.(c) shows the thermal power input planned by the controller.The dashed black lines in (b) and (c) indicate the carbon-intensity profile.(d) shows the time-integral of room temperature deviations below the lower limit, measured in kelvin hours (Kh).(e) shows the ambient temperature and the irradiance measurements.

Figure 7 :
Figure 7: Field experiment results of DHW.(a) shows the average tank temperature and the water draw over time.The planned and realized thermal power input into the tank are summarized in (b), in which the thermal power is normalized with a thermal power capacity inferred from historical data.

Figure 8 :
Figure 8: Field experiment results of all non-thermal assets.(a) shows the battery's SOC, planned/measured charging/discharging power.(b) shows the simulated EV's charging/discharging power.(c) shows the EV's SOC.The dashed black line indicates the user's driving pattern, with 1 indicating that the EV is connected to the charger at home and 0 indicating the opposite.(d) and (e) show the measured PV power and the uncontrolled load respectively.

2020- 11 -Figure 9 : 1 Figure 10 :
Figure9: Field experiment results of the net power exchange with the grid.The time series of the net electric power exchange is obtained by summing all respective power measurements and adding the simulated EV charging/discharging power.

Figure 11 :
Figure 11: An example of flexibility envelope exported by the controller.

Figure 12 :
Figure 12: Results of flexibility provision example.The bars on top of the figure denotes the actions between the emulated DSO and the prosumer.The blue and red curves denote the aggregate power of all flexibility resources outside and inside flexibility provision period respectively.
ev t , ϵ ebat t , z ebat t , z ev t , z grid t , z dhw t , P btg t , P gtb t |∀t ∈ H, ∀i ∈ I} denotes the set of the remaining decision variables, c emi t ∈ R + is the grid carbon intensity.It needs to be mentioned that only the variables in {U t |∀t ∈ H} can be physically controlled.Although the rest of the variables are formulated as decision variables of the OCP, they can be determined by {U t |∀t ∈ H}, system dynamics equations, and algebraic constraints.
1 , w 2 and w 3 are the customized weighting factors, {X t |∀t ∈ H} := {T sh i,t , T dhw t , SOC ev t , SOC ebat t |∀t ∈ H, ∀i ∈ I} is the set of state variables, {U t |∀t ∈ H} := {P sh t , P dhw t , P ebat,ch t , P ebat,ds t , P ev,ch t , P ev,ds t |∀t ∈ H} is the set of control input variables, {V t |∀t ∈ H} := {ϵ sh- i,t , ϵ sh+ i,t , ϵ dhw- t , ϵ dhw+ t , ϵ • C, 23 • C].The range was relaxed to [21 • C, 25• C] during the daytime, specifically between 8 am and 8 pm, as occupants are likely absent during these hours.Occupants can adjust the comfort zone without impacting the method's generality.