Economic Model Predictive and Feedback Control of a Smart Grid Prosumer Node

: This paper presents a two-level control scheme for the energy management of an electricity prosumer node equipped with controllable loads, local generation, and storage devices. The main control objective is to optimize the prosumer’s energy bill by means of intelligent load shifting and storage control. A generalized tariff model including both volumetric and capacity components is considered, and user preferences as well as all technical constraints are respected. Simulations based on real household consumption data acquired with a sampling period of 1 s are discussed. The proposed control scheme bestows the prosumer node with the ﬂexibility needed to support smart grid use cases such as bill optimization (i.e., local energy trading), control of the proﬁle at the point of connection with the grid, demand response, and reaction to main supply faults (e.g., islanding operation), etc.


Background and Aim
The decreasing cost of photovoltaic (PV) [1] and storage [2] technologies is accelerating the transition towards the smart grid of the future [3]. Prosumer nodes will become fundamental actors of the grid and dedicated energy management systems (EMSs) will be needed for them. This paper presents an EMS for the control of energy flows in a prosumer node hosting loads, storage devices, and a renewable plant. The benefits are: (1) minimization of the energy bill; (2) the possibility of participating in demand response (DR) schemes; and (3) increased resilience against grid power outages.
The proposed EMS works based on a combination of economic model predictive control (EMPC) and standard feedback control. EMPC works in discrete-time and plans the optimal activation of the energy resources in a given time window ahead of the current time (a predictive control technique). The EMPC formulation includes mathematical models of the node's dynamical devices: the energy storage system (ESS), and the plug-in electric vehicle (PEV) (a model-based technique), as well as forecasts of the relevant flows affecting the node's power balance (e.g., power consumed by loads, power generated from renewable plants, etc.). EMPC results in the proactive and efficient operation of the node. A second, low-level proportional-integral-derivative (PID) feedback control loop is added in order to mitigate the effect of uncertainties and disturbances, and thus to reduce the error between the actual power profile of the node and the optimal one planned via EMPC.
To provide a concrete case study, the paper focuses on a residential scenario. Commercial, tertiary, and industrial scenarios can be addressed as well with proper customizations.

