Keywords

1 Introduction

In the last decades renewable energy has become a topic of primary importance. Renewables are viewed as an alternative to traditional fossil fuels with the advantage of being endless natural sources with lower carbon dioxide emissions. However, the benefits of renewable energy come at a price of increasing complexity regarding safe operation of the energy grid [5, 6]. Motivated by financial and environmental concerns, many grid users have become both producers and consumers of electricity – the so-called prosumers. The proliferation of distributed energy resources poses several challenges, which include two-directional power flow and overload issues due to intermittent nature of renewables and irregular consumption [10].

Local Energy Communities (LECs) is a promising way to integrate renewable energy sources and engage grid users in the energy transition [16, 19]. Communities often include members who know and trust each other as well as share common goals and interests. LECs enable energy exchange at the community level allowing grid users to buy and sell energy locally. Local energy exchange is beneficial as losses due to transmission of electricity over long distances are avoided and funds are kept withing local economy. Communities can also participate in energy markets (e.g. wholesale, balancing, reserve markets ...), since by acting together, community members have stronger negotiation power when interacting with other energy market participants.

During recent years, the focus on LECs has been growing steadily leading to a number of industrial projects and research publications [16]. In this view, one interesting topic is the design of a peer-to-peer (P2P) market in which participants can buy and sell their energy. In [13], this was approached using the concept of virtual currency for governing the exchange of energy between community members, being the effectiveness of the local market highly depending on the definition of functions that determine buying and selling prices [3, 11]. While the functions proposed in [13] were designed to encourage balance between energy production and consumption, they ignored other important aspects such as the possibility of peers to adopt a strategic behavior. Usually, these strategic aspects are taken into account by means of game theory. In [14], price-based schemes and a game-theoretical framework have been investigated to coordinate flexible demand. The study described a promising approach but lacked consideration of distributed generation and energy storage systems. In [15], an auction-based market mechanism has been presented in which households submit their consumption bids and generation offers, which are, in turn, being used to determine prices and allocate energy. However, under these auction based schemes, participants need to provide accurate estimates of energy and prices to get profitable results, their final benefits being dependant on the outcome of complex forecasting models. Major advantages of P2P schemes are related to their decentralized nature as no central supervisory entity is needed and privacy concerns are diminished.

On the other hand, there is the possibility of creating a cost sharing mechanism in which the community has a single electricity bill that is shared among its members. This approach assumes a common goal to be pursued instead of individual ones and aims for cooperative behaviour of community members. In [12], a two stage aggregated control is proposed to realize this idea where an energy sharing coordinator controls flexible devices. An interior-point method was used to minimize the energy costs of the community. However, the centralized nature of this method is a major drawback that is also common to many existing approaches based on energy sharing. Centralization limits scalability and rises concerns about privacy as data are stored and processed in a single location. In contrast with centralised approaches, multiagent systems are well established paradigm for implementing decentralize computerized systems. A good survey regarding MAS applications for microgrid control can be found in [8]. Closer to our work, peer-to-peer trading in a local energy community using MAS has been previously addressed by [20, 21]. As in this paper, both works uses the Alternating Direction Method of Multipliers (ADMM) as the underlying protocol for agent negotiation. However, [20] is based on a very simplistic and abstract electricity prosumer model that consists on a set of allowed power profiles and a measure of dissatisfaction with respect to each profile. Similarly, [21] only considers electricity and a limited number of flexible devices. In conclusion, existing works often miss a careful outline of multiagent modeling methodology, use simple prosumer models and mostly focus on a single type of energy such as electricity.

Against this background, this paper presents a multiagent system developed for managing a local energy community. The multiagent models the energy network accounting for both electricity and heat. It solves an optimal power flow problem that is formulated as a convex optimization problem. Solutions yield optimal actions for controlling devices. The optimization is performed by decomposing the underlying problem into a number of smaller subproblems that are distributed among different computing agents. This study builds on our previous work presented as a conference paper in [4]. Herein it is consolidated and extended in several important ways: (i) we describe a multiagent system modeling starting from an individual building; (ii) we extend a congestion management approach by adding the model for ensuring flexibility delivery; and (iii) we present new results including fitting model parameters, building optimization, and congestion management.

The remainder of the paper is structured as follows. Section 2 outlines the decentralised optimization approach used to solve the underlying decision making problem. Section 3 presents multiagent system models. Section 4 details, for each type of agent, the local optimisation that allows them to participate in the decentralised negotiation. Section 5 presents and discusses the obtained results. Finally, Sect. 6 concludes the work.

2 Decentralised Optimisation Approach

We develop a multiagent system (MAS) with the aim to enable an autonomous and intelligence functioning of a local energy community. MAS models the energy grid as a network of computational agents that solve individual tasks and interact by exchanging messages. We use the Alternating Direction Method of Multipliers (ADMM) as the protocol for agent interactions, which determines the structure and order of messages. ADMM is a variant of augmented Lagrangian method for solving constrained optimization problems. It offers a powerful framework for distributed problem solving, which is suitable for problems whose structure can be represented by a bipartite graph. With this representation, nodes in the graph are assigned with tasks whilst edges show the structure of interactions and coupling between the tasks.

Fig. 1.
figure 1

A bipartite graph represents energy network and describes the structure of MAS. Two types of nodes are devices and nets, respectively depicted by circles and rectangles.

We represent energy networks as bipartite graphs and refer to agents and nodes interchangeably. In graphs, there are two types of nodes such as devices and nets that are depicted by circles and rectangles respectively, as shown in Fig. 1. The MAS manages the community energy network by controlling flexible loads. Flexible loads are those loads whose consumption can be shifted to better meet grid users’ needs and goals. The needs are related to satisfying comfort preferences of residents. The goals involve reducing the energy costs and ensuring the grid stability. The first goal is sought by making a better use of locally produced renewable energy through increasing self-consumption. This is because renewable energy is free for a particular household if is produced from its rooftop panels, and is cheaper when it comes from the neighborhood relative to that imported from the grid. The second goal relates to the fact that power flows should be within grid capacity limits. It is achieved by avoiding both excessive consumption of energy from the grid and excessive injection of renewable energy into the grid.

The needs and goals of grid users are addressed by solving power flow problems with appropriately formulated objective and constraint functions. The obtained solutions yield optimal control actions for agents. The structure of MAS described by a bipartite graph allows to formulate an optimization problem in the form

$$\begin{aligned} \begin{aligned} \underset{x_i \in \varOmega _i, z_i \in \varTheta _i}{\text {minimize}}\quad&\sum \limits _{i \in D} f_i(x_i) + \sum \limits _{i \in N} g_i(z_i)\\ \text {subject to}\quad&x_i = z_i, \;\;\forall i \in N \end{aligned} \end{aligned}$$
(1)

where \(f_i\) is a real valued objective function, defined in the feasible region \(\varOmega _i\), that is associated with the i-th device, \(g_i\) is a real valued objective function, defined in the feasible region \(\varTheta _i\), that is associated with the i-th net, \(x_i\) and \(z_i\) are the decision variables associated with the i-th device and net respectively. The constraints account for the fact that respective device and net agents should agree upon the values of shared variables.

Finding the minimizer to an equality constrained optimization problem is equivalent to identifying the saddle point of the associated Lagrangian function. This gives the following augmented Lagrangian function

$$\begin{aligned} L(x,z,\lambda ) = \sum \limits _{i \in D} f_i(x_i) + \sum \limits _{i \in N} g_i(z_i) + \frac{\rho }{2} \sum \limits _{i \in N} \Vert x_i-z_i+u_i\Vert _2^2 \end{aligned}$$
(2)

where \(u_i = \lambda _i / \rho \) is the scaled dual variable (for Lagrange multipliers \(\lambda _i\)) , \(x_i\) and \(z_i\) are primal variables.

The augmented Lagrangian function (2) is minimized with respect to primal and dual variables. Each iteration involves the following steps.

Step 1. Device agents compute in parallel their optimal variables by solving

$$\begin{aligned} x_{i\in D}^{(k+1)} = \mathop {\mathrm {arg\,min}}\limits _{x_i \in \varOmega _i} f_i(x_i) + \frac{\rho }{2} \Vert x_i - (z_i^k - u_i^k)\Vert _2^2 \end{aligned}$$
(3)

The corresponding values are communicated to neighboring nets.

Step 2. Net agents compute in parallel their optimal variables by solving

$$\begin{aligned} ~ z_{i\in N}^{(k+1)} = \mathop {\mathrm {arg\,min}}_{z_i \in \varTheta _i} g_i(z_i) + \frac{\rho }{2} \Vert z_i - (x_i^{(k+1)} + u_i^k)\Vert _2^2 \end{aligned}$$
(4)

Step 3. Net agents in parallel update their dual variables.

$$\begin{aligned} u_{i\in N}^{(k+1)} = u_i^k + (x_i^{(k+1)} - z_i^{(k+1)}) \end{aligned}$$
(5)

The corresponding primal and dual variables are sent to neighboring devices.

The above steps are repeated until convergence criteria are met. The convergence criteria are checked locally by nets and defined for primal and dual residuals as

$$\begin{aligned} \begin{aligned} r^{\text {primal}}&< \epsilon ^{\text {primal}} \\ r^{\text {dual}}&< \epsilon ^{\text {dual}} \\ \end{aligned} \end{aligned}$$
(6)

where \(\epsilon ^{\text {primal}},\epsilon ^{\text {dual}}\) are small positive numbers representing primal and dual tolerances, respectively. The primal and dual residuals are computed as

$$\begin{aligned} \begin{aligned} r^{\text {primal}}&= \Vert x_i^k - z_i^k \Vert _2 \\ r^{\text {dual}}&= \Vert \rho (z_i^k - z_i^{k-1}) \Vert _2 \\ \end{aligned} \end{aligned}$$
(7)

If the device and net functions f(x) and g(z) are convex, the constraint residual under ADMM is guaranteed to converge to zero and the objective value to the minimum of the dual problem, see [1].

3 Community and Multiagent Models

In this section we first give a general description of the community under study. Next we present a multiagent model of the energy network in individual building. Then we present a multiagent model of the whole community aggregating the models of different buildings.

3.1 Local Energy Community

As reported in [4], our study case involves a community of households located in the central Netherlands. Figure 2 depicts a general architecture. The community consists of 16 households and a district battery with the capacity of 220 kWh. Each household has a heat pump of 2 kW combined with a hot water buffer of 200 L. The heat pump is used for heating both domestic hot water and spatial heating. Each house has solar photovoltaics capable of producing up to 7 kW. Additionally, there is one in-home battery with the capacity of 7.8 kWh.

There is also the information and communications technology infrastructure that consists of different communication devices, software applications and protocols. Each house is equipped with a local energy gateway that is connected with flexible devices and it is able to communicate with the backend run on a cloud by means of the Advanced Message Queuing Protocol. Local energy gateways are used to control flexible devices and to communicate sensory data. The MAS runs on the cloud. The cloud also provides means for interaction with other energy market participants.

Fig. 2.
figure 2

Architecture of local energy community.

3.2 Building Energy Network

As a first step we develop multiagent models of building energy networks considering each building individually. Based on the presence of in-home battery we distinguish buildings with and without battery. Figure 3 displays the computation graph describing multiagent system for the building with battery.

The agent types and roles were defined in [4] and are as follows:

  • Electrical Net (ENet) models the electrical network in the house energy system ensuring the balance of electrical energy.

  • Heating Net (HNet) models the heating network in the house energy system ensuring the balance of heat energy.

  • Battery Net (BNet) ensures the energy balance in the decomposed model of battery.

  • External Tie (ET) represents a connection to an external source of power.

  • Connector (C) connects two nets modelling the transmission of energy. The transmission can be associated with losses. The transmission loss from ENet to BNet models a charging efficiency. The transmission loss from BNet to ENet models a discharging efficiency.

  • Battery (B) models an electrical storage that can take in or deliver energy.

  • Photovoltaics (PV) represents solar panels that generate electricity from absorbing sunlight.

  • Fixed Load (FL) represents an inflexible energy consumption that must be satisfied.

  • Heat Pump (HP) models the transformation of electricity to heat with some conversion coefficient.

  • Space Heating (SH) models indoor air temperature that must be kept within comfort limits.

  • Hot Water Storage (HWS) models the hot water tank and the domestic hot water consumption.

Fig. 3.
figure 3

Multiagent model of building energy network.

The model includes the electrical and heating networks shown in blue and red respectively. These networks account for the flows of respective types of energy. A heat pump agent (HP) connects two networks serving as a converter of electricity to heat. Net agents ensure the balance of corresponding energies (i.e. the ENet ensures electricity balance, the HNet heating balance and the BNet balance inside the battery model). The battery with losses is represented by connector, net and battery agents. The connector agent (C) that connects to the battery net models losses associated with charging and discharging. Finally, the battery agent (i.e. B) models linear constraints associated with its charge capacity. The models of remaining buildings are obtained by eliminating agents related to the in-home-battery.

3.3 Community Energy Network

In [4], we developed a multiagent model of the community energy network. The model is shown in Fig. 4. It was obtained by aggregating individual models of district assets, such as houses and the battery storage, and connecting them to LEMNet agent. LEMNet represents a local energy market where district actors negotiate their energy exchange. LEMNet is also connected to an external source of power that represents a connection point between the community and the main grid. In this view, the interaction protocol defined by the ADMM algorithm models negotiation of the energy exchange between actors in the community. The actors are the district battery storage, the prosumers and the main grid. Connector agents (i.e. C) that connect houses to the LEMNet serve as interface between the prosumers and the local energy market.

Agents connected to LEMNet negotiate energy exchange at the community level. In each iteration, LEMNet sends messages that can be viewed as requests. These messages contain the amount of energy requested, \(z_i^k\). The sign is used to distinguish between production and consumption. From a recipient perspective, a positive value indicates that the energy flows towards the recipient, a negative value indicates the flow towards the sender. It also includes the price, \(u_i^k\), which not only indicates the current market price, but also is used to distinguish between a situation of overconsumption (in which the price are positive) and a situation of underconsumption (in which the price are negative). Agents coordinate their actions through negotiation until consensus is reached on their energy use. The resulting actions in terms of energy use represent the optimal decisions with respect to the common goal of reducing the energy cost for the community.

Fig. 4.
figure 4

Multiagent model of the community energy network.

Along with the cost effectiveness, the MAS aims to ensure safe operation of the energy grid. The grid has the potential to experience times of intensive injection of renewable energy and excessive pulling of energy due to high consumption. Such conditions increase stress on the grid and could push it into failure. The grid condition when its capacity is insufficient to accommodate the requested power flows is referred to as congestion. Congestion management is performed to avoid overload and to ensure stability of the grid.

We consider congestion management using the Universal Smart Energy Framework (USEF) [7], which focuses on the use of market-based flexibility for congestion management. The aggregator and the Distribution System Operator (DSO) are two major players involved. The aggregator is an energy market participant that aggregates the energy consumption and generation of several consumers aiming to maximize the value of flexibility. The DSO is responsible for the operation and maintenance of the distribution grid ensuring that the energy in the system can flow between suppliers and consumers. The DSO performs grid safety analysis identifying potential congestion points. In case of congestion, the DSO procures flexibility through market based procedures sending a flexibility request to the aggregator active at the congestion point. This request indicates the need to reduce load and the available capacity at each time interval. In response, the aggregator optimizes its portfolio and provides a flexibility offer in terms of energy profile and price. The DSO analyses the offer and responds with an updated request or a flexibility order. The former occurs if the offer is not sufficient to solve the congestion. The latter indicates the offer is accepted and the aggregator is to be paid for the delivered flexibility. The flexibility is negotiated for the next day, starting after midday and continuing until agreement or timeout.

Our multiagent system is a part of the aggregator’s infrastructure used to provide flexibility services to the DSO. For congestion management, the structure of the MAS remains as is in Fig. 4. Appropriate modifications are only introduced to the ET agent. Congestion management determines two running regimes for the MAS. The negotiation phase happens for the day ahead, where the MAS provides solutions in response to flexibility requests. The DSO requests are transformed into constraints limiting power flows and the constrained optimization problem is solved yielding corresponding flexibility offers. During the course of the operating day, the MAS balances the differences between day-ahead commitments and the actual real-time operation. This is approached by solving optimization problems with objective functions aiming to minimize mismatch between target and actual energy use in the community.

4 Local Agent Optimisation Models

This section presents formulations of agents local subproblems and describes how those are solved.

4.1 Nets

All the net agents are considered to be instances of the Net agent. This agent solves the following subproblemFootnote 1 [4]

$$\begin{aligned} \begin{array}{rl} &{} \text {minimize:} \sum \limits _{\tau =1}^{H} (z_1(\tau ) - y_1(\tau ))^2 +\; \ldots \; +\sum \limits _{\tau =1}^{H} (z_{n}(\tau ) - y_{n}(\tau ))^2\\ &{} \text {subject to:} \sum \limits _{i=1}^{n} z_i(\tau ) = 0, \quad \tau = 1, \ldots , H. \end{array} \end{aligned}$$
(8)

where n is the number of neighbors. The constraints aim to ensure the energy balance. The problem (8) is solved by projecting the variables received from neighboring devices onto the feasible region. For each time interval \(\tau = 1, \ldots , H\) and each neighbor \(i = 1, \ldots , n\), the optimal values are computed as

$$\begin{aligned} z_i^{*}(\tau ) = x_i - \bar{x}(\tau ) \end{aligned}$$
(9)

where \(\bar{x}(\tau )\) is the average of neighbors’ variables at time interval \(\tau \).

4.2 External Tie

External Tie (ET) represents a connection to an external source of power. There are three different operational modes defined as follows.

Minimizing Energy Cost. It is associated with the objective function aiming at minimizing the energy cost. The ET agent solves the following local subproblem

$$\begin{aligned} \begin{array}{rl} \text {minimize:} &{} \sum \limits _{\tau =1}^{H} -c(\tau )\; x (\tau ) + \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2\\ \end{array} \end{aligned}$$
(10)

where

$$\begin{aligned} c(\tau ) = \left\{ \begin{array}{ll} c^{\text {sell}}(\tau ) &{} \text {if } x (\tau ) \ge 0 \\ c^{\text {buy}}(\tau ) &{} \text {otherwise} \end{array} \right. \end{aligned}$$
(11)

\(c^{\text {sell}}(\tau )\) and \(c^{\text {buy}}(\tau )\) are the prices of exported and imported energy, respectively. A positive value of \(x(\tau )\) indicates the energy is exported to the grid while a negative value of \(x(\tau )\) indicates the energy is imported. The function is separable and thus we can consider each of its components separately. The subproblem is solved by finding a critical point for \(x (\tau ) \ge 0\) as

$$\begin{aligned} x^{+}(\tau ) = \max \{0,\; c^{\text {sell}}(\tau ) / \rho + y(\tau )\} \end{aligned}$$
(12)

and a critical point for \(x (\tau ) \le 0\) as

$$\begin{aligned} x^{-}(\tau ) = \min \{0,\; c^{\text {buy}}(\tau ) / \rho + y(\tau )\} \end{aligned}$$
(13)

Both \(x_{+}^{*}(\tau )\) and \(x_{-}^{*}(\tau )\) are evaluated using (10). The one having the lower value is selected to be the optimal value of \(x^{*}(\tau )\) at time interval \(\tau \).

Addressing Flexibility Request. The flexibility request from the DSO is transformed into the set of constraints restricting the flow of energy coming into and out from the community. This is addressed by extending the subproblem of the ET agent as follows

$$\begin{aligned} \begin{array}{rl} &{} \text {minimize:} \sum \limits _{\tau =1}^{H} -c(\tau )\; x (\tau ) + \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2\\ &{} \text {subject to:}\; x^{\min }(\tau ) \le x (\tau ) \le x^{\max }(\tau ) \;\; \tau = 1,\ldots ,H \end{array} \end{aligned}$$
(14)

Notice that in (14) the objective function is the same as in (10) but constraints are added to address the flexibility request. The problem is separable and is solved by finding solutions for individual components. The critical point for \(x (\tau ) \ge 0\) is

$$\begin{aligned} x^{+}(\tau ) = \max \{0,\; \min \{x^{\max }(\tau ), \;\; c^{\text {sell}}(\tau ) / \rho + y(\tau ) \} \} \end{aligned}$$
(15)

and for \(x (\tau ) \le 0\) it is

$$\begin{aligned} x^{-}(\tau ) = \min \{0,\; \max \{x^{\min }(\tau ), \;\; c^{\text {buy}}(\tau ) / \rho + y(\tau )\} \} \end{aligned}$$
(16)

Both \(x_{+}(\tau )\) and \(x_{-}(\tau )\) are evaluated using (14). The one having the lower value is selected to be the optimal value of \(x^{*}(\tau )\) at time interval \(\tau \). The projection ensures that the solution lies within the feasible region and satisfies the constraints.

Ensuring Flexibility Delivery. The community should fulfill its obligations by delivering the energy profile agreed with the DSO during negotiation. Forecasts are imperfect and yield differences between predicted and observed values. Control actions based on inaccurate forecasts have the potential to mismatching the agreed energy use, which in turn leads to economical penalties. The MAS mitigates potential deviations from the target profile by running in a rolling horizon regime with the ET agent solving the following subproblem

$$\begin{aligned} \begin{array}{rl} \text {minimize:} &{} \sum \limits _{\tau =1}^{H} -c(\tau )\; x (\tau ) + \sum \limits _{\tau =1}^{H} \frac{w(\tau )}{2} (x (\tau ) - t (\tau ))^2 + \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2\\ \end{array} \end{aligned}$$
(17)

where \(t (\tau )\) is the target energy consumption/production and \(w(\tau )\) is the penalty coefficient. The subproblem (17) extends the original subproblem of ET agent in (10) by adding an extra term that penalizes the deviation from the target values. The problem is separable and is solved by finding solutions for individual components. The critical point for \(x (\tau ) \ge 0\) is

$$\begin{aligned} x^{+}(\tau ) = \max \left\{ 0,\; \frac{c^{\text {sell}}+\rho \; y(\tau )+w(\tau )\; t(\tau )}{\rho +w(\tau )} \right\} \end{aligned}$$
(18)

and for \(x (\tau ) \le 0\) it is

$$\begin{aligned} x^{-}(\tau ) = \min \left\{ 0,\; \frac{c^{\text {buy}}+\rho \; y(\tau )+w(\tau )\; t(\tau )}{\rho +w(\tau )} \right\} \end{aligned}$$
(19)

Both \(x_{+}(\tau )\) and \(x_{-}(\tau )\) are evaluated using (17). The one having the lower value is selected to be the optimal value of \(x^{*}(\tau )\) at time interval \(\tau \).

4.3 Connector and Heat Pump

Connector (C) and heat pump (HP) agents connect two nets modelling the transmission of energy between different parts of the energy network. The transmission can be associated with losses. Both C and HP are instances of an agent that solves the following subproblem [4]

$$\begin{aligned} \begin{array}{rll} &{} \text {minimize:}&{} \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x_1(\tau ) - y_1(\tau ))^2 + \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x_2(\tau ) - y_2(\tau ))^2\\ &{} \text {subject to:} &{} \eta _1 \; x_{1} (\tau ) = -x_{2}(\tau ) \quad \text {if } 0 \le x_{1}(\tau ) \le x_{1}^{\max }(\tau ) \\ &{}&{} -x_{1}(\tau ) = \eta _2 \; x_{2} (\tau ) \quad \text {if } 0 \le x_{2}(\tau ) \le x_{2}^{\max }(\tau ) \end{array} \end{aligned}$$
(20)

where \(\eta _1,\eta _2 \in (0,1]\) are transmission efficiencies and \(x_{1}^{\max },x_{2}^{\max } \ge 0\) are the maximum values restricting the energy flow from the corresponding net. The two constraints correspond to the two possible scenarios: (i) when the energy flows from net 1 to net 2 and (ii) when the energy flows in the opposite direction, from net 2 to net 1. The problem (20) is separable and is solved for each time step \(\tau \) individually by finding critical points for two cases and selecting the one with a lower value of objective in (20).

4.4 Photovoltaics and Fixed Loads

On one hand, photovoltaics (PV) represent solar panels that generate electricity from absorbing sunlight. On the other hand, a Fixed Load (FL) represents an inflexible energy consumption that must be satisfied. Both PV and FL are instances of an agent that solves the following subproblem [4]

$$\begin{aligned} \begin{array}{rl} &{} \text {minimize:} \;\frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2 \\ &{} \text {subject to:}\; x(\tau ) = \hat{x}(\tau ),\quad \tau = 1,\ldots ,H \end{array} \end{aligned}$$
(21)

where \(\hat{x}\) are forecast values. The solution to (21) is trivial (\(x^k = \hat{x}\)).

4.5 Battery

Battery (B) represents an electrical storage that can take in or deliver energy. The B agent has a set of constraints aiming to keep its state of charge as well as charging and discharging rates within the allowed range. The B agent solvesFootnote 2 the following subproblem [4]

$$\begin{aligned} \begin{array}{rll} &{} \text {minimize:} &{} \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2 \\ &{} \text {subject to:}&{} Q^{\min } \le Q(\tau ) \le Q^{\max },\quad \tau = 1,\ldots ,H \\ &{}&{} x^{\min } \le x(\tau ) \le x^{\max },\quad \tau = 1,\ldots ,H\\ \end{array} \end{aligned}$$
(22)

where \(Q^{\min }\) and \(Q^{\max }\) are the minimum and maximum allowed charge of the battery, \(x^{\min }\) and \(x^{\max }\) are the limits of discharging and charging rates. The battery’s charge evolves as in [9]

$$\begin{aligned} Q(\tau ) = Q^{\text {init}} + \sum \limits _{\tau =1}^H x(\tau ) \end{aligned}$$
(23)

where \(Q^{\text {init}}\) is the initial charge of the battery.

4.6 Space Heating

Space Heating (SH) represents indoor air temperature that must be kept within limits for comfort. The SH agent solves(see footnote 2) the following subproblem [4]

$$\begin{aligned} \begin{array}{rl} &{} \text {minimize:}\; \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2 \\ &{} \text {subject to:} \; T^{\min } \le T(\tau ) \le T^{\max },\quad \tau = 1,\ldots ,H \\ \end{array} \end{aligned}$$
(24)

where \(T^{\min }\) and \(T^{\max }\) are the temperature limits. For \(\tau = 1,\ldots ,H\), the room temperature evolves as in [9]

$$\begin{aligned} T(\tau ) = T(\tau -1) + \frac{\mu }{c}\cdot \Big (T^{\text {amb}}(\tau ) - T(\tau -1)\Big ) + \frac{\eta }{c}\cdot x(\tau ) \end{aligned}$$
(25)

where T(0) is the initial temperature, \(T^{\text {amb}}\) is the outdoor temperature, \(\mu \) is the conduction coefficient, \(\eta \) is the heating efficiency and c is the heat capacity of indoor air.

4.7 Hot Water Storage

Hot Water Storage (HWS) represents the tank with hot water and the consumption of domestic hot water. The HWS agent solves(see footnote 2) the following subproblem [4]

$$\begin{aligned} \begin{array}{rl} &{} \text {minimize:} \; \frac{\rho }{2} \sum \limits _{\tau =1}^{H} (x(\tau ) - y(\tau ))^2 \\ &{} \text {subject to:} \; T^{\min } \le T(\tau ) \le T^{\max },\;\tau = 1,\ldots ,H \\ \end{array} \end{aligned}$$
(26)

with \(T^{\min }\) and \(T^{\max }\) are the temperature limits. For \(\tau = 1,\ldots ,H\), the water temperature evolves as [18]

$$\begin{aligned} T(\tau ) = T(\tau -1) + \frac{V_{\text {cold}}(\tau )}{V_{\text {total}}}\cdot \Big (T_{\text {cold}} - T(\tau -1)\Big )+ \frac{1}{V_{\text {total}}\cdot c} \cdot x(\tau ) \end{aligned}$$
(27)

where T(0) is the initial temperature, \(V_{\text {cold}}\) is the volume of water with temperature \(T_{\text {cold}}\) entering the tank to replace the consumed hot water, \(V_{\text {total}}\) is the tank volume, and c is the specific heat of water. The consumption of hot water is given by forecast.

5 Results and Discussion

This section presents and discusses the results of validation tests. The tests were performed using the data for the winter season. Winter days are characterized by the need to use heat pump for both heating domestic hot water and maintaining room temperature within comfort limits. This represents the most challenging optimization scenario as during other seasons heat pump is only used for reheating domestic hot water. The optimization considers a 24-h time horizon divided into 96 program time units (PTUs), with each one corresponding to 15-min interval.

5.1 Estimating Parameters and Validation of Local Models

The local optimization models of agents formulated in Sect. 4 need parameters for their initialization. Some of these parameters represent physical properties whose values can be readily encountered in the literature, e.g. the heat capacity of air or the specific heat of water. Instead, others are more specific for the application context and should be estimated from the data. This is the case of the conduction and thermal efficiency coefficient parameters of the heat pump, space heating and domestic hot water storage agents. For these parameters, in this section we carried out a study to estimate them from the database of historical records and validate in this way the effectiveness of our agent models. In more detail, the values of these parameters were determined through optimization by minimizing a sum of squares representing differences between temperature values from historical data and those computed by agent models.

Fig. 5.
figure 5

Temperature profiles given by model and historical data for the (a) space heating and (b) hot water storage agent models.

Figure 5 shows temperature profiles coming from historical data and corresponding models with estimated parameters for the space heating and hot water storage models. The plots refer to the data collected for one house during the first two months of 2019. As expected, there is no perfect fit between the real and estimated values. This can be explained by imperfections in sensors, measurements, noise, as well as the linear nature of models. However, it can be seen that the models can adequately approximate important temperature dynamics regarding both the room air and domestic hot water. Notice that the line representing the values estimated by the model follows the general trend. As to space heating, the model approximates the decrease in room temperature due to weather conditions and its increase as a result of heating as a consequence of the action of the heat pump. Regarding hot water, the model provides adequate temperature estimates for periods of water consumption and reheating. The latter is particularly challenging due to irregular consumption profile and complex thermal dynamics inside the tank.

It is important to note that these plots depict temperature estimates for two months on a daily basis. For each day, the temperature was calculated for each of 96 time slots, corresponding to 15-min intervals during 24 h. The difference between the real and estimated values is smaller in the beginning of each time horizon. This is because the models use real sensor measurements for the previous time slot. When estimating the values for the following time slots, the models rely on estimates from previous slots instead of the real values. This way, errors are accumulated making the discrepancy between the real and estimated values higher in the later time slots. In practice, the above issue can be effectively addressed by a receding (rolling) horizon optimization. This technique involves the MAS updating all the parameters and running the optimization in the beginning of each time slot, i.e. every 15 min. As a result, uncertainties are expected to be cancelled out or minimized.

5.2 Building Optimization

We validated the MAS models of buildings in the community by optimizing each building individually. This represents a valid approach for minimizing the energy costs for community members. Though, in this study, we focus on the collective energy management and use the results of the two approaches for comparison purposes. In the community, the buildings have similar characteristics in terms of devices and consumption patterns. The main source of flexibility in most buildings comes from both the admissible ranges of temperatures for domestic hot water and indoor air. The building with in-home battery has the largest potential in terms of flexibility. The presence of battery allows for storing the energy in time intervals when there is the surplus of PV production. It also enables storing the energy imported from the grid for a later usage (i.e. future domestic needs and/or injecting it back to the grid). Here we limit the presentation of building optimization results to the case of the building with in-home battery.

Fig. 6.
figure 6

Energy consumption with shares of different loads.

Figure 6 shows a daily consumption for the building with battery. The effects of optimized battery usage can be observed. The optimization suggests using the battery for storing the energy in off-peak periods and then releasing it to satisfy uncontrollable consumption, which is represented in our models by the flexible load device. The results clearly indicate the benefits of having the battery installed inside the house. The battery provides a significant flexibility in terms of energy usage, which also indicate incentives for investing in electrical storage installation.

From the experiments, we observed that the consumption of heat pumps can be shifted to keep indoor and water temperatures inside the admissible range. Though, the flexibility is relatively limited. This fact can be explained by the power of heat pumps and some characteristics of thermal loads. As for room temperature, heating a building is a very slow process. The use of heat pumps for space heating is regular and without high amounts of consumed energy. This contrast with heating domestic hot water whose consumption is short time and irregular in consumed volume. Heating domestic hot water is a relatively fast process but requires large amounts of energy in short periods of time. Once a large volume of hot water is drawn from the tank, it is replaced by the same volume of cold water that must be heated to ensure the temperature limits with low flexibility. The promise comes from aggregating several heat pumps to increase the amount of flexibility, which is discussed next.

5.3 Community Optimization

Community members participate in community energy management with the common goal of increasing social welfare through collective use of local resources [4]. They coordinate the energy use to reduce the shared cost at the connection point between the community and the main grid. The multiagent system automates the process of coordination by optimizing energy flows and using the solutions for control actions. When running a day ahead optimization, the system attempts to schedule energy consumption for flexible loads to time intervals with available renewable energy. Starting optimization at different time slots during the day changes the perspective as the time horizon moves forward embracing time slots from the next day. The optimization is executed at the beginning of each time interval with updated sensor data. This operational mode is known as rolling horizon optimization. Rolling horizon can mitigate uncertainties in the models, such as forecast errors, and account for the fact that the real time horizon is not limited to a single day.

Fig. 7.
figure 7

Energy profile of the community with simple day ahead optimisation and with rolling horizon optimisation, adapted from [4].

Figure 7 shows the resulting dairy energy profile of the community as a result of the rolling horizon optimization. For comparison, the graph also shows the results of the day ahead optimization. The day ahead approach yields the results from single optimization run at the beginning of the day. The rolling horizon approach involves the results of 96 optimizations during the day. The data for the first PTU is used for control and is shown in the graphs. The difference can be readily understood. The rolling horizon optimization results in smaller energy exports during times of intense PV generation. This is because the system suggests storing the excess of energy to meet local demand in time slots receding into the future with each optimization run.

The results presented in Fig. 7 refer to the day characterized by a massive energy production from solar panels. The optimized energy profiles yield peaks of energy injection around midday when PV generation is high. This is because no constraints were imposed on possible energy flows. The system solely focuses on minimizing the energy bill. Although the results indicate that rolling horizon optimization can reduce peaks to some extent, it is not the goal of the community at this step. The issue of dealing with possible grid overload is addressed later as part of congestion management.

The optimal behavior of the community is characterized by shifting consumption of flexible devices to time intervals with electricity available from solar panels. This is because this electricity is cheaper relative to those taken from the main grid. Figure 8 shows the energy use of the heat pumps and the district battery after optimization.

Heat pumps are flexible devices at home level. They are used to provide heat for both domestic hot water and space heating. As expected, the MAS suggests using heat pumps in times with available renewable energy. This is shown in Fig. 8a that depicts a three-dimensional bar chart with the consumption profiles of each heat pump in the community. It can be seen that most of consumption occurs in times of high PV generation. Consumption in other time intervals is dictated by the need to satisfy temperature limits, especially for domestic hot water. The consumption of domestic hot water is irregular with respect to time and amount, especially in the evening.

At the district level, there is a battery storage. When multiagent optimization runs in a rolling horizon mode, at the end of the day, the battery SOC is not at its lower state because it holds some energy to account for the following time horizon. This is shown in Fig. 8b. Figure 8c graphically illustrates the control actions for the battery during the day in terms of the amount of energy charged and discharged in each PTU.

Fig. 8.
figure 8

Energy profiles of (a) heat pumps, (b) and (c) the district battery as result of the rolling horizon optimization, adapted from [4].

5.4 Comparing Building and Community Optimizations

Community management should ensure its members benefit from collective energy usage. To provide insights about the advantages of community-based approach we compared the results of in-home and community optimizations [4]. The former optimized community households individually and combined their energy profiles. The latter performed the community optimization. The results indicate the performance of two approaches varies depending on the amount of renewable energy that is locally produced. Community-based approach is better when there is excess of renewable energy. On the other hand, both approaches perform similarly when it is low.

Fig. 9.
figure 9

Comparing individual in-home and community optimizations, adapted from [4].

Figure 9 illustrates the amount of imported energy for the two optimization approaches. It can be seen that for all days community optimization yields less or equal energy import relative to in-home optimization. The two approaches perform similarly only when PV generation is low. The increase in renewable energy generation leads to the decrease in the amount of energy imported from the grid. During the period under consideration, the total renewable energy production was 9047.91 kWh. Similarly to the above daily data, the total energy import and export of the community was reduced.

We also use self-consumption as an indicator for performance comparison. Self-consumption is defined as the ratio between the amount of renewable energy consumed and produced in the community. The results indicate that the community-based optimization approach increases self-consumption. Instead of exporting the produced renewable energy outside the community it is used to meet local demand. These results provide important insights about advantages of collective energy management and the estimates of potential savings. It is also worth noting that economic benefits are accompanied by reduced stress on the main grid.

5.5 Addressing Flexibility Request

When it comes to congestion management, there are two possible scenarios. The first refers to the situation with the excess of injected renewable energy and low local demand. This can readily occur in sunny weather and lead to the increase in voltage that can damage the grid components if proper actions are not taken.

Fig. 10.
figure 10

Community energy profiles under congestion management scenarios due to overproduction, adapted from [4].

Figure 10 shows a day ahead scenario for the community addressing the oversupply of renewable energy. The energy profiles resulting from unconstrained community optimization are shown in blue. The results obtained when addressing the flexibility requests are shown in yellow. Two different requests limiting the energy injection are considered, which correspond to the maximum energy injection of 5 kWh and 3 kWh per PTU. It can be seen that both the grid capacity limits are respected by the MAS. The amount of renewable energy injected into the main grid does not exceed the limits requested. This is achieved by shifting the export from peak sunny periods during the day to evening and night hours. This reduces the stress on the distribution grid and provides energy in times of high demand, such as evening hours.

The availability of the storage capacity in the community is critical to exhibit this behavior. The battery enables storing the excess of renewable energy in peak times and later releasing it to meet local demand and for export. Figure 11 shows the behavior of the district battery storage in terms of charging and discharging of energy. The figure illustrates the more grid capacity is limited, the more energy is taken in peak times. It can also be observed that the battery does not take more energy than needed for meeting the flexibility request, which in turn minimizes the losses associated with charging and discharging.

The second scenario aims at avoiding the overload of grid components due to excessive pulling of energy. This situation is common in times when the local production is limited and the consumption is high. Figure 12 shows the results of addressing the flexibility requests to limit consumption to 4 kWh and 3 kWh per PTU. The given day is characterized by the low production from PV panels and the peak in demand around 16:00. The request is addressed by exploiting flexibility from the district battery and heat pumps, as shown in Figure 13. The battery stores the energy imported in off-peak hours and discharges to meet the peak demand. The consumption of heat pumps is shifted closer to midday.

5.6 Ensuring Flexibility Delivery

In the following, we investigate the effectiveness of the mechanism introduced in (17) to deal with the differences between day-ahead commitments and the real-time operation. The differences are expected due to unforeseen changes in behavior of grid users and forecast inaccuracies. We consider the start of the day and the obligation to deliver the profile show in Fig. 10a. This profile results from the negotiation between the DSO and the aggregator and represents the commitment to deliver and consume certain amount of energy at each time interval during the day.

Fig. 11.
figure 11

District battery profiles when handling overproduction.

Fig. 12.
figure 12

Community energy profiles under congestion management scenarios due to overconsumption, adapted from [4].

Fig. 13.
figure 13

Energy profiles of the district battery and heat pumps when handling overconsumption.

Fig. 14.
figure 14

Effects of change in PV production during congestion management.

Fig. 15.
figure 15

SOC of district battery with deviations of PV production in congestion management with a target profile.

First we examine the effects of both the increase and decrease in energy production from rooftop panels up to 20% relative to the forecast values. Figures 14a and 14b show the updated and the target energy profile of the community. When the production is lower than it was expected, the community cannot inject the amount of energy agreed. In terms of injected energy, the actual profile deviates from the target starting from around 8:00 to 24:00. The target and actual profiles also differ before 8:00 when there is no production at all. This is because the quadratic term in (17) penalizes deviations from the target profile in a way so that these are distributed along different time intervals starting from the begging of the time horizon until the actual mismatch happens. On the other hand, when the production is higher than what was expected, the community is able to deliver the target profile. In this case, the excess of energy is injected into batteries. Figure 15 show graphs depicting the state of charge of the district buttery for these two scenarios. The differences between the planned and actual SOC demonstrate a way in which the multiagent system makes use of available flexibility to meet obligations of the energy community.

Fig. 16.
figure 16

Effects of increased consumption on congestion management with a target profile.

We also study how the increase in consumption affects the ability to deliver the agreed energy profile. Figure 16 depicts the results for the cases of increased energy consumption in both morning and evening. In the former case, the community fails to meet the target only in morning hours while meeting the target during the rest of the day, as shown in Fig. 16a. A different behavior is observed when the consumption is larger than forecast in evening (after 17:00), as shown in Fig. 16. In this case, small deviations from the target profile are experienced throughout the day. This results from optimizing the objective with the quadratic penalty term define in (17). The mismatch is distributed among all time intervals starting from the begging until the last interval with the difference between forecast and actual values. The behaviour is similar to the above discussed case of increased production.

6 Conclusions

This paper presented the multiagent system developed for intelligent and autonomous functioning of the local energy community. The energy grid considering electricity and heat is modelled as the network of computational agents. These agents collaboratively solve energy flow problems and use the solutions to control consumption of flexible loads.

The obtained results showed the ability of the system to reduce the energy costs and to ensure the grid stability while satisfying the needs of the grid users. The optimized energy consumption profiles are meaningful, that is: (i) the energy consumption of flexible loads is scheduled in times when renewable energy is available; and (ii) the export of energy is scheduled so that local demand is met first and only the remaining excess is fed into the main grid. The optimization finds solutions satisfying all the constraints whenever feasible solutions exist. The constraints refer to each time unit and involve allowed levels of batteries’ charge, temperature limits, energy flow and energy balance in each node of the network.

The presented study considered the real-world community of households located in a close neighborhood. As observed in [4], these households have similar characteristics in terms of available flexible loads as well as energy consumption and production patterns. All households experience energy surplus and high local demand in same times during the day. Under such circumstances, the energy exchange at the community level is limited and the energy sharing mechanism is not fully appreciated. Although the presence of district battery alleviates this issue, it’s operation is costly as it is leased. The community would benefit from joining households without solar panels that are pure consumers. On the one hand, such consumer households would enjoy low prices for locally produced renewable energy. On the other hand, producer households would benefit from selling the energy to neighbors as the corresponding price is higher compared to the one for exporting to the main grid.

As future work, we intend to incorporate uncertainties into optimization as a way to account for forecast inaccuracies and to consider how costs and profits can be fairly distribute between community members.