Peer-to-peer energy sharing through a two-stage aggregated battery control in a community Microgrid

A R T I C L E I N F O


Introduction
With the ambitions of reducing carbon emissions and enhancing energy security and affordability, the integration of distributed generators (DGs) into electrical power systems is being widely promoted by countries across the globe. Many energy consumers are now becoming prosumers, i.e. both producers and consumers of electricity. They are motivated by financial and environmental concerns, as well as low levels of trust in large energy suppliers. This has led to local energy schemes such as residential-scale photovoltaic (PV) systems, community-owned small-scale wind farms, or Combined Heat and Power (CHP) plants and even to local authorities entering the supply market [1][2][3]. As a result, community energy systems play an important role in tackling the trilemma of challenges in the future energy systems.
Peer-to-peer (P2P) energy sharing is being considered as an effective method to manage the distributed energy resources (DERs) in community Microgrids, and provide regional market solutions. P2P energy sharing describes energy trade between prosumers, or between prosumers and consumers, where the excess electricity from prosumers is shared among neighbors [4][5][6]. P2P energy sharing is being becoming more attractive than the conventional peer-to-grid (P2G) trading.
Recently, there has been a significantly increasing number of research activities and demonstration projects carried out on P2P energy sharing over the world. The research on P2P energy sharing can be categorized by energy trade without and with an intermedia. Detailed review of the state-of-the-art of the research activities and demonstration projects are present as follows.
Strictly speaking, P2P energy sharing means energy trade without an intermedia. A local market platform is provided with necessary functions, in which all the prosumers trade or share energy with each other to maximize individual prosumers' benefits. In this framework, prosumers have full control of their own DERs, and DERs are supposed to be managed in a distributed manner.
Many studies worked on designing mechanisms for P2P energy sharing without an intermedia [7][8][9][10][11][12][13][14][15][16][17][18]. They are divided into three categories: auction model (e.g. [7,8]), multi-agent model (e.g. [9][10][11][12]), and analytical model (e.g. [13][14][15][16][17][18]). For example, an auction based local energy market was proposed in [7] to allow prosumers to trade their energy with each other in a grid-connected Microgrid. A learning mechanism based on 1-D recursive least squares was used to estimate the spot price and demand level for the energy bidding or offering in the auction platform. A multiagent-based game theory reverse auction model was used in [9]. A competitive local market was created in a grid-connected Microgrid, where the lumped load was supplied with the lowest price due to the competitive behaviour of the DER owners. An analytical model refers to pricing the electricity from DERs in a local market based on certain rules, calculation methods or game theoretic approaches. For example, a supply demand ratio (SDR) method was used to define the internal pricing in a Mircogrid in [13]. This allows prosumers to carry out an internal price-based demand response. A mid-market rate (MMR) based P2P energy sharing models was proposed in [14], but the flexibility in DERs were not considered. A discriminate pricing technique using game theory was adopted in [15]. This technique allowed participating energy users to decide their   energy use (consumption or supplying energy) based on the price per unit of energy. Fairness between energy users were optimized by using Pareto optimality. The game theoretic approach was also adopted for P2P energy sharing in [16][17][18]. All these works have one thing in common that is, these P2P sharing mechanisms do not need a central control system, but a local market operator is required to collect the bidding/offering information and provide the pricing signal to individuals in the community Microgrid. This required intensive computational power and communication infrastructures. Moreover, divergence problem exists in the bidding and pricing iterations. In [10], two techniques (i.e. step length control and learning process involvement, and a last-defence mechanism) were proposed to facilitate the convergence in determining the trading prices in the local energy market. Broadly speaking, P2P energy sharing does not necessarily mean prosumers directly control their DERs, and prosumers may get use of a third party entity (e.g. an aggregator, or an energy service company) to manage their resources.
Several works carried out P2P energy sharing via a third party entity [19][20][21]. Battery energy was shared between two groups of electric vehicles (EVs) that have different driving characteristics (divided by the journey distance, and daily re-charging habit) [19]. The EV aggregator, was used as a third party to define the P2P energy sharing price, and to schedule the EV discharging and charging. The paper concluded that the proposed P2P energy sharing took place in workplaces, and the number of EVs able to participate in P2P energy sharing was limited. In [20], a localized P2P electricity trading model was proposed for locally buying and selling electricity among hybrid EVs. Aggregators were used as the market operator. The social welfare was considered as the optimization objective function. However, the social welfare is an index for all the population, and using this index would be likely to result in inequality between customers, and some customers might be worse off comparing to the case when these customers did not participate in P2P energy sharing. To solve this problem, a Pareto optimality method was used in [21]. This work proposed an optimal P2P energy sharing model for smart homes, where a centralised control of all the appliances were carried out to minimize the energy cost of the community Microgrid as well as each individual customers. A cloud controller was considered as a third party entity. This method requires a central processing unit/ centre (i.e. a cloud infrastructure) to collect and process the information of all households, which is challenging in the power distribution network. Therefore, it was found that, when relying on a third party to conduct P2P energy sharing, it comes naturally for the third party to become the controller of the DERs as well as the market operator of the community Microgrid. There are two problems: (1) Control from a central point requires intensive communication infrastructure. (2) It is difficult to allow the third party to ensure each individual have economic gains and to encourage large numbers of customers to participate in the P2P energy sharing.
Electric utilities, industrial enterprises and high-tech start-up companies have conducted a number of trial projects on P2P energy sharing [22][23][24][25][26][27][28]. Blockchain based P2P sharing has been trailed in local communities, such as on President Street in Brooklyn, US [4,22,23], and National Lifestyle Villages in Perth, Australia [24,25]. These projects intended to demonstrate the effectiveness of blockchain technology. Online matching platform based P2P energy sharing enables consumers to buy energy directly from DER sellers. Hence, the sellers are able to receive payment at a higher rate than is typically received from electricity suppliers. The consumers may purchase energy from their nearby resources at a lower rate than is normally supplied by electricity suppliers. Trials of this type are available, such as Piclo in the UK [26], and Vandebron in the Netherlands [27]. P2P energy sharing with battery storage allows individual battery owners to store their surplus energy and sell to other community members later when these members do not have sufficient energy. For example, customers who joined the Son-nenCommunity [28] do not need a conventional electricity supplier, and they buy, sell, or swap excess electricity directly with each other. The rapid development of P2P energy sharing in practice highlights the importance of the research on relevant topics. However, most of the works did not emphasized on users/customers' point of view. To motivate prosumers to participate in P2P energy sharing, the economic benefit to each individual customer in the community should be investigated.
Therefore, the research gaps are summarized as follows.
(1) For P2P energy sharing without an intermedia, intensive sensing and communication infrastructures are required for information flows in a local market for the iterations between the price determination and control of the DERs, e.g. [7,9,13]. For P2P energy sharing with a third party entity, intensive sensing and communication infrastructures are required for building a central control system, e.g. [21]. Therefore, a control framework requiring a limited number of measurements and communications but able to realize P2P energy sharing is needed. (2) Many studies worked on pricing mechanisms for P2P energy sharing. However, most pricing mechanisms, such as the SDR mechanism in [13], the MMR mechanism in [14], and a social welfare based optimization model in [20], could not ensure every prosumer gain economic benefits. Therefore, an appropriate market mechanism is required to ensure each individual prosumer be better off when using the P2P energy sharing, compared to the P2G trading. This will encourage more and more prosumers to participate in P2P energy sharing. (3) Some previous works evaluated the benefit of P2P energy sharing, but they either carried out from the network operators (or the utility grid)'s point of view, e.g. [29,30], or from merely the community point of view, e.g. [19]. A thorough assessment method is required to analyze the benefit of P2P sharing to the community as well as to individual customers.
This paper proposed a two-stage aggregated control of many smallscale batteries in a community with many residential PV battery systems to carry out P2P energy sharing. This method allows individual prosumers to manage the control of their batteries via a third party entity. The third party entity acts as the controller of the DERs and the market operator. The main contributions of the paper are as follows: (1) A novel two-stage aggregated control framework was proposed to realize P2P energy sharing in low voltage distribution networks.
Comparing to the previous works of P2P energy sharing with a third party entity, this control framework requires for very limited measurements and a one-way communication, providing a feasible and practical solution to P2P energy sharing. Compared to the P2P energy sharing without an intermedia, there is no need of fast communication between the market operator and the individual DERs, because the pricing and billing are conducted 24 h after the actual electricity consumption, using the recorded import/export energy (e.g. half-hourly) data from smart meters. Also, there are no divergence issues. (2) An innovative P2P pricing mechanism was developed to ensure all customers in a community gain economic benefits, i.e. being better off compared to the conventional P2G trading. This pricing mechanism is modified from a previous SDR mechanism to include a compensating price. The modified pricing mechanism can be used as a benchmark applicable to any P2P energy sharing model. (3) A thorough assessment framework was established to evaluate the benefits of P2P energy sharing from a community point of view, as well as from individual customers' point of view. Therefore the comparison between P2P energy sharing and P2G energy trading in terms of the energy cost of the community and individual customers can be conducted.

Problem formulation
This section firstly presents the general idea of P2P energy sharing, including the P2P energy sharing structure and the responsibility of the players. This is then followed by the modelling of loads, PV systems and battery systems.

P2P energy sharing structure
With a peer-to-grid (P2G) energy trading, a PV battery system is managed from an individual customer's perspective, through maximizing the self-consumption of the customer's own generation. At the time when there is insufficient energy from the PV battery system, the prosumer buys energy from an electricity supplier, and when there is excess energy, the surplus is sold to the same supplier.
P2P energy sharing provides options for prosumers to trade energy within the neighborhood through local buying and selling, allowing local funds to remain within the local economy [31]. With P2P energy sharing, several customers in a community Microgrid share the connection to the main grid. The combined load is subject to random coincidence of the individual loads, which averages stochastic fluctuations [32,33]. This means that surplus PV power from a customer can be consumed by another customer with excess consumption. Fig. 1 shows the architecture of P2P energy sharing. In the P2P sharing community, there are N customers, NB of which have individual PV battery systems installed ( ⩽ NB N ). Although the PV outputs in a community are likely to be similar due to almost the same solar radiation, the net loads vary between prosumers, because of the differences in load, kWp of PV systems and battery statuses. Therefore, it is possible for the prosumers to share PV power with each other. The surplus PV power from prosumers can also be traded with consumers who do not have PV systems.
A third party entity named "energy sharing coordinator (ESC)" coordinates between customers and provides P2P sharing services, i.e. assuring the power balance and payment balance [13]. The ESC is the controller of the DERs as well as the local market operator. The ESC is located at the PCC (e.g. the low voltage substation). A smart meter is installed at the PCC, measuring the real-time net power consumption of the community, and this measurement is the input of the ESC. The ESC is communicated with the controllers of these small-scale batteries at the prosumer premises, and provides control signals to them via oneway communication. Through managing the battery charging/discharging, the ESC ensures the maximum use of local energy resources and the minimum amount of electricity fed back into the grid. Therefore the overall energy cost of the community is reduced, and the reduced cost is distributed to individual customers through a P2P pricing mechanism. The ESC also calculates energy bills of individual customers based on the P2P pricing mechanism, using the recorded import/ export energy (e.g. half-hourly) from smart meters at the premises. Details of the control framework and the pricing mechanism for the local market are presented in Section 3.
In practice, there are two types of PV battery systems: DC coupled and AC coupled. A DC coupled PV battery system consists of PV arrays, a battery, and a bi-directional converter. The PV panels and the battery are coupled through a DC circuit, and they are connected to the AC wires and load at the customer premises by a grid inverter (see prosumer 1 and prosumer NB in Fig. 2). An AC coupled PV battery system also consists of PV arrays, a battery and a bi-directional converter. The battery and the converter directly connect to the AC wire at the customer premises (see prosumer 2 in Fig. 2).
There are three types of players in the P2P sharing community, and they are the ESC, prosumers, and consumers. The responsibility of these players in the P2P sharing community are (1) Energy sharing coordinator (ESC) • Export power to (or import power from) the main grid to ensure the power balance of the community; • Contract with a supplier for the electricity trade at pre-defined exporting/importing prices and ensure the payment balance between the community and the supplier; • Control the charging/discharging activities of all batteries; • Contract with individual prosumers and consumers according to the P2P pricing mechanism and ensure the prosumers' income balance with the consumers' expenditure.
(2) Prosumers • Hand over the control of their batteries to the ESC; • Contract with the ESC, pay/repay their electricity bills according to the P2P pricing mechanism (The prices are calculated 24 h after the actual consumption according to the predefined pricing mechanism). (

3) Consumers
• Contract with the ESC, pay their electricity bill according to the P2P pricing mechanism (The prices are calculated 24 h after the actual consumption according to the predefined pricing mechanism.

Modelling of load and photovoltaic systems
The power consumption of the ith customer during the operation time period is defined as, where N is the total number of customers. T is the number of time slots over the operation time period.The PV generation of the PV battery system at the ith customer premises (these customers are also prosumers) is defined as where NB is the total number of prosumers ( ⩽ NB N ).For the ith prosumer, the net load at the time t is presented by

Modelling of battery systems
The battery at a premises is modelled by a simplified linear expression. Assuming that the charge and discharge power remain constant during a time slot, the stored energy of the battery is described by  ∆ is the length of each time step. The self-discharge of the battery was neglected, and hence σ SD t i , is taken as zero. The battery charging and discharging efficiencies are taken as constant values, neglecting the dependence of the efficiency on the charging or discharging power, the temperature and the battery age [34].
The status of the stored energy of a battery is defined as state of charge (SOC), and the SOC is where W BN i , is the nominal capacity of the battery (i.e. battery size), and the SOC is presented in percentage. In practice, the battery SOC is usually restricted within a certain range, and the charging and discharging power is constrained by the size of the inverter, as shown by where SOC min i and SOC max i are the minimum and maximum allowable SOC, and P BC max i , are the maximum charging and discharging power. In this work, lithium-ion batteries were considered. The SOC of individual batteries was restricted to a range between 20 and 80% of the nominal capacity [34]. The battery charging and discharging power normalized to the nominal capacity assumed to be 1 kW/ kWh.
From the perspective of the daily charging/discharging cycle of a battery, Fig. 3 illustrates the schematic of the behavior of a battery with the P2G energy trading and P2P energy sharing. Fig. 3(a) shows a daily charging cycle of a battery on a clear sky day with the conventional P2G energy trading. When the PV generation is higher than the load in the morning, the excess PV energy is used to charge the battery until the battery is fully charged. Then when the PV generation is lower than the load later in the evening, the battery discharges. It is shown in Fig. 3(b) that, for the P2P energy sharing, when the PV generation is higher than the load, the excess PV energy is firstly used to supply for the neighbors who have excess consumption, and the remaining PV power, if there is any, is used to charge the battery. In the evening, when the load is higher than the PV generation, some of the load is met by discharging his own battery, and the remaining load, if there is any, is met by the PV power or battery energy from his neighbors who have excess PV/battery power. From a single household's point of view, using the P2P energy sharing is able to reduce the amount of electricity sold to the grid as well as to reduce the amount of electricity bought from the grid. The excess PV energy is sold to his neighbors and the excess load is bought from his neighbors instead.

Methodology
The schematic overview of this work is firstly presented. This is followed by a detailed description of the two-stage aggregated control method, the use of the SDR method with a compensating price as the  Fig. 3. Schematic of daily charging and discharging behavior of a battery with PV generation on a clear sky day.
P2P pricing mechanism, and the performance metrics to be assessed. Fig. 4 shows the schematic overview of this work, which is divided into three blocks: two-stage aggregated control, P2P trading mechanism, and assessment with the performance metrics.

Assessment framework
Firstly, a two-stage aggregated battery control is carried out using the constrained non-linear programming (CNLP) optimization with a rolling horizon, and a rule based control. This is carried out by the ESC, and the control signal is provided to individual controllers at the prosumer premises. The purposes of the control is to minimize the amount of electricity fed back to the grid and minimize the energy cost of the P2P sharing community.
In the second block, the smart metering data at all the premises in the community are collected to calculate the aggregated supply and demand at different times of the day (for the previous 24 h). The dynamic supply and demand ratio is used to calculate the P2P trading prices using the SDR method. In practice, this is done 24 h after the actual electricity consumption, and therefore there are no iterations between the pricing and control activities.
Finally, the assessment of the P2P energy sharing is carried out. In the community level, the self-consumption and self-sufficiency rate of the community, and the energy cost are analyzed. In the individual customer level, the energy cost of each customer is calculated and a participating willingness index is introduced to evaluate the willingness of prosumers participating in P2P energy sharing. This in turn helps the ESC to adjust the compensating price, which is used to ensure all customers in the community gain economic benefit.

Two-stage aggregated battery control
In the P2P sharing community, a two-stage aggregated battery control was adopted. In the first stage, a CNLP optimization was conducted. This optimization was run in a rolling horizon (e.g. every 30 min) to allow for the update of the most recent historical load data and the control set-points. In the second stage, a rule based control was carried out adjusting the control set-point by using the real time measurement of the net load at the PCC. A bandwidth was given to the reference set-points obtained from the first stage to provide the upper and lower boundaries for the control in the second stage. Details of the two-stage aggregated control are presented as follows.

CNLP optimization with a rolling horizon
The load measured at the PCC and the actual control set-points (i.e. the actual schedule of battery charging and discharging) for the previous 24 h were used to forecast the demand and PV generation for the next 24 h. The optimization provides the control set-points for all the batteries in the community for the next 24 h. This is run in a rolling horizon, and therefore it provides continuous and updated control signal. The objective function for the optimization is the total energy cost of the community. Due to the fact that the power flow at the PCC is bidirectional, the electricity price should include the price of electricity bought from the grid and sold to the grid. Here, λ grid is used to represent the electricity price. The objective function and the constraints for the optimization in the first stage are presented by are the actual battery charging and discharging power at time t-24 h (taken from the ESC), and they are values from the second stage. Hence, ,2 4 is the sum of PV generation and demand for the previous 24 h (without the battery part). The sum of PV generation and demand for the future 24 h are considered unchanged, i.e. being the same as the previous day, based on which the schedule of the battery charging and discharging in the time window T is optimized. λ grid t , conforms the constraints that when the demand is higher than the generation in the community, λ grid t , is equal to the price of electricity bought from the grid (i.e.λ buy t , ); when the demand is lower than the generation, λ grid t , is equal to the selling price of electricity sold to the grid (i.e.λ sell t , ). x t i are the decision variables, and it represents the  , it means battery charging. The charging/discharging power is also constrained by the physical charging/discharging power of the inverters, as shown in Eqs. (5)(7). These constraints are presented as follows.
Considering prices of electricity bought from the grid and sold to the grid, the objective function can also be presented by To further simplify the objective function (10), removing the absolute value calculations, the objective function (10) can be transformed as The techniques used in [35] was used here to discard the absolute value calculation in the objective function in (10). Details are provided in [35].

Rule-based control
In the second stage, a rule-based control was conducted where the control set-point was adjusted according to the real-time measurement of the net load at the PCC. A rule was taken that when the community has surplus energy, the prosumers share their responsibilities by charging their batteries in an amount which is in a linear relation to the size (i.e. nominal capacity) of their batteries. Vice versa, when the community consumes electricity, the prosumers share their responsibility by discharging their batteries in an amount which is linear to the size of their batteries.
By taking the shared responsibility, the battery charging/discharging power normalized to the nominal capacity of each battery was assumed to be the same. Therefore, the ESC provides each individual battery controller with the same control signal. This means that all batteries are approximately at the same SOC. In practice, some batteries reach the maximum or minimum SOC earlier than others, due to differences in the aging conditions of batteries and inverters. However, this does not affect the control strategy as the control signal depends on the real time measurement at the PCC.
The battery controller only receives control signals from the ESC, disregarding the prosumer's own net load. For example, a battery can be discharging whilst the prosumer has surplus PV generation. This is because the energy is required and consumed by his neighbors.
The control logic for the rule based control is that the net load (i.e.
) at the PCC is measured in real time, and when the community's total PV generation is higher than the total load (i.e. ), and the SOC is lower than the maximum allowable SOC (i.e. SOC max ), the surplus generation charges all the batteries, and as soon as their SOC reaches SOC max , the surplus generation feeds into the grid. When the community's total PV generation is smaller than the total load (i.e. ∑ > = NP 0 i N t i 1 ), and the SOC is higher than minimum allowable SOC (i.e. SOC min ), the residual load is supplied by discharging all the batteries, and when their SOC reduces to SOC min , the residual load is supplied by the grid. The charging/discharging power is constrained by the physical charging/discharging power of the inverters. Moreover, the resulted control set-point from the rule based control has a boundary (upper and lower) which is taken from the results of the optimization in the first stage. Fig. 5 shows the block diagram of the rule based control and the links between the two stages of the control algorithm. The measurement at PCC is considered as the real-time input for the rule based control. The optimal scheduling of the battery charging and discharging power obtained from stage 1 is the constraints for the rule based control (i.e. considered as the constraints 1 as shown in Fig. 5). The physical charging/discharging power constrains referring to Eqs. (5)(7) are the fix constraints for the rule base control (i.e. considered as the constraints 2 as shown in Fig. 5).
Detailed control logic when the batteries are at charging/discharging conditions are shown as follows.
The control set-point has to be within the upper and lower limits of the boundary, and this is presented by where P ∆ BW is the bandwidth for the battery charging set-point. Usually P ∆ BW can be taken as a percentage of the P BC max i , , such as 50%. The use of bandwidth is to control the battery charging/discharging to constrain/follow the set-point obtained from the optimization, where the planning operation in a longer time span is considered.
The control set-point has to be within the upper and lower limits of the boundary, and this is presented by where P ∆ BW is the bandwidth for the battery discharging set-point. P ∆ BW can also be taken as a percentage of the P BD max i , , such as 50%.

P2P trading mechanism
Given the fact that in economics the relation between price and SDR is inverse-proportional, reference [13] formulated a P2P pricing model based on the supply and demand ratio. Here, the SDR method is also used. The total selling power is from the PV battery systems, which is equal to the remaining PV power after carrying out the charging or discharging activities, and the total buying power is the customer demand. Thus, the SDR at a community Microgrid at time t is defined as, The P2P buying and selling prices are fluctuated over different times of the day, and the price set is presented by Pr  Pr  Pr  Pr Pr  Pr  Pr  Pr  {  ,  ,,  ,,  ;  ,  ,,  ,,  }   buy  buy  buy  t  buy  T  sell  sell  sell  t  sell  T  12 12 (18) where Pr buy t is the P2P buying price at time t, and Pr sell t is the P2P selling price at time t. The P2P buying price (Pr buy t ) should not be higher than the price of electricity bought from the grid (λ buy t , ) and the P2P selling price (Pr sell t ) should not be lower than the price of electricity sold to the grid (λ sell t , ). Therefore, the P2P selling and buying prices are defined as a function of the SDR. They are shown as there is no selling power in the community, and all the required energy is bought from the main grid. The P2P selling and buying prices are both equal to the price of electricity bought from the grid (i.e. == PrP rλ sell t buy t buy t , ). When = SDR 1 t , the selling power is equal to the buying power in the community, and no power is required to import from (or export to) the main grid. The P2P selling and buying prices are both equal to the price of electricity sold to the grid with a compensation (i.e. ). Here, λ is a compensating price ( ⩽⩽ − λλ λ 0 buy t sell t ,, ), and it is used to compensate the prosumers to ensure the prosumers be better off when they participate in P2P energy sharing. When <〈 〉 SDR orSDR 0 1, 1 tt , the P2P selling and buying prices would dynamically change according to Eqs. (19) and (20). The relation of the P2P buying/selling prices and the SDR is graphically shown in Fig. 6.
The reason for introducing the compensating price is that, when there is no compensating price (i.e. = λ 0), both P2P selling and buying prices are equal to the price of electricity sold to grid when the SDR is more than 1. This will undermine the prosumers' income, but provide economic benefits to the consumers (i.e. these who do not have PV battery systems). It might happen that the prosumers receive lower incomes than the case of not participating in P2P energy sharing.

Assessment metrics
In a community level, the self-consumption, self-sufficiency and energy costs were taken as the assessment criteria. In an individual customer level, the energy bill of each customer, and the P2P participating willingness index were taken the assessment metrics.

Self-consumption
The community's self-consumption is defined as the ratio between the PV energy which is used by the community (including the electric loads and energy used for charging batteries) and the overall PV generation [39,40].
With P2G energy trading, the community's self-consumption is calculated by where E M i is the PV energy that is used by the electric load at the ith prosumer premises (see Fig. 7). E BC i is the PV energy that is used for charging the battery at the ith prosumer premises. E PV i is the PV production at the ith prosumer premises.For an individual PV battery system, either the load or PV output limits the part of the PV power that is used by the load. This is expressed as where P Mt i , is the PV power that is consumed by the load at the ith prosumer premises. Therefore, E M i is calculated by The PV energy that is used for charging the battery at the ith prosumer premises, E BC i , is calculated by With P2P energy sharing, the energy use of the entire community is aggregated. The community's self-consumption, s agg , is calculated by where E Magg is the PV energy that is used by all the electric load in the community. E aggBC is the PV energy that is used to charge the batteries in the community. Either the total load or the total generation limits the part of PV power that is used by the community. This is expressed as where P Magg t , is the PV power that is consumed within the community. Therefore, E Magg is calculated by The PV energy that is used to charge the batteries in the community is calculated by

Self-Sufficiency
Self-sufficiency of a community describes the share of load that is supplied by the PV battery systems. This includes the load supplied by the PV systems and the energy discharged from batteries.
With P2G energy trading, the community's self-sufficiency is calculated by  (29) where E L i is the electric load at the ith prosumer premises. E BD i is the amount of energy discharged from the battery at the ith prosumer premises, and E BD i is calculated by With P2P energy sharing, the community's self-sufficiency, d agg ,i s calculated by where E aggBD is the amount of energy discharged from the batteries in the community, and E aggBD is calculated by

Cost of community energy
The cost of community energy for P2G trading is calculated by where λ buy t , is the price of electricity bought from the grid, and λ sell t , is the price of electricity that sold to the grid. P im t i , is the power imported from the grid and P ex t i , is the power exported to the grid. They are obtained from smart meters that are installed at individual premises.
The cost of community energy for P2P energy sharing is calculated by where P aggim t i , is the power imported from the grid at the PCC, and P aggex t i , is the power exported to the grid. They are obtained from the smart meter that is installed at the PCC.

Energy bills of individual customers
The cost of energy for individual premises with P2G trading is calculated by where B P P i 2 is the energy bill for customer i under P2P energy sharing. Pr t is the P2P trading price, and the value of the Pr t depends on the role (i.e. consumer or producer) the customer is playing at time t. Therefore, Pr t is calculated by

Participation willingness index
The participation willingness index measures the percentage of the prosumers who obtain economic benefits after participating in P2P energy sharing, compared to the P2G energy trading.
Besides the overall energy cost of the community as evaluated by Eq. (32), the benefits of each prosumer counts as well. If the energy cost of a prosumer under the P2P energy sharing mechanism is higher than that with P2G energy trading, the prosumer will have the motivation to exit the P2P energy sharing and seek to trade with the supplier directly. In this case, it is difficult for the mechanism to keep the population of the participants. Therefore, the participation willingness is measured by the proportion of the prosumers who have lower energy cost under P2P energy sharing compared to that under P2G energy trading. The   (38) where N lower cost represents the number of prosumers who have lower energy cost under P2P energy sharing than that under P2G energy trading, NB PP 2 is the total number of prosumers participating in P2P energy sharing. For the consumers, as the P2P buying price (Pr buy t ) is never higher than the price of electricity bought from the grid (λ buy t , ), the energy bill of consumers will be always lower when participating in P2P energy sharing than under the P2G energy trading. Hence, there is no need to evaluate the participation willingness of consumers.

Case study
Two case studies were carried out considering residential customers and their daily load and PV profiles. In case 1, a community with 3 customers was used to illustrate the charging/discharging process of the batteries. In case 2, P2P energy sharing was demonstrated on a community with 100 households, considering various seasons, battery sizes and control cycles. The formulated CNLP optimization was solved by an interior point algorithm using the MATLAB tool box. The relevant computation experiments were performed on a desktop machine, Intel (R) Core (TM) i7-4790 CPU @ 3.6 GHz, 16 GB RAM and MATLAB version R2014a. Comparisons between the P2P energy sharing and the conventional P2G energy trading were carried out considering the assessment metrics analyzed in Section 3.4.

Load and photovoltaic profiles
The tool developed by the Centre for Renewable Energy Systems Technology (CREST) [36] was used to model the domestic load profiles at a time-granularity of 1 min. The load of an individual household was modelled considering type of day (week day or weekend), seasonality, occupancy and the associated use of electric appliances [36]. The number of occupants per household followed UK statistics [37], i.e. the percentage of houses with 1, 2, 3 and more than 4 persons are 28, 35, 16 and 21%. Once the number of occupants in a household was determined, the individual daily load profiles were created. For the PV systems, the same day was adopted and the corresponding generation was modelled also using the CREST tool. Due to the relatively small area of a community Microgrid, all PV systems were considered to have the same generation profile. The nominal capacity of the PV systems was randomly selected from a range of 2 to 4 kWp.

Case 1: Illustration of battery charging and discharging
For illustration purposes, a community with 3 customers was used, and the 3 customers were all equipped with individual PV battery systems (i.e. == N NB 3). The load and PV profiles were randomly selected from the profile pool. Fig. 8(a) shows the SOC, and the charging and discharging of the 3 batteries with P2G energy trading. For customers 1 and 2, their batteries were fully discharged in the evening and the SOCs at 24:00 were 20%. For customer 3, the battery was not fully discharged at 24:00, but used during the next morning. For simplicity, it was assumed that the remaining energy was used in the early morning of the same day. At time t1 (10:00) the battery at customer 1 was discharging, whilst the battery at customer 2 was fully charged, and customer 2 was feeding PV power to the grid. Similarly, at time t2 (around 12:30) and t3 (16:00), the battery of customer 2 was discharging, but the PV power at customers 1 and 3 was feeding into the grid. Potentially, the PV power that was fed into the grid was able to be used by neighbours. Fig. 8(b) shows the SOC, the charging and discharging of the batteries for the same day but with P2P energy sharing using the two-stage aggregated control. The battery control signal was determined by the net load of the community using the rule based control, taking the upper and lower boundaries from the optimization carried out in the first stage. It is seen that the 3 batteries had the same SOC profile, and the power supply from the grid and power fed-into the grid was reduced.  Table 1 shows the seasonal and annual performance under P2G energy trading and P2P energy sharing. with varying battery sizes: from 0 to 16 kWh (with 4 kWh increment). Here, the results for the P2G energy trading are considered as the base case for the comparison purposes. Both the charging and discharging efficiencies were 90%. The price of the energy bought from the grid was taken as 15 pence/kWh and the price at which energy is sold to the grid was 5/per kWh [38]   throughout the day. The annual average is calculated by adopting a weight of 25% for summer, 25% for winter, and 50% for spring/autumn. It is observed that, P2P energy sharing resulted in an increase of the annual average self-consumption by 10-30%, and an increase of selfsufficiency by approximately 20%, both compared to conventional P2G energy trading. Self-consumption in winter is slightly higher than that in summer, spring and autumn. Self-sufficiency in winter is significantly lower than that in summer, spring and autumn. With P2G trading, the average annual energy cost is 456.4-558.9 £/household. With P2P energy sharing this is reduced to between 301.5 and 409.6 £/household, equivalent to a ∼30% reduction in the energy cost of the community.

Performance with various control cycles
Given that there will be communication delays/losses in the process of the aggregated battery control, different control cycles were considered. A control cycle is defined as the time needed to collect the measurement data at the PCC, determine a control signal and send the control signal to the individual controllers. For P2G energy trading, no communication is required, hence only a 1-min control cycle was considered. For P2P energy sharing, control cycles of 1-min, 5-min, and 15-min were considered.
It is seen in Fig. 10(a) that for P2P energy sharing, the shorter the control cycle, the higher the community's self-consumption. This is because a short control cycle allows an efficient use of the surplus PV power to charge the batteries, thus resulting in increased self-consumption. It is shown in Fig. 10(b) that, the longer the control cycle, the higher the community's self-sufficiency. This is because a longer control cycle allows the controller to collect data from a longer time window and gain a better knowledge of the average demand and generation, thus the charging/discharging decisions result in more demand being supplied by the PV battery systems. For the energy cost of the community, it was found that the shorter the control cycle, the lower the energy cost (see Fig. 10(c)).

Performance with various numbers of customers participating in P2P sharing
In practice, there might only be a fraction of customers in a community participating in P2P sharing, whilst the other customers use P2G trading. A sensitivity study was carried out considering different numbers of customers participating in P2P sharing. This number was varied from 0 to 100 (with an increment of 20). The number "0" means all the customers are doing P2G energy trading, and this is the base case for comparison purposes; the number "100" means all the customers are participating in P2P energy sharing. The battery size was varied from 0 to 16 kWh (with 4 kWh increment). Heat maps with contour lines in Fig. 11 present the performance metrics. Fig. 11(a) shows that increasing the number of customers participating in P2P sharing has a similar impact on raising the community's self-consumption as increasing the battery size. When all customers use P2G trading, i.e. "0" on the x-axis, 80% self-consumption requires all prosumers to install 10 kWh batteries. The required battery size is reduced with more customers participating in P2P sharing. When 100% customers participate in P2P sharing, 80% self-consumption only requires all prosumers to install ∼3 kWh battery systems. Fig. 11(b) shows that the more customers participating in P2P sharing and the bigger the battery size, the higher the community's self-  sufficiency. When all customers use P2G energy trading, 30% self-sufficiency requires all prosumers to install ∼12 kWh battery systems. When 100% customers participate in P2P sharing, 30% self-sufficiency only requires each prosumer to install a less than 1 kWh battery system. Fig. 11(c) shows that the more customers participating in P2P sharing and the bigger the battery size, the smaller the community's average annual energy cost. When all customers use P2G energy trading, the average annual energy cost is £400/household with all prosumers installing ∼12 kWh battery systems. When 100% customers participate in P2P sharing, all prosumers installing less than 2 kWh will also result in the annual energy cost of £400/household. P2P energy sharing has a similar impact on raising the community's self-consumption, self-sufficiency, and reducing energy cost, as batteries, but at significantly less capital cost than the batteries. Taking the Tesla Powerwall 2 battery as an example, the equipment and installation cost of one 14 kWh Powerwall 2 battery system is currently ∼£6900 (∼£500/kWh). The Powerwall 2 has a 10 year warranty. If the Powerwall 2 battery is cycled once per day, and works for 10 years, the simple annual cost is £690. The cost of the 40 battery systems in the community is then £27,600/year. With P2G energy trading, 14 kWh batteries saved £10,234/year for the community (see Table 1), compared to the case without batteries. Hence, for the current market price of batteries, it is not worth buying a battery, unless the price of the battery system reduces dramatically to £182/kWh. With P2P energy sharing, 14 kWh batteries saved £25,735/year (see Table 1), but the equipment and installation costs of (one-way) communications are required. It is assumed that the average cost of communications is £400 per battery controller unit, and the annual cost of all communications is £1600/year. Hence, for the current market price of batteries, with P2P energy sharing, it is still not worth buying a battery, but it only requires to reduce the price of the battery system to £430/kWh (only 14% lower than the current market price).

Energy bills of individual customers
This work also evaluated the energy bills of individual customers and the P2P participation willingness with varying compensation prices, as shown in Fig. 12. This evaluation is carried out with various penetration levels of PV battery systems (from 20 to 100%), i.e. the percentage of prosumers ( × 100% NB N ) varies from 20 to 100%. It is found that with a higher compensating price, it is ensured 100% of the participation willingness, i.e. every prosumer is better off when participating in P2P energy sharing compared to the P2G energy trading. When the compensating price is zero, at all the penetration levels of PV battery systems, some prosumers are paying more electricity bills or gaining lower incomes when participating in P2P energy sharing. This is because the economic benefits were obtained by the consumers, whilst for some of the prosumers, it may not be worth participating in P2P energy sharing. It is also interesting to notice that to ensure a 100% participation willingness, the lowest compensating prices were 4, 3.5, 6, 8.5 and 7.5 pence, respectively, for 20, 40, 60, 80 and 100% penetration of PV battery systems. This means that for a community with a medium penetration level (e.g. 40%) of PV battery system, a lower compensating price is required to ensure all prosumers are better off when participating in P2P energy sharing. Therefore, the penetration level of the PV battery systems in a community and the compensating prices managed by the ESC are the main factors to impact the participating willingness for P2P energy sharing, and they should be considered by prosumers and energy service companies when they initialize for P2P energy sharing.
For a 40% penetration of PV battery system in community Microgrid, a compensating price of 4 pence was taken. The annual electricity bill of each individual customer is shown in Fig. 13. The first 40 customers are prosumers, and the remaining customers are consumers. For the prosumers, a positive value means the amount of electricity bill the prosumer is required to pay, and a negative value means the amount of income the prosumer receives. It is found that for all the 100 customers, the dashed blue line is always below the solid red line, i.e. it means it is cheaper to pay or higher to be repaid when the customers participate in P2P energy sharing compared to the conventional P2G energy trading (the base case). For consumers, the electricity bills are reduced by 3.7-33% (with an average of 12.4%), and for prosumers, the annual income is increased by (or the annual electricity bill is reduced by) £17 to £182 per premises (with an average of £57 per premises).

Discussions
It was shown from the case study that P2P energy sharing is able to bring significant economic benefits to the community as well as to individual customers. Also, with the revised SDR pricing mechanism, every customer benefits from the P2P energy sharing. There are also limitations for the work carried out, and these are considered as the future research to be undertaken.
The case study did not demonstrate the advantage of using the proposed two-stage control compared to that of using solely one-stage control. Also, for solving the CNLP optimization problem, this work did not compared the interior point algorithm used with other optimization approaches, such as evolutionary algorithms like genetic algorithm (GA), particle swarm optimization (PSO), etc. This is due to that this work mainly focuses on formulating the problem to realize P2P energy sharing where the requirements for sensing and communications can be significantly reduced. Investigating to what extent one optimization algorithm is more effective than another is out of the scope of this paper. However, considering the complexity of the optimization, evolutionary algorithms could be used to achieve a global optimum. Using evolutionary algorithms to achieve the global optimum for P2P energy sharing is considered as one of the future works to be undertaken.
Dynamic pricing at the main grid may result in the batteries charging when the retail price of electricity is low, and discharging when the retail price is high. In this case, the proposed two-stage control would result in an optimal scheduling of the battery charging/discharging according to the retail price. In this work, for simplicity and the purposes of demonstrating the benefits of P2P energy sharing, flat rates of grid buying and selling prices were taken in the case study. Hence, the energy used to charge the batteries completely came from the PV systems. However, the proposed method and formulations are also applicable to scenarios with dynamic pricing at the main grid.
Power flow analysis was not considered in this work. The demand and generation data of the households in Fig. 8 were used for the study, but the topology of the network and the impedance of branches were not considered. Further research works will be undertaken considering the distribution network data with power flow analysis and the network constraints.
The unfairness of economic gains may exist, i.e. there are differences in bill savings (or repayments) among consumers (or prosumers). This is due to the differences in the generation and demand coincidence with the community's availability of generation at different times of the day. For example, consumers who use more electricity at generation peaks would save more. Therefore, further economic gain might be possible when the prosumers and consumers are able to control their flexible demand at the premises. It is worth carrying out further research works on the rescheduling of the flexible demands to facilitate P2P energy sharing in community Microgrids.

Conclusions
This paper proposed a two-stage control method to realize P2P energy sharing in community Microgrids. This method significantly reduced the requirement for sensing and communication infrastructures when implementing P2P energy sharing in power distribution networks, and is able to bring significant economic benefits to the community as well as to individual P2P participants.
With an appropriate setting of the compensating price, the modified supply demand ratio based mechanism ensures every individual customer in the community be better off compared to the conventional P2G energy trading, i.e. every individual prosumer and consumer gain economic benefits. This pricing mechanism can be used as a benchmark applicable to any P2P energy sharing model. The proposed assessment framework is able to analyse the benefits of P2P energy sharing from a community's as well as individual customers' point of view.
By comparing with the conventional P2G energy trading, this work highlights the benefits of P2P energy sharing, P2P energy sharing in the case study results in (1) a reduction of energy cost of a community by 30%; (2) an increase in the self-consumption of the PV energy by 10-30%; (3) an increase in the self-sufficiency by ∼20%; (4) a reduction in the electricity bill of individual consumers by ∼12.4%, and (5) an increase of the annual incomes of individual prosumers by £57 per premises.
Note it is worth emphasizing that P2P energy sharing has a similar impact on raising the community's self-consumption, self-sufficiency and reducing energy cost as batteries, but at significantly less capital cost than the batteries. P2P energy sharing provides a great potential for profitable applications in the near future.
This paper demonstrates the benefits of integrating P2P energy sharing in local power distribution networks from the technical perspectives. However, a series of reforms on the current energy policy, laws and energy trading systems are still required before it becomes a reality. The flexibility in DER with characterized prosumer preferences, the new technology for trustworthiness of different institutional and business arrangements for P2P energy sharing, the regulatory change, and the confliction between the economic performance and the social satisfaction are the avenues for future research in this area.