Related Works
Over the last decade, DR policies, algorithms, and enabling technologies have attracted attention in several sectors of the academic community. A review of the many concepts and methods in EMS design and DR problems can be found for example, in [4][5][6][7].
The potential benefits coming from the large-scale adoption of the DR paradigm have been the subject of several studies focusing on different aspects of network operation. For example, in [8] the potential impacts of DR on service reliability in a Finnish residential distribution system are evaluated both on a qualitative and quantitative basis. Typical load profiles of household appliances and the related flexibilities are identified and then, for every contingency, feasible modifications of appliance load profiles are considered such that the lowest possible interruption cost is realized; the obtained results are finally combined to calculate service reliability indices. Reasoning at higher level of power system operation, in [9] it is stated that DR has a large potential for the provision of short-term services such as spinning reserve or primary control and for damping residual load gradients. The DR potential is instead recognized as being lower for longer-term services like secondary or tertiary control. The reason for this conclusion is that the potential of DR is not limited by the magnitude of shiftable capacity but by the maximum shift duration, which makes it useful for fast and short-term services but less useful for longer shifts.
A key aspect for assessing the potential of DR is the user responsiveness, which has been recognized as being influenced by several variables, such as the pricing scheme and incentive mechanism [10], the type of loads [11], the presence of generation from renewable sources [12], the occupancy of the household [13], and the weather [14]. All these factors result in a variability of performances; something that is confirmed by the quantitative results reported in the context of successful pilot projects running in Germany [15], Belgium [16,17], and the Netherlands [18].
The pricing scheme undoubtedly constitutes a key factor for introducing flexibility in the demand. In order to facilitate this process, over the last years retailers have started to design new tariff schemes, with which the risk related to the volatility of energy price in the market is shared with their customers [19]; typical examples of well established pricing models are the time-of-use (TOU), day-ahead pricing (DAP), critical peak pricing (CPP), and real-time pricing (RTP) [20,21]. However this key aspect continues to be the subject of intensive research. For example, in [22] a pricing algorithm is proposed with the aim of reducing the peak-to-average ratio of the aggregated load demand in the practical case when the retailer is uncertain about user responsiveness. Also, in [23] it is shown that simple time-varying pricing schemes might create pronounced rebound peaks in the aggregated residential demand. To cope with this negative effect caused by the synchronization of the individual demands, new electricity price structures called Multi-TOU and Multi-CPP are proposed.
The Dutch pilot study reported in [18] represents a real-life experience in which both manual and automated DR were studied over a long period of time (>1 year) to assess the overall household flexibility and the effect of variable peak pricing on the peak load. To assess user responsiveness on quantitative basis, two comparable groups of users were considered, which were subject to a different moment of evening peak pricing. The results reveal that the flexibility mainly comes from the white appliances (i.e., the washing machine, tumble dryer, and dishwasher); also, while the manual intervention of users in response to price signals seems to be stable over the time, the automation of the load-shifting process appears beneficial for the improvement of the overall system performance.
The benefit coming from the use of an EMS for automated participation in DR programs is largely recognized as fundamental in more challenging scenarios, in which multiple sources of energy like local generators from renewable energy sources (RESs) and ESSs have to be managed in combination with relatively new types of loads, such as PEVs, and in the presence of complex electricity price structures. This is the case of prosumers, which pursue the typical objective of minimizing the operational costs of their microgrid not only by optimizing the power withdrawal from the grid, but also by maximizing the self-consumption and selling the residual energy. Several studies have been performed and reported in the relevant literature, which typically differentiate with respect to the considered equipment and the related operational constraints, the applied pricing schemes, and the control strategy.
Rule-based methods, based on e.g., "if-then" rules, are widely used in current EMSs because of their simplicity and low computation load. In [24], the rules are used in the context of a microgrid for assuring that the power consumption of the electrical appliances is always lower than the threshold, also exploiting the internal microgeneration. In [25], a rule-based EMS was proposed, which takes advantage of the "Rete" algorithm, a typical pattern-matching algorithm for "if-then" rules. Despite their ease of implementation, rule-based control algorithms may be oversimplified and lack the lookahead capability of the predictive control techniques.
Advanced EMSs typically rely on different forms of optimization, such as linear programming [26], binary linear programming [27], non-linear programming [28], mixed-integer linear programming (MILP) [29][30][31], mixed-integer non-linear programming [32], and multiparametric programming [33]. These techniques are typically used for day-ahead scheduling or real-time scheduling, through the integration in event-driven or time-driven model predictive control (MPC) frameworks. In this regard, the idea of periodically re-optimizing is currently largely accepted as a way to manage the occurrence of real life events and inaccurate system modeling.
For example, in [27] an event-driven MPC algorithm based on binary programming was proposed to schedule smart household appliances. The enabled use cases include: overload avoidance, minimization of the electricity bill, presence of a TOU tariff, and real-time reaction to price and volume signals. An extension of the work in [27] is presented in [29], which details an MPC framework based on MILP, integrating the ESS, the PEVs, and microgeneration, tested in presence of DAP and RTP tariffs. The formulations in [27,29] provide a way to quantify the minimum remuneration that a qualified market player has to pay to the user for the active participation in the DR program.
In [30] another interesting MILP formulation is proposed to jointly schedule demand, generation (also including RESs), and ESSs in a microgrid. The uncertainty in the demand and the power generation from renewables is managed through a rolling horizon approach and the periodic updates of input data. Part of the demand is considered flexible, but penalties are associated with the delay of loads. An extension of the work is presented in [31] where the heating is integrated in the scheduling problem for the microgrid; also, the interruptions in the energy demand are taken into account, under penalties in the economic objective function. A focus on the schedule of the heating system is also provided in [34], considering a microgrid integrating multiple micro combined heat and power (microCHP) generators. A similar scenario is investigated in [33], where a state-space multiparametric program working in a rolling horizon framework is proposed. The characterizing aspect of the approach in [33] is that it allows for management of bounded uncertainties. The authors show that by considering as uncertain parameters the set of variables that describe the state of the system at the beginning of the prediction horizon, it is possible to formulate a set of state-space multiparametric programming problems that are solved just once and off-line. The output of these problems provides a complete set of control signals as a function of uncertain parameters. The paper overcomes the limitations related to the occurrence of multiple disruptive events, but the authors emphasize the necessity to solve a number of multiparametric programming problems, in case binary or semicontinuous variables are included in the initial state of the system.
When the optimization problem is characterized by a high level of complexity, alternative solution methods for dealing with optimization problems are used for the management of microgrids, such as evolutionary methods, logic-based techniques, and relaxation and decomposition methods. Genetic algorithms can be used when large mathematical formulations requiring large computational effort to reach the optimal solution are used [35,36]. For example, in [36] the authors discuss how a local EMS can be designed to optimize the size and operation of an ESS, minimizing the effect of aging and replacement costs. Other heuristic techniques proposed are for example particle swarm optimization [37] and metaheuristic Tabu search [38].
Moreover, logic-based optimization techniques, like constraint programming [39], have been proposed to simplify the modeling phase, reduce the combinatorial search efforts, and improve the handling of non-linearities. Other approaches applied in this area are Lagrangian relaxation [40], and the Benders decomposition [41]. For extensive reviews about the optimization techniques applied to the microgrid the reader can refer to [42,43].
Learning techniques have been applied as well in the context of residential EMSs. In [44], artificial neural networks were proposed as a tool for load scheduling with the aim of maximizing the self consumption from local renewable energy sources (RESs). The appliances self-organize and then a coordinator makes corrections in order to provide a feasible and optimal schedule. The approach cannot be used in a real-time framework, since the user must provide in advance the list of appliances to be executed within the scheduling period. In [45], the authors present a Markov decision process formulation integrating the concept of utility functions. Reinforcement learning in the form of Q-learning is used to find a policy which establishes a trade-off in the long run between the need of optimizing the cost of electricity and the dis-utility deriving from task delays. The delicate points here are the selection of the utility functions and the potentially high dimension of the state space.
Other interesting approaches are presented in [46][47][48], which propose a joint formalization of the day-ahead capacity procurement problem and the real-time demand response problem, in the presence of renewable energy source (RES) uncertainty. Appliances are modeled via utility functions and, as in [45], the strong assumption that appliances can adapt their demand within a continuous power interval and without power correlations among phases is made. Household appliance manufacturers instead recommend a specific power profile for each appliance program, and allow only for minor deviations, like temporarily suspensions after specific phases. This aspect of the detailed modeling of the appliances' power profile is rarely taken into account in literature.
The present paper represents an extension of the previous works [27,29], which are in the class of the MPC framework.
The MPC has been already proposed in this field, as it naturally handles multivariable control and the presence of constraints, both typical features of EMS problems. In [49], a switched MPC control strategy is presented for the energy management of a standalone system composed of a PV module, a diesel generator, and a battery bank. Charging and discharging efficiency factors are estimated online (the same technique could be adopted in this work), while the switching between charging and discharging is decided based on a heuristic. The aim is to: (1) minimize the usage of the diesel generator; (2) maximize the usage of PV power; and (3) minimize battery activation. The included constraints are on the energy flows, on the ESS state of charge (SOC), and mutually exclusive charging/discharging activation. In the present work, some of the assumptions made in [49] are removed, namely, the assumptions on rigid loads (in [49] loads' starting times are not managed) and fixed charging/discharging switching times. Also, an economic term is included here in the target function to minimize the bill.
Several heuristic and evolutionary DR strategies have been developed to cope with the non-linearities involved in the problem (see e.g., [50,51]) . In advanced tariffs, the price/cost of the energy changes depending on the direction and the magnitude of the power flow between the node and the grid. Recently however, MILP models have been developed which are able to model the trading with the grid with a linear formulation including Boolean variables. For example, in [52,53]-the works in literature closest to the present one-deal with MPC optimization of the energy bill in a microgrid with loads, local generation, and ESS. Based on [54], they derive a linear formulation for controlling the energy trading with the grid. The present work extends [52,53] by introducing: (1) a more general tariff model (which entails a more involved exact linearization); (2) more detailed modeling of controllable loads (beyond on/off load activation); (3) inclusion of PEV charging compliant with standard IEC61851 [55]; (4) introduction of a second control level to mitigate the effect of disturbances and uncertainties on the node power profile; and (5) simulations in a very realistic setting (1 s resolution of consumption data). Another interesting contribution is found in [56], which presents a setting similar to the references above, and in addition proposes a soft peak power-limiting strategy consisting in the integration into the MILP problem of a critical peak pricing scheme, something which is generalized by the present paper. Additional and similar recent MILP formulations of a residential EMS are presented in [57], which uses it to assess the DR-driven load pattern elasticity of smart households, in [58], which minimizes the response fatigue of the controlled devices and considers uncertainties of PEV availability and small-scale renewable energy generation, and in [59], which aims at minimizing costs and maximizing user convenience in the context of real-time and capacity-based pricing schemes (for the capacity-based tariff case, Park et al. [59] considers a quadratic tariff function and proposes an approximate technique).

Main Contributions
The distinctive features and innovations of this work are as follows.
1. The formulation of the problem is very general and flexible, integrating plannable and non-plannable demand, local generation, and ESS/PEV control. The formulation can integrate heterogeneous tariff models (volumetric, capacity, and mixed models, including flat rates, day-ahead pricing, time-of-use pricing, real-time pricing, inclining block rates, critical peak pricing, and two-part tariff schemes [60]). Smart appliances are modeled in a realistic and detailed way: the EMS takes as input the detailed load forecast computed by the smart appliance for each program to be executed, something which is already made available by today's smart appliances. The integration of PEV charging is also realistic and compliant with the applicable standards on alternating current recharging. Being based on high-level MPC control and low-level PID control, the proposed scheme is fully compatible with the dynamics of a real environment, such as real-time interaction with the user and fluctuations in the PV power output. This richness and flexibility of the formulation significantly differentiates it from the other works present in literature, and makes it suitable for a possible practical implementation. 2. The EMS presented here can tackle an articulated electricity tariff model which includes both volumetric and capacity components. This is expected to be very relevant in the light of the future evolution of the electricity tariffs as a way to implement implicit DR schemes, through e.g., increased incidence of the capacity component coupled with real-time variation of the prices. The natural mathematical formulation to cope with this complexity is non-linear, and computationally not compatible with a real implementation of the controller. In this paper it is shown how the natural mathematical formulation can be linearized exactly, resulting in a computational effort in line with a practical implementation. 3. A combination of MPC and standard feedback control is used for increased resilience to uncertainties and disturbances. Although the necessity for such a scheme is acknowledged in literature (e.g., [52]), to the best of the authors' knowledge this is one of the first works to investigate it in practice. Furthermore, the interaction among the two controllers is an interesting research line to be investigated in future works. 4. Real generation and consumption data are used [61], with high time resolution (1 to 6 s) and high granularity in terms of monitored loads (53 monitored loads, plus the node meter). This makes the simulations more realistic compared to previous works, where the data used in the simulations are mostly 15-min based, if not in the order of half-hour periods. This is relevant, because the metering data show that the PV output and the load curves of the appliances can have significant variations in the time frames on the order of the seconds. Similarly, the load profiles are real ones, and so are the associated request times. This makes the simulations very realistic, because they are based not only on real data, but also on real dynamics of the household (as a matter of fact, one of the complexities of building the simulation setting has been that of acquiring and isolating from the data repository provided in [61] all the load profiles occurring during the simulated time frame). 5. The points listed above are also the main innovations of the present work with respect to our previous works [27,29].

Paper Organization
Section 2 details the reference scenario. Section 3 discusses the use cases enabled by the proposed control strategy. Section 4 explains the EMS control logic. Sections 5 and 6 detail the mathematical formulation of the two EMS control levels. Section 7 discusses the results of the work. Section 8 discusses the limitations of the work. Section 9 concludes the work and presents the future works.

Reference Scenario
This study takes as reference scenario a prosumer node connected to the electricity grid and equipped with consumption, generation, and storage resources (Figure 1). Notable devices inside the prosumer node include: the loads, the ESS, the PEV, the PV plant, the smart meter, and the smart plugs. The main actors involved in the EMS problem are: (1) the distribution system operator (DSO), which establishes the node power limits; (2) the retailer, which has an energy contract with the user; (3) aggregators, mediating between the node and the previous actors in case the node is part of a wider energy community; and (4) other service providers (e.g., PV forecasting providers). A survey on the actors and devices involved in the node EMS problem and the different architectural choices can be found in [62]. In the following, more modeling details are given regarding the appliances, the PEV and the tariff scheme.

Appliances
Appliances (also named loads here) are either plannable or non-plannable. Management of plannable appliances is left to the EMS. The user sets the preferences in terms of first allowed start time (S l , l denoting the load) and the latest allowed end time (E l ). Plannable appliances make available to the EMS a forecast of the adsorbed power curve. The EMS decides when best starting the plannable load. Non-plannable appliances offer no load-shifting flexibility. However, non-plannable loads that make a consumption forecast available to the EMS can be integrated in the EMS problem. Instead, those that do not make available consumption forecasts (e.g., legacy appliances) act as a disturbance in the EMS problem. Their impact is mitigated through the feedback, second-level controller. Another solution could be to estimate their consumption through the analysis of data at granular level-i.e., via local smart plugs-or at node level, via disaggregation techniques [62].

PEV
PEVs can be capable of both load shifting and modulation. The EMS manages charging/discharging considering the preferences set by the user (latest allowed charging completion time F pev and final desired SOC pev,req . PEV control is compliant with standard IEC 61851 [55]. According to this standard, charging can be either zero, or greater than a minimum positive value level (i.e., arbitrarily small charging power is not allowed). This leads to the inclusion of semi-continuous variables.

Tariff Model
Electricity tariffs can be reduced to a combination of the volumetric and the capacity-based models [60]. Volumetric tariffs (e.g., flat, fixed, time of use, dynamic tariffs [60]) charge the amount of consumed energy (EUR/kWh), irrespectively, in their pure form, of the power consumption pattern (with or without load peaks). They are still the most widespread tariff model for distribution customers. In their pure form they do not reflect the costs of operating the grid, which are mainly capacity-driven [60]. Capacity tariffs bill the energy based on the level of consumption capacity (i.e., the level of consumption power (EUR/kW)). They penalize consumption peaks and hence contribute to flattening the load curve.
The tariff scheme adopted in this paper is a combination of the two models. It is mathematically described as a function C(k, P(k)), where k is the time and P(k) the power exchanged with the grid at k (see example in Figure 2). C is assumed to be piece-wise constant in the power interval [P min , P max ], being P min the injection power threshold and P max the consumption power threshold of the node. C j (k) denotes the energy tariff value at time k for the generic jth power interval ∆P j (k) = [∆P min j (k), ∆P max j (k)] in which the tariff function is constant with respect to the power variable. The dependence of C on time allows to integrate time varying pricing models. The dependence on the power level allows to include the capacity models.

Use Cases
The proposed EMS enables the following use cases.
1. Optimization of the energy bill: This use case captures the normal operative condition, where the main objective is to optimize the energy bill. The re-optimization scheme at the base of EMPC allows support of time-varying tariffs (i.e., real-time energy trading). 2. Reaction to faults and attacks to the grid: The proposed control strategy can increase node resilience to adverse events by changing the way the energy assets are operated during the emergency conditions, with several measures: • Before the emergency begins, the ESS and the PEV are recharged in view of possible operation in the absence of power supply from the grid (islanded operation).

•
Self-consumption is maximized in order to prolong the operation of the node in the absence of main power supply.
• Low-priority loads are shed as last resort measure in order to prolong the operation of the critical loads in the node.
3. DR applications: The node can implement DR actions by reacting to price signals (modifications of the tariff) and volume signals (modifications of the node power thresholds).These DR measures allow grid actors, like aggregators, to harvest flexibility and compose balancing services. Figure 3 illustrates the control architecture of the proposed EMS. There are two main controllers: a high-level, slower EMPC controller, and a low-level, faster, PID controller. ). 2. The low-level PID controller works at high sampling rate (1 s in the simulations, but potentially even higher rates-e.g., kHz, as required by the use case) and compensates for the impact of uncertainties (e.g., on PV and appliances' consumption forecasts) and disturbances (e.g., activation of non-monitored loads, etc.). It takes as reference the node power profile resulting from EMPC computation (P), and compares it against the smart meter node power measure P measured ; it then activates the ESS to compensate for mismatches.

Proposed Control System Logic
EMPC [63] is a variant of MPC [64], an optimization-based technique in which, at the generic discrete time k, the plant control signals are computed by solving a constrained optimization problem defined in a time window N steps in the future (i.e., [k, k + N − 1]). The first sample of the computed control is applied to the plant and the process is reiterated at time k + 1. The generic optimization problem at time k is built based on the feedback of the state of the plant. Closed loop properties arise from the combination of state feedback and continuous re-optimization. MPC enables multi-variable constrained control and offers great flexibility through the proper selection of the objective function.
In standard MPC, the objective function is selected with the aim of stabilizing the plant around a desired reference state. In EMPC, instead, the objective function is selected to optimize the economical operation of the system (for practical and theoretical implications of EMPC, see e.g., [63,65]).
The controlled plant here is given by the plannable loads, the ESS, and the PEV. The control signals computed through EMPC are: the starting times of the plannable loads, the ESS and the PEV control signals. Furthermore, at each time k the EMS retrieves the state of all the plannable loads currently controlled (started or not-started; non-started loads can be re-scheduled) and the SOC of the ESS and the PEV. The EMPC controller takes the following further inputs: (1) new user requests; (2) updates of the tariff (in the case of real-time pricing); (3) updates of the node power limits (in the case of DR); (4) updates of the PV forecasts; and (5) updates of the loads' forecasted consumption profiles.
Summarizing, the EMPC controller has a planning scope, and acts based on energy feedback (i.e., SOC feedback). If it had perfect and complete knowledge of the loads and generation sources in the node, the second-level fast PID controller would not be needed. The role of the PID controller, which acts based on feedback of power measurement from the smart meter, is indeed that of activating the ESS to compensate for disturbances on the node power profile planned at EMPC level. The two controllers influence each other, since they both act on the ESS (the second-level controller perturbs the SOC feedback acquired by the EMPC one, while the ESS setpoint computed at EMPC level may in practice limit the control possibilities at second PID level; e.g., the ESS EMPC setpoint may be close to the ESS upper/lower threshold and thus make further up/down ESS control corrections by the PID impossible).
The mathematical formulation of the two controllers is detailed in the two following sections.

Design of the EMPC Controller
The core of the proposed EMPC controller is the optimization problem described in this section. In the following, k denotes the current time, N ∈ N the MPC control horizon, and T ∈ R the discretization time step.

Objective Function
The proposed objective function V(k) captures the energy-related costs/profits of the prosumer node. It is composed of three terms, accounting for: (1) costs/revenues from the energy exchanges with the grid; (2) costs/revenues from storing power in the ESS; and (3) depreciation costs for the devices. where: • V(k) grid captures the costs/revenues due to the energy exchanges with the grid over the control where P(i) is the power exchanged with the grid at i and C(i, P(i)) the tariff. V(k) grid can be exactly linearized, as shown in Section 5.2.11. • V(k) ess prices the delta of energy stored in the ESS at the end of the control window, compared to the amount stored at the initial time k. V(k) ess = C ess [SOC ess (k + N) − SOC ess (k)]E ess /100. SOC ess (k) is the SOC of the ESS, expressed in percentage of the maximum energy capacity E ess . C ess prices the energy stored in the ESS.
is the depreciation cost due to the activation of the ESS and the PEV. C dep,ess and C dep,pev are depreciation cost factors weighting the charging/discharging powers. P ess (k) and P pev (k) are respectively the ESS and the PEV exchanged power at k. The depreciation term makes sure that the ESS and the PEV are activated only when the deriving economic benefit overcomes the depreciation costs.

Constraints
Constraints below are defined for all the times i ∈ [k, k + N − 1].

Power Balance Equation
The power exchanged between the node and the grid at i is given by P(i) = P npl (i) + P pl (i) + P ess (i) + P pev (i) + P pv (i) (2) where P npl , P pl , P ess , P pev and P pv are, respectively, the power from non plannable loads, from plannable loads, from the ESS, from the PEV and from the PV panel.

Power of Plannable Loads
P pl (i) is given by (see [29]) where L(i) is the set of plannable loads to be controlled at time i, S l the earliest allowed start time for load l, N l the load duration in time slots, F l the latest allowed termination time, P l the power consumed by load l and s l (j) a Boolean control variable equal to one if and only if load l is scheduled to start at time j.

Power of the ESS
The ESS power can be written as follows: P ess (i) = P ess,c (i) + P ess,d (i) (4) where P ess,c (i) and P ess,d (i) are, respectively, the power absorbed and discharged by the storage at time i.

Power of the PEV
Similarly P pev (i) = P pev,c (i) + P pev,d (i)

ESS Activation
The ESS either absorbs or discharges power at a given time: The first two constraints ensure that the Boolean variables c ess (i) and d ess (i) are equal to one if and only if, respectively, the ESS is charged or discharged at i. Constraint (8) then ensures that charging and discharging are mutually exclusive.

ESS SOC Dynamics
The ESS SOC dynamics can be written as follows: where ξ ess accounts for losses. |P ess (i)| = P ess,c (i) − P ess,d (i). E ess is the energy capacity of the storage (kWh). SOC ess k is the SOC value at k (i.e., the SOC feedback).

PEV SOC Dynamics
Similarly, The last constraint ensures that the PEV is recharged at the desired level within the desired time.

No Arbitrage Constraints
A range of constraints could be imposed to avoid the ESS or the PEV being used to trade with the grid beyond the strict energy needs of the node (e.g., to exploit arbitrage conditions such as buying cheap power and selling it back when the tariff is higher). Arbitrages are limited in practice by the losses associated with ESS charging and discharging, so that they appear only when the difference between tariff's maxima and minima are very high, or in case of very efficient equipment. Such constraints are not included in the simulations below. They can be given on the behavior of the entire node and/or on the behavior of only the storage elements. A very strong condition could be to require the node to behave as a passive one Conditions on the ESS could be: • To allow the ESS to recharge only from the power locally generated (strong condition). P ess,c (i) ≤ −P pv (i) (17) • To allow the ESS to discharge power only to balance local loads (softer condition).
− P ess,d (i) ≤ P npl (i) + P pl (i) + P pev,c (i) (18) 5.2.11. Linearization of the Objective Function Term V(k) grid The term V(k) grid = ∑ k+N−1 i=k P(i)TC(i, P(i)) can be linearized as shown in the following. Let us partition the power interval [P min , P max ] into L sub-intervals ∆P j (i) = [∆P min j (i), ∆P max j (i)], such that a given energy price, say C j (i), is associated to each sub-interval (i.e., the energy price is constant with respect to the power variable in ∆P j (i)). The dependence on i means that the tariff can be time-varying. ∆P min j and ∆P max j are such that ∆P min 1 (i) = P min , ∆P max j (i) = ∆P min j+1 (i) for j = 1, ..., L − 1 and ∆P max L (i) = P max (so that ∪ L j=1 ∆P j (i) = [P min , P max ] and ∩ L j=1 ∆P j (i) is a set of zero measure). A Boolean variable δP j (i) is associated to each power interval ∆P j (i), and it is equal to one if and only if the power exchanged with the grid at time i lies in ∆P j (i) (δP j (i) = 1 ⇔ P(i) ∈ ∆P j (i)). P(i) can belong to only one power interval at a time (save the limit cases in which it is exactly equal to ∆P min The following constraint then forces to one the variable δP j (i) such that P(i) ∈ ∆P j (i).
Hence, P(i)C(i, P(i)) = ∑ L j=1 P(i)δP j (i)C j (i), where C j (i) is the tariff at time i associated to the power interval j. It is only left to linearize the product of the continuous variable P(i) for the Boolean variable δP j (i). It suffices [66] to introduce an auxiliary variable, say z j (i), to represent the product to be linearized, and four auxiliary constraints, as follows: With the above constraints, z j (i) = P(i)δP j (i) always holds. Hence, V(k) grid can be finally rewritten in linear form as

Variables' Limits
The limits of the variables are as follows: P ess,min ≤ P ess (i) ≤ P ess,max P pev,min ≤ P pev (i) ≤ P pev,max

Constraints on Variables' Nature
The variables used are of the following types: SOC ess , SOC pev , P, P ess ∈ R (31) P pl , P pev , P ess,d , P ess,c , P pev,d , P pev,c ∈ R (32)

The Overall EMPC Problem
EMPC iteration at generic time k: given, over the control window [k, k + N − 1], the value of the tariff, the PV forecast, and the user requests and preferences for the execution of loads and the recharging of PEVs, the available power forecasts from plannable and non plannable loads find the loads' start times and the PEV/ESS charging control by solving argmin of (1) subject to (2)- (15) and (18)-(34).

Feedback Controller
The presence of unmonitored loads and the disturbances and uncertainties affecting the PV and the load consumption forecasts, and the ESS and the PEV dynamics, etc., impact on the performance of the EMPC loop. The feedback controller (Figure 4) is introduced to compensate for this. The control signal, denoted as ∆P ess , is a correction term which is summed to the ESS control computed at the EMPC level (see Figure 3). The saturation accounts for the ESS power limitations, which depend both on the ESS maximum and minimum nominal power, and also on the current SOC (e.g., the ESS may be unable to provide high power because close to fully discharged). The design of this controller will be improved in future works, when the control scheme will be integrated with the ESS/PEV/PV dynamics, and metering data at even higher sampling frequency will be employed (e.g., the 16 kHz metering data in [61]).

Simulation Setup
The experimental setup is as follows: • Node power limits: P min = −5 kW, P max = 5 kW.

•
Tariff price as in Figure 5. The figure reports the evolution over 24 h of the Italian reference electricity price (PUN-"Prezzo Unico Nazionale" [67]).

•
Real appliance consumption data from [61] (house 1): 53 loads monitored via smart plugs at 1/6 Hz, plus node's metering data at 1 Hz. Figure 6 shows as an example a dishwasher consumption profile, and two washing machine profiles exhibiting a different variability (i.e., different program phases).
The EMS has been programmed using the Julia v0.5.2 technical computing language (http://julialang.org/), on an Intel I7, 8GB RAM machine running Windows 10. The EMPC optimization problem has been written in Julia, using the JuMP package [68], and has been solved using the Gurobi 7.0.2 solver [69]. Simulations presented in the following showcase the use cases of energy bill optimization (with time of use volumetric tariff and capacity tariff) and the use case of reaction to main supply power outage. All the simulations presented-and the deriving figures-are based on the real data acquired in [61], in "house 1", on 7 and the 8 December 2014 (i.e., the same days displayed in [61]). Data from [61] have time resolution of 6 s at the level of single appliances, and of 1 second at the level of the node smart meter. The dataset described in [61] is available for download as a CSV file (how the data are structured is described in details in [61]). The PV curve data is instead the one from Figure 5. The figures reported below have been obtained in Julia through the plotting functions of the package PyPlot [70]. Two types of figures will be presented in the following: (1) plots of the overall power profile at node level (also called net node power profile, see e.g., Figure 7 below); and (2) stacked bar plots with the detail of the different power consumptions and injections that concur to the overall net node power profiles (power consumptions are plotted as positive bars, power injections as negative bars-see e.g., Figure 8 below). Four scenarios will be simulated: 1. Scenario 1: power profiles in case the node is not controlled (uncontrolled scenario, i.e., same result as in [61] for what concerns the appliances). 2. Scenario 2: application of the proposed approach when considering a TOU tariff. 3. Scenario 3: application of the proposed approach when considering a capacity tariff. 4. Scenario 4: simulation of islanding operation in case of main power supply outage.
The fact that all the presented simulations are based on the same data makes possible to compare the results obtained in the different scenarios.
Finally, an additional note on the nomenclature: in the figures below, P 0,1 denotes power from unmonitored loads, P 2 the power from non-plannable loads which make available to the EMPC their consumption forecast, and P 3 the power from plannable loads. P max P 0, 1 P 2 P 3 P pv P pev  Figure 7 reports the net power profile at the point of connection with the grid, in the uncontrolled scenario. It is as in [61], plus the PV and PEV profiles. A PEV charging request is inserted at 17:00 h on day 1, with 10% current SOC, 100% final desired SOC, and allowed charging time up to 08:00 h of day 2. The PEV is recharged here in uncontrolled mode (charging at the maximum power, 3.3 kW), which leads to violation of the power threshold. Figure 8 reports a stacked chart of the different power consumptions (positive values) and injections (negative values) at node level. The total cost is EUR 1.61.

Scenario 2: Proposed Two-Level EMS
The proposed EMS is effective in shifting plannable loads and PEV recharging to the most convenient times (Figure 9). The action of the ESS is twofold: it compensates for the unknown loads and disturbances (low-level control), and it improves the economic performance of the node through PV self-consumption and balancing of plannable loads and PEV recharging (EMPC control). Figure 10 reports the node power profile computed by the EMPC controller (P), and the corresponding measured profile P measured , when the second level controller is not enabled. The discrepancies are due to the presence of unmonitored loads and uncertainties affecting the data input to the EMPC. Figure 11 reports Figure 10 in detail, including also the measured profile (in red) achieved when the second-level controller is enabled. Figure 12 reports the ESS control detail. The total cost is EUR1.20.
140,000 145,000 150,000 155,000 160,000 165,000 170,000 Figure 11. Scenario 2: Further details with respect to Figure 10, showing (in red) the measured net profile when the second-level controller is enabled (data from [61]).

Scenario 3: Example of Capacity Tariff
It is considered here as an example a capacity tariff in which the cost of the energy from the grid doubles when the power withdrawn exceeds 2 kW. Figure 13 reports the resulting load profile as computed by the EMPC. Comparing it with Figure 10, it can be seen how the EMPC controller weights the information on the 2-kW capacity tariff threshold. 20,000 40,000 60,000 80,000 100,000 120,000 140,000 160,000

Scenario 4: Reaction to Main Power Supply Outage
The EMPC controller can react to notifications of DR signals and adverse events, and plan resources accordingly in advance (the feedback controller in addition allows a fast reaction to sudden events). Here a loss of power supply is simulated from the grid during day 1. Figure 14 shows how the combined action of the two controllers achieves the islanding operation of the node during the outage. The operation is made possible by the combined action of load-shifting, storage, and self-consumption. When this is not enough, prioritized load shedding is unavoidable. One of the interesting features of having a predictive controller is namely that it is able to tell in advance if the resources available are enough to cope with the interruption of main power supply in a given interval, or rather if shedding is required.  Finally, a note on the computational complexity. This scenario is the most complex one in terms of number of variables and constraints, and solving times. For this scenario, consisting, like the others, of 2880 EMPC iterations, the average number of variables, the average number of constraints, and the average solving times were, respectively, 10,274, 16,883 and 0.99 s. Performances are promising and could be further improved by designing tailored MILP solving heuristics.

Limitations of the Proposed Approach
The proposed approach has some limitations. In terms of technological limitations, the approach requires the availability of smart meters with advanced metering and communication functionalities, as compared to the ones currently on the market. These kinds of meters are however being already tested in pilot studies and are expected to reach the market in a few years. In terms of limitations regarding practical implementation: additional constraints on the activation of the storage devices have to be included, in order to ensure that any limitations in the rate of change of charging/discharging are considered (i.e., ramping constraints-they have been left out in order to not overburden the formulation). Also, the impact of practical issues such as delays and loss of data, especially in case of wireless communication, have to be considered for practical implementation. Finally, a practical implementation of the proposed EMS would also benefit from the introduction of load prioritization and the possibility of load shedding, which could become necessary in highly congested scenarios or in case of operation in islanded mode.

Conclusions
This paper has presented a two-level energy management system for prosumer nodes. A-high level controller, based on economic model predictive control (EMPC), optimally plans the energy resources in a future time window, while a second and faster controller provides additional energy storage system (ESS) control to ensure the tracking of the node load profile planned at the EMPC level. Compared to the works in literature the authors are aware of, both control loops work with small sampling times and are based on real data, which makes the results highly significant in practice. The flexibility of the overall scheme allows it to work both in scenarios where pure economic optimization of the tariff is sought (where DR takes the form of tariff updates and/or price signals-i.e., "implicit DR") and in scenarios foreseeing instead a more direct control of the node load profile (e.g., DR through volume signals, node profile smoothing, etc.-i.e., "explicit DR"). Future works will address: (1) a theoretical assessment of the stability of the overall control scheme; (2) a study on the return on the investments, in the light of cost/price trends; andd (3) the study of the system in a standalone configuration, with the inclusion of controllable local generation.
Acknowledgments: The authors gratefully acknowledge company Gurobi EMEA, the Julia community, and the anonymous reviewers.
Author Contributions: Francesco Liberati contributed to the overall design of the proposed energy management system and in particular to the development of the tariff model and of the linearized version of the control algorithm. He developed the simulation software using the Julia programming language and performed the simulations. Alessandro Di Giorgio contributed to the overall design of the proposed energy management system based on the model predictive control technique. He provided the detailed analysis of the state of the art and the critical revision of the simulations presented to show the effectiveness of the proposed energy management system.

Conflicts of Interest:
The authors declare no conflict of interest.

C
Electricity tariff C j Electricity tariff value for the power interval ∆P j C ess Pricing factor of the energy stored in the energy storage system (ESS) C dep,ess Depreciation factor for the ESS C dep,pev Depreciation factor for the plug-in electric vehicle (PEV) c ess (i) Boolean variable equal to one if the ESS is recharging at time i, zero otherwise d ess (i) Boolean variable equal to one if the ESS is discharging at time i, zero otherwise ∆P j j-th interval of powers where the electricity tariff is constant with respect to the power variable ∆P ess Correction of the ESS control resulting from the Proportional-Integral-Derivative (PID) control δP j Boolean variable equal to one if the node power consumption is in the interval ∆P j , zero otherwise ∆P min j , ∆P max j Bounds defining δP j : δP j ∈ [∆P min j , ∆P max j ] e P Difference between P and the node power measured by the meter P measured (i.e., power error) E ess Maximum energy capacity of the ESS [kWh] E l Latest possible finish time for the l-th plannable appliance (decided by the user) F pev Latest possible time for completion of the PEV recharging (decided by the user) k Generic discrete time index L Number of intervals ∆P j into which the node power consumption [P min , P max ] is divided N Integer number denoting the length of the MPC prediction horizon N l Integer number denoting the duration, in time slots, of the execution of the l-th appliance P Node power consumption (i.e., power exchanged between the node and the grid), as computed by the MPC controller P 0,1 In the simulations, denotes the power from non monitored loads (e.g., legacy loads not connected through a smart plug) P 2 In the simulations, denotes the power from monitored but uncontrolled loads (e.g., legacy loads connected through a smart plug) P 3 In the simulations, denotes the power from monitored and controllable loads P measured Measured node power consumption P max , P min Maximum positive (i.e., consumption) and minimum negative (i.e., injection) allowed values for P P pv Photovoltaic (PV) power P ess Electric ESS power P ess,c ESS charging power P ess,d ESS discharging power P npl Aggregated power consumed by non plannable loads P pl Aggregated power consumed by plannable loads P pev Power exchanged between the PEV and the node S l Earliest allowed start time for the l-th plannable appliance (decided by the user) s l (j) Boolean variable equal to one if the l-th appliance is started at time j, zero otherwise SOC pev,req Desired final state of charge for the PEV at the end of the recharging process (decided by the user) SOC ess State of charge of the ESS T Discretisation time step V Target function of the MPC problem z j (i) Auxiliary variable equal to P(i) if δP j (i) = 1, zero otherwise ξ ess (i) Efficiency coefficient of the ESS () * * denotes the actual value of a variable (as opposed to an estimated or measured quantity)

Abbreviations
The following abbreviations are used in this manuscript: