*Article* **Local Energy Market-Consumer Digital Twin Coordination for Optimal Energy Price Discovery under Thermal Comfort Constraints**

**Nikos Andriopoulos 1,\*, Konstantinos Plakas <sup>1</sup> , Christos Mountzouris <sup>1</sup> , John Gialelis <sup>1</sup> , Alexios Birbas <sup>1</sup> , Stylianos Karatzas <sup>2</sup> and Alex Papalexopoulos <sup>3</sup>**


**Abstract:** The upward trend of adopting Distributed Energy Resources (DER) reshapes the energy landscape and supports the transition towards a sustainable, carbon-free electricity system. The integration of Internet of Things (IoT) in Demand Response (DR) enables the transformation of energy flexibility, originated by electricity consumers/prosumers, into a valuable DER asset, thus placing them at the center of the electricity market. In this paper, it is shown how Local Energy Markets (LEM) act as a catalyst by providing a digital platform where the prosumers' energy needs and offerings can be efficiently settled locally while minimizing the grid interaction. This paper showcases that the IoT technology, which enables control and coordination of numerous devices, further unleashes the flexibility potential of the distribution grid, offered as an energy service both to the LEM participants as well as the external grid. This is achieved by orchestrating the IoT devices through a Consumer Digital Twin (CDT), which facilitates the optimal adjustment of this flexibility according to the consumers' thermal comfort level constraints and preferences. An integrated LEM-CDT platform is introduced, which comprises an optimal energy scheduler, accounts for the Renewable Energy System (RES) uncertainty, errors in load forecasting, Day-Ahead Market (DAM) feed in/out the tariff, and a fair price settling mechanism while considering user preferences. The results prove that IoT-enabled consumers' participation in the energy markets through LEM is flexible, cost-efficient, and adaptive to the consumers' comfort level while promoting both energy transition goals and social welfare. In particular, the paper showcases that the proposed algorithm increases the profits of LEM participants, lowers the corresponding operating costs, addresses efficiently the stochasticity of both energy demand and generation, and requires minimal computational resources.

**Keywords:** local energy markets; consumer digital twin; transactive energy; thermal comfort; DER

## **1. Introduction**

In recent years, technological advancements and policy directives in the European Union (EU) [1] and the United States of America [2] have led to a significant increase in the number of Distributed Energy Resources (DER) that are primarily connected to the energy grid [3]. Therefore, the traditional energy consumers have been transformed into prosumers, i.e., active entities of the energy market that simultaneously consume, produce and share energy, depending on the regulatory framework, the weather and the operating conditions [4]. Prosumers may own multiple energy assets, primarily small-scale DERs for energy generation, and batteries or Electric Vehicles (EVs) for energy storage [5]. These trends reshape the conventional and centralized power system and eventually disrupt

**Citation:** Andriopoulos, N.; Plakas, K.; Mountzouris, C.; Gialelis, J.; Birbas, A.; Karatzas, S.; Papalexopoulos, A Local Energy Market-Consumer Digital Twin Coordination for Optimal Energy Price Discovery under Thermal Comfort Constraints. *Appl. Sci.* **2023**, *13*, 1798. https://doi.org/10.3390/ app13031798

Academic Editor: Chun Sing Lai

Received: 30 December 2022 Revised: 26 January 2023 Accepted: 28 January 2023 Published: 30 January 2023

**Copyright:** © 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

the existing energy system. In this emerging landscape, the power system must undergo structural changes to adapt and leverage the benefits of Internet of Things (IoT) technologies, digitalization, and decarbonization policies.

The edge grid is a structural component of the power system; thus, the concepts of Transactive Energy System (TES) and Local Energy Market (LEM) are considered novel solutions that enable energy exchange between prosumers, increase the power system's efficiency, and reliability, and support the coordination between DERs [6]. Financial and engineering advancements are embraced by TES and LEM, and they form an integral part of the hierarchical energy marketplace, which includes wholesale, retail, and local markets. Inevitably, the solutions of TES and LEM offer incentives for participation for all stakeholders and maximize the social welfare in the energy market.

The exponential growth of computational power and IoT has created a strong technological infrastructure for collecting, transmitting, and processing data in a reliable, efficient, and cost-effective manner. In this context, the concept of Digital Twin (DT), i.e., virtual representations of physical entities that encompass the most discriminative characteristics of the corresponding entity, has attracted the attention of researchers and the industry. Bidirectional and automatic data flow between the physical and virtual entities are used by DTs to produce predictive analytics, perform actions and support informed decisions. In the power sector, DTs are considered promising solutions for sustainability, demand side management, control of energy assets, reliable energy distribution and monitoring of energy grid operations [7].

As flexibility can be obtained either at the residential or community level, this work focuses on residential flexibility, which is then procured to the external grid through LEM. Controlling Heating, Ventilation and Air Conditioning (HVAC) systems based on consumers' thermal comfort tolerance, scheduling household appliances and EV charging are the typical ways to obtain residential flexibility. Based on the consumer's preferences, designated flexible loads are activated at optimal intervals during the desired time window to minimize energy costs. Moreover, by allowing the consumer to specify the subjective intensity of importance for each flexible load, prioritized Demand Response (DR) scheduling can be implemented.

As residential flexibility is becoming critical for power systems and is now at the forefront of the energy market, LEMs are acting as a catalyst in procuring residential flexibility and empowering small RES owners [8]. LEMs simplify and accelerate this process, enabling energy consumers at the edge of the grid to evolve from passive entities to active integral energy market actors. Despite the fact that LEMs expedite consumers' participation in the energy market, prosumers' involvement will not be materialized as long as their market engagement is conducted in a complicated way, limiting the interest on LEM and leading to potential depreciation and eventually failure. Apparently, a seamless and consumer-friendly way of market engagement is a decisive factor for LEM's success. To this end, the Consumer Digital Twin (CDT) serves as a powerful information tool that provides automated data streams on consumers' key characteristics and personalized preferences to minimize their active involvement in operations, increase the efficiency of operations and enhance the consumer-centricity of the LEM.

In this work, a LEM-CDT structure is introduced in order to bridge the gap between local flexibility potential and the consumers' preferences. Towards this end, the benefits of both concepts are leveraged. On one hand, the local flexibility is procured efficiently to the wholesale energy markets while guaranteeing monetary and social benefits for LEM's participants and at the same time the preferences of LEM members are not only respected but also, and most importantly, incorporated in the optimal LEM scheduling. By combining these concepts, the aim is to harness optimally the local flexibility capacity at the distribution grid and attract more participants at LEM initiatives in order to create local sustainable energy communities. To achieve this, CDT is an essential tool since it provides the necessary information to the LEM operator in order to consider the particularities and preferences of each participant placing them at the center of the electricity market. This usercentric approach is one of the main novelties of this paper, offering an efficient solution for LEM operators to model their energy scheduling accurately and attract more participants.

The envisaged LEM–CDT structure is shown in Figure 1. Flexibility stems from the prosumers' side, either in the form of production from various DERs or through DR actions. As shown, prosumers are at the center of the energy market, contributing to the energy mix with any means they own, such as DERs, EVs, or even via DR schema. Supplying flexibility has both technical advantages (e.g., quick response time) and widens the pool of potential LEM members; thus, consumers who do not own DER assets can also be members and contribute to the overall supply through their load flexibility. In addition, participation via DR schema promotes democratization within the community, as all members contribute to the aggregation generation and benefit from their participation. The stochasticity of both energy demand and generation is taken into account to ensure a constant, reliable, and cost-effective energy supply, thereby mitigating the cost of remedial action.

**Figure 1.** The consumer-centric structure of LEM

This paper is divided into five sections: In Section 2, a comprehensive literature review for both LEMs and CDTs is provided. In Section 3, the proposed solution for the integration of CDT and LEM is presented. In Section 4, the results from experiments are displayed revealing the benefits of integrating CDT into LEM. Finally, in Section 5, the conclusions of the work are provided.

#### **2. State of the Art**

#### *2.1. Local Energy Market*

Recent research by Honarmand et al. [9] and Doumen et al. [10] emphasized the emergence of the LEM as a solution that prioritizes consumers in integrating DERs into distribution networks effectively. The LEM approach allows the efficient management of DERs, thereby increasing their utilization and overall impact on the distribution grid. LEMs facilitate prosumers' unfettered access to the electricity market, leading to increased flexibility in the grid and creating revenue streams for small-scale prosumers while supporting balancing, congestion management, and ancillary services [11]. An LEM comprises small-scale energy deployments and energy assets located in a small or a wide geographic area. They are connected to the distribution grid in a decentralized structure where participants cooperate with the available resources (DERs, DR, EVs) on a community level, as depicted in Figure 2. LEM's main objective is to encourage market participation by providing monetary incentives to prosumers to trade energy with one another with minimum or no intermediate (e.g., energy aggregators) [12]. In this market, prosumers can share the benefits of local flexibility within the community, promoting the deployment of distributed renewable generation and DR [13]. To promote prosumers' participation, the LEM achieves load balancing at a lower price compared to the external grid. Consumers (buyers) can reduce energy costs by buying energy at a lower price. In comparison, producers (sellers) can increase their profit by offering energy at a higher price compared to the external grid. Moreover, from a social perspective, it allows participants to be active members of their communities by supporting and enabling them to consume renewable energy and benefit from its distributed generation.

**Figure 2.** The future decentralized electricity system.

The pricing mechanisms of an LEM constitute one of its most important elements; many algorithms for the LEM clearing price have been proposed. Specifically, Tushar et al. [14] investigated the feasibility of social cooperation among prosumers participating in a peerto-peer (P2P) energy trading market by utilizing a canonical coalition game approach. The results indicated that the proposed scheme can increase the prosumers' willingness to participate in P2P energy trading schemes. Lee et al. [15] proposed a direct electricity trading market, in which the electricity pricing scheme achieves a fair allocation of profits between consumers and small-scale energy suppliers by using the asymptotic Shapley value function. Tsaousoglou et al. [16] presented a TES where an auction mechanism is implemented with non-convex prosumer models and resource constraints. Long et al. [17] presented three examples of a P2P market structure, namely bill sharing, mid-market rate, and auction-based pricing, to validate the effectiveness of the proposed markets. These market structures were applied on a residential community microgrid with a PV system. Mengelkamp et al. [18] proposed a blockchain-based microgrid energy market without central coordination and evaluated the 'Brooklyn Microgrid Project' as a case study. Finally, Paudel et al. [19] introduced a game-theoretic approach for P2P energy trading among prosumers, where consumers can adjust their consumption according to market conditions.

Since LEMs are not fully restricted in electricity production, Brolin et al. [20] presented a corresponding multi-energy structure that utilizes its full flexibility potential, while Hayes et al. [21] facilitated the efficient flexibility procurement by an aggregator. In the proposed platform, an aggregator can communicate directly with the participants and determine costs and rewards between them so the benefits for both the aggregator and the electrical systems are mutually increased. Lyu et al. [22] proposed a comprehensive energy-sharing framework for smart buildings considering multiple dynamic components covering heating, ventilation, air conditioning, battery energy storage systems, and EVs. Bachoumis et al. [23] investigated the provided ancillary services to the external grid and particularly the fast frequency response service. Finally, Huo et al. [24] considered the uncertainty of PV production by employing the chance-constraints optimization method for the operation of an energy hub.

The current LEMs lack consumer-centrism, failing to take into account the individual preferences of participants. This proposal aims to address this knowledge gap by designing a consumer-centric LEM that respects the priorities of LEM participants, as expressed through personalized preferences for the flexible residential loads and the individual's indoor thermal comfort level. By prioritizing the preferences of consumers, the proposed LEM will increase the effectiveness of DERs integration in distribution networks, providing more efficient and cost-effective energy solutions for the participants.

## *2.2. Consumer Digital Twin*

In electricity markets, DTs are promising solutions for sustainability, control of energy assets, demand-side management, control of energy assets, reliable energy distribution, and monitoring of energy grid operations [25]. Danilczyk et al. [26] proposed a DT to address security issues and detect potential failures in a microgrid, such as instabilities and failures in power distribution, in a timely manner. Darbali-Zamora et al. [27] introduced a real-time DT that optimizes DER operations for distribution voltage regulation and increases the awareness of power system dynamics. Podvalny et al. [28] proposed a scalable and evolutionary DT framework to simulate the behavior of a power system under critical events by employing a neural network as a decision support infrastructure. Wu et al. [29] introduced a DT of grid batteries to diagnose faults in time and control their usage to extend their lifetime, while Jain et al. [30] proposed a virtual replica of solar PVs to promptly detect operational faults and evaluate their power generation performance. Atalay et al. [31] proposed a DT that performs simulations over the virtual copy of the physical grid to detect possible power supply interruptions. Dembski et al. [32] introduced an urban DT representing a real community to enable the execution of scenarios over the virtual twin and provide customized energy services to prosumers. Bazmohammadi et al. [33] mentioned the enhancement of microgrid operations through DTs. Nguyen-Huu et al. [34] and Han et al. [35] utilized DTs as an orchestration mechanism to coordinate the operation of LEM and DER, respectively. Aghazadeh Ardebili et al. [36] used DTs as a tool to predict energy production in power systems with a high volume of RES. Zhou et al. [37] highlighted the benefits of DTs for providing flexibility in industrial power systems.

In the energy sector, the employment of DTs has gained significant attention as a means to optimize the management of DERs. However, while DTs have proven to be versatile tools in representing and simulating physical entities, their application to human entities remains a challenge. The complexity of human behavior, influenced by factors such as mental activities, ethics, and social interactions, makes it difficult to model human behavior deterministically [38]. As a result, human DTs tend to only include key attributes and selected characteristics to represent the corresponding human entity from a specific socioeconomic perspective. Despite this limitation, the development of human-oriented DTs holds potential for further advancements in the energy sector, particularly in the areas of demand response and local energy markets.

The proposed CDT is a human-oriented, simplified virtual replica that represents the entity of an electricity consumer within the context of an energy market. It incorporates the most informative and distinguishing characteristics, attributes, and behaviors of its physical counterpart, while ensuring synchronous and bidirectional data flow between the physical and virtual entities. To achieve this, raw data from both physical sources (smart meters and wearable devices) and digital sources (REST API services) are collected and processed to extract knowledge and facilitate informed decision-making.

The functionalities performed by the CDT include developing dynamic constructs of prosumer energy behaviors, while also identifying consumer preferences with respect to energy usage, thermal comfort tolerance and openness to engaging in flexibility and DR actions, and the assessment of prosumer's indoor thermal comfort level according to the ASHRAE-55 standard [39] using environmental and physiological parameters captured by a wrist-worn device. Thermal comfort expresses the personal thermal satisfaction associated with indoor thermal environmental conditions and adheres to an ideal thermal condition and the appropriate tolerance limits within which the consumer feels comfortable. Continuous and automatic consumer thermal comfort assessment in conjunction with consumer preferences is critical since it enables pertinent and optimal demand side management while preserving the desirable thermal tolerance limits making the consumer predictable energy-wise.

By utilizing time series of predicted weather data, CDT produces forecasts of the consumer's energy demand and projected energy production from owned RES, which are further optimized based on the user's preferences. With this in mind, the proposed CDT is a core element that facilitates the deployment of human-centric DR optimization strategies, it enables personalized and non-intrusive control functions of energy assets without compromising the consumer's desired thermal comfort tolerance, and it provides consumer flexibility to aggregators. Additionally, it ensures the improvement of short and mid-term demand forecasting by using real data streams from the consumer's energy assets to address the stochasticity of the distribution grid and minimize DR strategy overruns.

The CDT consists of a front-end, a back-end, and a database intending to act as a web-based tool that records and processes the user's preferences to produce priority vectors through multi-criteria decision analysis, and user's environmental and physiological parameters through ML methods to assess indoor thermal comfort. Additionally, CDT completes analytics and enables interoperability to cater to aggregator platforms with critical flexibility information in real-time.

The overall contribution of this paper can be summarized as follows:


#### **3. Framework Implementation**

In this section, the CDT and LEM-implemented models are described and their integration is presented. The main goal of the proposed framework is to integrate the benefits of CDT into the LEM architecture. This will enable every member of an LEM to be an active prosumer and empower its position in the energy market through the LEM. In that context, CDT offers the opportunity of seamless participation in the local market and at the same time the incorporation of consumers' preferences into the market outcome.

#### *3.1. Consumer Digital Twin*

Consumer preferences constitute a set of decision criteria that reflect the consumer's prioritized demand response potential within an LEM. As such, the consumer defines the subjective intensity of importance for each residential flexible load, i.e., HVAC system, heat pump, EV charger, battery storage unit, dishwasher, and washing machine, and the desired operation time window of each load, to generate a priority vector as input to the LEM. Additionally, the boundaries of the consumer's thermal comfort tolerance are defined, adhering to Fanger's 7-point thermal sensation scale [40], as depicted in Figure 3. In this scale, each state of thermal sensation corresponds to a numerical value between −3 and +3, where −3 and +3 denote the cold and hot thermal states, respectively, and 0 denotes the neutral state.

The hierarchical ordering of consumer preferences needs to be arranged through a formal methodological approach. Therefore, the Analytical Hierarchy Process (AHP), which is a decision-making framework that allocates weights to a set of N decision criteria and produces a priority vector imposing pairwise comparisons between them, is employed. A 9-pointed balanced importance scale is utilized, in which the consumer defines whether a criterion is superior or inferior to the compared one in terms of verbal appreciation. More specifically, the scale's values come under the discrete set of ∆<sup>1</sup> = {1, 3, 5, 7, 9} and indicate equal, moderate, strong, very strong, and extreme importance, respectively, whereas intermediate values of the discrete set ∆<sup>2</sup> = {2, 4, 6, 8} are omitted as they represent a compromise between the compared criteria. To a superior criterion, the corresponding numerical value of the verbal response is assigned as priority value *aij*, while the reciprocal *a* −1 *ij* one is assigned to the inferior one. The priority values are allocated to a squared decision matrix *AN*×*<sup>N</sup>* to derive the normalized priority vector for the set of decision criteria (preferences). To evaluate whether the obtained weights from the AHP method are plausible, the consistency ratio metric (CR) is applied to the normalized priority vector. This metric employs the random consistency index, whose value results from a predefined set of constant values with respect to the number of decision criteria. The results of the method are considered sufficiently consistent and acceptable if the CR index is less than 0.1. If this condition is not met, the stakeholder should revise the intensity of importance for each pairwise comparison, and the process of the method is iterated.

CDT provides two matrices as input to LEM; the load flexibility matrix, denoted by **LF** , whose elements represent the relative importance of each flexible load as determined by the AHP method along with the operating time window of each flexible load as defined by the consumer, and the thermal flexibility matrix, denoted by **TF**, whose elements include the consumer's current thermal comfort level and thermal comfort tolerance deviation.

The **LF** matrix allocates to each row the weight of the corresponding flexible load and the operating time window intervals, respectively, so that the first column vector *l f***:,1** of **LF** matrix represents the priority vector determined by the AHP method. For instance, the vector *l fn***,:** = [0.2, 2, 7] represents a weight of 0.2 assigned to the corresponding load and a desired load's operating time window between 2:00 a.m. and 7:00 a.m., whereas the vector *l f***:,1** = [0.2, 0.1, 0.1, 0.3, 0.1, 0.2] indicates weights of 0.2, 0.1, 0.1, 0.3, 0.1, 0.2 to the HVAC system, the heat pump, the EV charger, the battery storage unit, the dishwasher and the washing machine, respectively. At the same time, CDT provides data streams with the consumer's current thermal comfort level and the thermal comfort tolerance deviation from the desired range in 15-min intervals. For instance, the **TF** = [−1.1, +0.9, +2.1] represents a consumer with thermal comfort tolerance desired range from −2 (cool) to +1 (slightly warm) and a current thermal comfort level of −1.1.

To insert and update the subjective intensity of importance for each residential flexible load, as well as the desired load's operation time window and thermal comfort tolerance boundaries, CDT offers a user-friendly graphical interface. This interface allows consumers to determine their thermal comfort tolerance over the thermal comfort scale, as presented in Figure 3 and the intensity of importance for each load through pairwise comparisons and the desired operation's time window intervals over a 9-pointed importance scale, as presented in Figure 4.

**Figure 3.** The implemented thermal comfort scale.


**Figure 4.** The implemented 9-pointed importance scales.

#### *3.2. Local Energy Market*

The LEM is a digital platform that facilitates transactions between a number of energy actors, i.e., consumers and prosumers, at a local level. A community, comprising at least two participants engaging in energy trading, can be characterized as LEM. The LEM optimizes the Day-Ahead (DA) scheduling to minimize its operating costs. The price at which the transaction is cleared within LEM can be determined using different approaches. In this section, two applied pricing algorithms are presented and compared along with the market design.

#### 3.2.1. Market Design

LEM allows small-scale DER owners to actively engage in energy trading among themselves and to participate in the wholesale and retail energy markets. The fundamental feature of the LEM is the lower market clearing price compared to the external grid, which provides an incentive for prosumers and consumers to participate in such a cooperative market mechanism. Another important feature of the proposed LEM market is the clear definition of the market architecture and the pricing rules. It is evident that the rules of the design should be disseminated and explained in detail to the LEM participants so that each participant knows in advance the operation of the market. In our case, a two-sided market is considered, meaning that several buyers hold items for sale and several buyers consider buying these items. The key concept in such a market is that every participant (either buyer or seller) has a different valuation and risk profile of the held items, products and services. An efficient market maximizes the total profit obtained both from the buyers' and sellers' sides. To achieve an efficient local market, the total profit must be maximized for both groups.

#### 3.2.2. Pricing Algorithms

For the validation of the proposed coordination scheme between CDT and LEM, the first step is the local price clearing at which the transactions take place in the market. Regarding the pricing algorithms, two different approaches are considered. In both algorithms, the price resolution is hourly, similar to the price signals of the external day-ahead market (DAM). Therefore, there is a different arbitrage (difference between LEM price and external price) for each particular hour. The two algorithms are summarized below:

• Peer-to-peer (P2P) pricing algorithm: The first approach is a direct P2P pricing mechanism. In a P2P transaction, the buyer and the seller transact directly with each other in terms of the delivery of the good or service and the exchange of payment. Specifically, after the initial submission of the bids from both sides, the order book of the pairs of transactions is created. Multiple price levels are initially created since different energy levels are offered at different prices. Prices are ranked for sellers from the lowest to the highest and vice versa for buyers. If the lowest price for consumers is lower than the highest price for sellers, the transaction can be executed. Otherwise, there is a case of supply deficit; in that case, the minimum of the supply-demand pair is cleared within the internal market and the rest is supplied by the grid. The clearing price *Plem* (the average value of the two prices) creates one universal price inside the LEM. A universal (same) price is desirable since it is easier to evaluate the efficiency of the market. The clearing price results from:

$$P\_{lcm} = \frac{P\_{prod\_{low}} + P\_{cons\_{high}}}{2} \tag{1}$$

• CDT-LEM pricing algorithm: In this work, the price is calculated based on the LEM's production and consumption values. In other words, the participants are not directly participating in the market in the form of bids. This pricing mechanism has three main advantages. First, it minimizes the participants' involvement so that the LEM is accessible to more potential members by lowering the entry barriers. Secondly, the elimination of a bidding process strengthens the resiliency of LEM against market manipulation concerns. Finally, the solution's applicability is straightforward since all the necessary data are directly taken from smart meters or IoT devices. The process of determining the clearing price is analyzed in more detail in the following section.

In both pricing algorithms, the internal market is cleared at a price lower than the selling price of the retail external grid and higher than the buying price of the external grid. The internal energy is practically exempt from transfer losses and any other monetary burdens (such as transfer may incur due to the transition of energy through a large-scale grid) and thus the internal price can be lower. The time horizon that transactions take place depends on the market design (Day-ahead market, Real-time market, etc.), while the granularity of the algorithm's solution is determined mainly by how often the system updates its information and control signals.

#### 3.2.3. LEM and CDT Integration

The potential impact of CDT on LEM services is significant due to the integration of consumers' energy flexibility information with supplementary parameters from thirdparty resources, such as the energy retailer's price. As shown in Figure 5, bidirectional and automatic data flows between the LEM and the CDT platform are enabled by the communication layer, so thus individual parameters that affect the consumer's energy flexibility potential are seamlessly elicited by CDT for each LEM participant, specifically, the participant's energy demand and production, the prioritized DR scheduling based on the participant's preferences and the participant's thermal comfort level. The LEM

platform refers to the energy market and the assets that locally generate electricity while CDT involves information regarding user comfort. The information exchange between the platforms aims at the maximization of users' benefits. To this end, CDT serves as a strong knowledge base for enhancing the efficiency of LEM operations and price discovery mechanism and optimizing energy management services.

**Figure 5.** Integration of LEM and CDT.

The information exchange between LEM and CDT is critical for the integration of the two platforms and provides the following benefits:


#### **4. Results and Validation**

#### *Use Case Description*

In this work, the CDT-LEM pricing is compared with P2P pricing [18]. The evaluation is conducted in terms of consumers' payment, prosumers' profit, and computational performance of both algorithms. To assess the applicability of LEM, both pricing algorithms are examined in a real-world test case: a residential community in central Germany. In particular, the total number of participants in the community is 27 residential members, 12 of them have installed PV systems on their rooftops, while the rest of them are solely energy consumers. The former group contributes to the LEM through their flexible loads, in our case their HVAC systems, via a DR scheme. This specific flexible load was chosen since it is the most energy-consuming appliance in households and, in our case, it is possible to control HVACs' operation through smart controllers. Moreover, the time period is a typical single day during summer, characterized by substantial PV production and high demand for HVAC load.

The pricing algorithm and the optimal scheduling are calculated on the LEM operator's cloud platform. Additional critical services, such as load and generation forecasting, interaction with the wholesale energy market, and integration of meteorological data, are also deployed in LEM's cloud. Regarding the CDT implementation, each participant is equipped with a wrist-worn wearable device, which assesses and transmits the thermal comfort level. In addition, energy preferences have been provided by the consumer and processed by CDT, as described in Section 3.1. Based on this information, participants are classified into three classes. To simulate the participation of the consumers, the different classes of flexibility capacity stemming from each participant are considered to follow the normal distribution. The classes are derived based on the values provided by the flexibility and thermal comfort matrices. The first class contains the non-flexible consumers whose load profile cannot be altered. The second class contains low-flexibility participants, while the third class contains fully flexible participants with no constraints of adjusting their load. In all three classes, the thermal comfort limits of each user are not violated. These classes are formulated as parameters in the optimization problem and determine the allowed shiftable demand of each participant. In that context, CDT extends the flexibility capabilities of LEM by creating a more stable and fair cooperative energy scheme, since even the members who do not own any energy production assets can contribute to the energy community. Accordingly, all participants contribute to LEM for mutual benefit. Finally, CDT offers a seamless way of performing load shifting based on participants' preferences. The main advantage of the CDT-LEM pricing algorithm is that active engagement of participants is not required. Consumers are encouraged to participate, as the price results are always within the range of feed-in and feed-out tariffs. The inputs of the algorithm are consumption and generation forecasts, along with feed-in and feed-out tariffs, and the output is the resulting LEM clearing price. The LEM price curve is a representation of the local generation and demand, and is made available to all participants. It is depicted as a three-dimensional surface, as illustrated in Figure 6. The curve is generated for each hour, although it can be created for any other desired time horizon.

On the contrary, in the case of P2P pricing, the price is calculated based on each participant's bidding strategy, which is prone to market manipulation, especially in the case of a single participant with significant market power (e.g., higher installed PV capacity). Hence, the adoption of the P2P algorithm requires a sufficient regulatory framework. Even so, both algorithms lead to lower energy costs, where consumers and prosumers interact with the external grid via feed-in and feed-out tariffs respectively.

LEM's main goal is to optimize the DA scheduling by minimizing its operating costs. Batteries' charging and discharging are among the decision variables of the optimization problem. The minimization of LEM's operating cost is calculated based on the forecasted values of local generation and local demand in a one-day horizon. The forecasting error, especially in low-scale energy deployments [41], leads to deviations in the output of the optimization problem. Hence, the DAM schedule differs from the optimal deterministic

solution, leading to remedial actions that bear down higher costs on LEM participants. Incorporating stochastic variables in the optimization problem is the key to ensuring a constant, reliable power supply and achieving a cost-efficient LEM operation.

**Figure 6.** LEM pricing curves with feed-out and feed-in tariffs as limits.

The stochasticity of DERs generation and local consumption affects the LEM scheduling [42]. It is crucial to design a market that effectively deals with stochasticity, as the cost for remedial actions will be significant in the case of high uncertainty levels [43]. A wide variety of stochastic optimization methods have been employed to cope with uncertainty in power systems operation, namely scenario-based approaches, robust optimization, and chance-constrained optimization [44]. The chance-constraints method allows certain unexpected events to violate specific constraints considering the overall constraint satisfaction is satisfied with a predefined level of probability. Chance constraints are transformed into deterministic equivalents, and a standard solution method is then employed to solve the problem. The uncertainty of DERs and demand is incorporated into the optimal scheduling process by using statistical moments of the parameters' distribution, which are derived from historical data such as mean and standard deviation [45]. The ability to accommodate a wide range of distributions eliminates the need for discretization of a probability space for scenario sampling [46] or the derivation of a finite uncertainty set [47].

In this work, a chance-constraints approach for the DA scheduling is employed, which explicitly incorporates the stochasticity of DERs generation and local demand and analyzes the effect of uncertainty level on LEM's social welfare. The rationale behind our choice was that compared to the other two stochastic optimization methods, the chanceconstrained leads to less conservative results [48]. Another important factor is that the level of uncertainty can be tuned via a confidence interval [49]. Finally, by incorporating the stochastic optimization problem into a chance constraints formulation, the convexity of the optimization problem is maintained. In this paper, stochasticity is accounted for on both the supply (i.e., solar PV) and demand sides. The granularity of the optimal scheduling of the LEM is equal to 1 h and has an interval horizon of 24 h, similar to the wholesale DAM

market architecture. The objective function of the optimization problem is formulated as follows:

$$\min \mathcal{C}\_{total} = \sum\_{i=1}^{24} \left( \pi\_{\text{int}}^{i} \times \mathbf{P}\_{\text{int}}^{i} + \pi\_{\text{buy}}^{i} \times \mathbf{P}\_{\text{in}}^{i} - \pi\_{\text{sell}}^{i} \times \mathbf{P}\_{\text{out}}^{i} \right) \tag{2}$$

where *i*, *l*, *k*, and *n* indicate the hour, flexible consumers, PV owners and battery owners, respectively. *C i total* denotes the total LEM cost, *π i int* is the LEM price, and *π i buy* and *π i sell* are the respective feed in and feed out grid tariffs. *P i in* and *P i out* denote power import and export from and to the grid.

Equations (3)–(6) outline the energy conservation laws and constitute the constraints of the optimization problem:

$$P\_{\rm int}^{i} = P\_{\rm gen}^{i} + P\_{\rm BBdis}^{i} - P\_{\rm load}^{i} + FI \times \mathbf{SC}\_{l,i}^{+} - FI \times \mathbf{SC}\_{l,i}^{-} - P\_{\rm BBch}^{i} \tag{3}$$

$$P\_{gen}^{i} = \sum\_{1}^{k} (P\_{\mathcal{S}^{en}}^{i,k}) \tag{4}$$

$$P\_{load}^{i} = \sum\_{1}^{l} (P\_{load}^{i,l}) \tag{5}$$

$$P\_{\rm int}^i = P\_{\rm gen}^i + P\_{\rm BBdis}^i - P\_{\rm load}^i + FI \times \mathcal{SC}\_{l,i}^+ - FI \times \mathcal{SC}\_{l,i}^- \tag{6}$$

where *F I* indicates the flexibility index derived from the flexibility matrix and thermal comfort matrix, *SC*<sup>+</sup> *l*,*i* and *SC*− *l*,*i* indicate the amount of power consumption for the specific *i*-hour, shifted by each household at each time-step and the amount of power consumption that has previously been shifted and is now consumed, respectively. Additionally, *P i gen* indicates the total LEM production, *P i BBdis* and *P i BBch* indicate the battery's discharging and power, respectively, and *P i load* indicates the LEM's load profile. The notations of *k*, *l* and *n* indicate the number of producers, consumers and storage owners, respectively:

$$0 \le P\_{\rm in}^i \le P\_{\rm in}^{\rm max} \tag{7}$$

$$0 \le P\_{out}^i \le P\_{out}^{max} \tag{8}$$

The allowed bounds of energy exchange between the LEM and the grid are defined by constraints (7) and (8):

$$e\_{BB}^{n,i} = e\_{BB}^{n,i-1} + \eta\_{ch}^{\text{n}} P\_{BB\text{ch}}^{\text{n},i} \times \Delta t - (1/\eta\_{dis}^{\text{n}}) \times P\_{BB\text{dis}}^{\text{n},i} \times \Delta t \tag{9}$$

$$0 \le P\_{BBch}^{\text{Il}, \dot{i}} \le P\_{BBch, \text{max}}^{\text{Il}} \tag{10}$$

$$0 \le P\_{BBdis}^{\eta, i} \le P\_{BBdis, \max}^{\eta} \tag{11}$$

$$0 \le e\_{BB}^{\eta, i} \le e\_{BB, \max}^{\eta} \tag{12}$$

$$e\_{BB}^{n,1} = e\_{BB}^{n,T} = (1/2)e\_{BB,\max}^{n} \tag{13}$$

Equations (9)–(13) denote the storage energy state update, in which *e n*,*i BB* denotes the battery's energy state and *η n ch* and *η n dis* show charging and discharging efficiency levels, respectively. Lastly, *P n BBch*,*max* and *P n BBdis*,*max* denote the maximum and minimum storage charging rate while *e n BB*,*max* and *SD<sup>t</sup>* define the maximum storage capacity and shifted demand, respectively,

$$FI \times \text{SC}\_{l,i}^{+} \le FI \times \text{SD}\_{l} + \text{SC}\_{l,i}^{-} \tag{14}$$

$$\text{SC}\_{l,i}^{-} = \text{SC}\_{k,i-1}^{+} \tag{15}$$

$$\mathcal{SC}\_{l,I}^{+} = \mathbf{0} \tag{16}$$

Demand can be shifted by one hour at a fixed rate determined for each tenant based on their preferences. Constraint (14) assures that the amount of the shifted demand does not exceed the maximum residential load, by restricting the amount of shifted demand to the residential load for the specific time step plus the shifted demand in the previous time step. Equation (15) guarantees that the already shifted demand is either consumed in the current time-step or shifted further. The shifted demand at the end of the time horizon for the optimization problem in Equation (16) should equal zero, ensuring that the demand will not be shifted to the next day's optimization problem:

$$\Pr\{P\_{gen}^{i} \le P\_{gen}^{i}\} \ge \mathfrak{a}' \tag{17}$$

$$\Pr\{P\_{gen}^{i} \ge \tilde{P}\_{gen}^{i}\} \le \mathcal{J} \tag{18}$$

$$
\alpha' + \beta' \le 1 \tag{19}
$$

Equations (17)–(19) denote the probability of the actual production to be in a specific range, where *P*˜*<sup>i</sup> gen* is equal to the forecasted generation value plus the forecast error *e<sup>i</sup>* . Finally, *α* 0 and *β* 0 denote the probabilities of upper and lower bounds, respectively.

The proposed method in [50] is applied in order to transform the probabilistic chance constraints into deterministic values that can be used as input to the optimization procedure.

The maximum PV forecasting error *e<sup>i</sup>* is considered equal to 20% following the normal distribution N(0, *σ* 2 ), with a 99.7% confidence interval achieved in [−3*σ*, +3*σ*] range. At time interval *i*, *σ* is equal to 0.1*P i Fgen*, which is the forecasted PV generation. Moreover, *ei* is constrained between maximum installed capacity *P max gen* and the forecasted value *P i Fgen*; therefore, the error distribution *e<sup>i</sup>* belongs within the range [−*P i Fgen*, *P max gen* − *P i FPV*]. The *e<sup>i</sup>* follows the conditional probability distribution given by:

$$\Phi\_i(\mathbf{x}) \sim N(0, 0.01(P\_{FPV}^i)^2) \tag{20}$$

where Φ*i*(*x*) is the conditional probability distribution:

$$\Phi\_i^{\prime}(\mathbf{x}) = \frac{\Phi\_i(\mathbf{x}) - \Phi\_i(-P\_{F\text{gen}}^i)}{\Phi\_i(P\_{\text{gen}}^{\max} - P\_{F\text{gen}}^i) - \Phi\_i(-P\_{F\text{gen}}^i)} \tag{21}$$

$$\Phi\_{i}^{-1'}(\mathbf{x}) = \Phi\_{i}^{-1}[\mathbf{x}\Phi\_{i}(P\_{\mathcal{gen}}^{\max} - P\_{\mathcal{F}\mathcal{gen}}^{i}) + (1 - \mathbf{x})\Phi\_{i}(-P\_{\mathcal{F}\mathcal{gen}}^{i})] \tag{22}$$

If (22) is solved and Φ −1 0 *i* (*x*) can be found, then (17) and (18) can be transformed into the following equation:

$$F\_{\mathcal{J}}^{-1}\{\tilde{P}\_{\mathcal{G}^{\mathrm{en}}}^{i}\} \le P\_{\mathcal{G}^{\mathrm{en}}}^{i} \le F\_{1-\mathcal{a}}^{-1}\{\tilde{P}\_{\mathcal{G}^{\mathrm{en}}}^{i}\} \tag{23}$$

where *F* <sup>−</sup>1{*P*˜*<sup>i</sup> gen*} is the inverse forecasted PV production distribution.

To address the stochastic nature of demand, a similar approach as the one described above for the generation is followed. Across the literature, there are two approaches for modeling load uncertainty as a way to ensure that demand will not be shifted with equality constraints containing stochastic parameters in the optimization problem. The first method converts the equality constraints into inequality ones, whereas the second method eliminates variables [51]. However, by following the second one, the final variable values will remain uncertain; this is because the aforementioned variables depend on stochastic parameters. In our case, those variables are the charging/discharging level of the batteries and the demand shift, while the parameter is the day-ahead load. Moreover, if the variables that will be eliminated contain stochastic parameters as coefficients, eliminating such variables leads to nonlinear optimization problems. On that account, this approach is not recommended because the eliminated variables (i.e., the charging/discharging level of the batteries and the demand shift) depend on the stochastic parameters, which is the day-ahead demand. Moreover, it is evident that the selection of variables determines the subsequent optimization problem. In other words, the choice of different eliminating variables leads to different optimization problems.

Based on the above, the first approach is followed and the equality constraints (4) and (5) are converted into inequality constraints (25) and (26), respectively:

$$k = P\_{gen}^{i} + P\_{BBdis}^{i} - P\_{load}^{i} - P\_{BBch}^{i} \tag{24}$$

$$k - d \le P\_{\text{int}}^i \le k + d \tag{25}$$

$$\sum\_{1}^{l} (P\_{load}^{i,l}) - d \le P\_{load}^{i} \le \sum\_{1}^{l} (P\_{load}^{i,l}) + d \tag{26}$$

where *d* is a small parameter to ensure that the above inequalities are tight at optimality.

#### **5. Results**

In Figure 7, the hourly prices for both pricing algorithms are presented. The price levels of both algorithms are within the bounds defined by the external grid (feed-in and feed-out tariffs); therefore, consumer participation in an LEM framework is beneficial under both pricing algorithms. In particular, the prices of our proposed algorithm are lower than those of the P2P approach during hours of high PV production. This is to be expected since, in the CDT-LEM pricing, no direct bids are submitted by the participants; the price behavior follows the pattern of residual load. Therefore, during time intervals with excess PV production, the community energy demand is lower and the prosumer is not adequately compensated. On the other hand, the prices of the proposed algorithm are significantly higher during the night hours of the day (7:00 p.m.–6:00 a.m.), as shown in Figure 7.

**Figure 7.** Hourly prices with the two (2) different pricing algorithms.

In Table 1, it is evident that, without an LEM, the procurement daily costs are significantly higher. Specifically, employing the proposed algorithm without CDT, the cost is reduced by 20.7%, while the cost reduction with CDT is 27.8%. It is noticeable that, while P2P pricing also leads to cost reduction, the percentage drop is smaller compared to the respective one from our proposed algorithm. This is due to the different way, in which the LEM operates; under the P2P algorithm, there is a higher trade of energy with

the external grid, while the proposed algorithm seeks to optimize the energy within the LEM framework.

**Table 1.** Total Daily Cost in Euros.


In Table 2, consumer payments are the lowest under the proposed method with CDT. The producers' profit is also the highest under the same schema since the traded energy is higher with the proposed algorithm than with the P2P approach, which leads to profit maximization.

**Table 2.** Total payment and profit in euros.


In Table 3, the results for both pricing algorithms are displayed, with and without the utilization of the CDT. The results focus on two time periods, between 2:00 a.m. and 8:00 p.m. and between 2:00 p.m. and 8:00 p.m. These time periods are selected because the pricing algorithms generate different state-of-charge values during these time periods. In particular, under P2P pricing, the excess energy (during midday) is sold to the external grid, leading the batteries to reach their lowest accepted levels (20% state of charge) regardless of the CDT. On the other hand, with CDT-LEM pricing, this energy is used to charge the batteries, which is why there are no abrupt peaks. This fact leads to a more "self-sufficient" LEM since the interaction with the external grid is lower than in the P2P case. In the CDT-LEM pricing mechanism, the LEM prioritizes the local energy needs and then the energy trading with the external grid via the wholesale markets. Apparently, our algorithm leads to battery charging when there is a higher local generation while the P2P algorithm sells the excess capacity to the wholesale market.

Figures 8 and 9 show how the probability of constraint violation affects the total operational LEM costs. As the probability decreases, the total expected cost increases due to the fact that the LEM operation becomes more "conservative" in order to respect the optimization constraints. Furthermore, the CDT-LEM pricing coupled with the CDT results in the lowest costs, regardless of the probability. Clearly, there is a trade-off between higher operating costs and low-risk scheduling, and the associated decision rests with the LEM operator and the specific pricing mechanism.

In Figure 10, the energy exchange levels with the external grid are presented. Positive values represent the sale of energy to the grid and negative values represent the purchase of energy from the grid. As mentioned earlier and shown in Figure 10, the energy exchange is actually higher in the P2P approach, while our algorithm leads to lower dependence on the external grid. This is due to the fact that LEM first resolves its local imbalances and then interacts with the external grid. The hourly intervals with the highest grid interactions are around midday since the production level within LEM is high during these hours leading to a large energy surplus.

Finally, in Table 4, the scalability and the computational performance of the two proposed algorithms are examined for an increasing number of LEM participants. Apparently, our proposed algorithm outperforms the P2P pricing, as it is multiple times faster, particularly as the number of participants increases. This is due to the fact that the P2P algorithm requires a computationally demanding matching algorithm between the energy supply offers and energy demand bids. This procedure is conducted through an optimization problem in order to achieve optimal matching. Hence, as the number of participants increases, the optimization problem is more complex with a higher computational burden. On the other hand, the CDT-LEM pricing computational needs are minimal, since it results from a heuristic process that requires only the generation/demand values and the external market tariffs.

**Figure 8.** Total cost vs. probability of generation stochasticity violation


**Table 3.** Batteries state of charge.


**Table 4.** Computational performance of the P2P and proposed algorithm.

**Figure 9.** Total cost vs. probability of demand stochasticity violation.

**Figure 10.** Energy exchange with the external grid.

#### *Visualization of Results through CDT*

In the proposed integration, CDT additionally serves as a visualization tool for consumers to track key indicators of their participation in LEM, as shown in Figure 11, promoting energy flexibility as a financial incentive. Specifically, a dashboard displays information on weekly energy production and demand with a daily resolution, financial profit from LEM participation, and specific parameters that affect thermal comfort.

**Figure 11.** Consumer digital twin dashboard.

#### **6. Conclusions**

This paper presents an integrated framework of LEM-CDT that maximizes the flexibility potential of the participants and improves the market's operations efficiency. A detailed market design with different pricing mechanisms for handling LEM transactions is also introduced. The results of the proposed framework are summarized as follows:


The proposed solution encounters challenges with regard to regulatory compliance and ensuring the confidentiality of participants' data. Despite a current dearth of clear guidelines for LEMs design and operations, efforts are being undertaken to rectify this. In order to establish trust and attract new members, LEMs must prioritize creating a reliable environment. Additionally, the integration of a large number of IoT devices accentuates the necessity for robust cybersecurity measures to safeguard against potential breaches.

The proposed model holds the potential for further enhancement in two directions. One area of improvement would be the integration of a more comprehensive collection of consumer preferences, with the aim of augmenting its consumer-centric orientation and further refining the consumer priorities for LEM operation. Another avenue for research would be to incorporate the distribution network constraints within LEM, in order to prevent voltage and line congestion incidents. Additionally, the proposed integration of LEM-CDT should be assessed in a larger-scale study utilizing a larger volume of data.

**Author Contributions:** Conceptualization, N.A., K.P., C.M. and J.G.; Methodology, N.A., K.P., C.M., J.G. and A.B.; Software, N.A. and C.M.; Validation, N.A., K.P., C.M. and J.G.; Writing—original draft preparation, N.A., K.P., C.M. and J.G.; Writing—review and editing, A.B., S.K. and A.P.; Visualization, N.A., K.P., C.M. and J.G.; Funding acquisition, J.G. and A.B. All authors have read and agreed to the published version of the manuscript.

**Funding:** This work has been supported by TwinERGY project, No 957736, "Intelligent Interconnection of Prosumers in Positive Energy Communities with Twins of Things for Digital Energy Markets-TwinERGY", H2020-LC-SC3-2020-EC-ES-SCCRIA.

**Institutional Review Board Statement:** Not applicable.

**Informed Consent Statement:** Not applicable.

**Data Availability Statement:** Not applicable.

**Conflicts of Interest:** The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.

#### **Abbreviations**

The following abbreviations are used in this manuscript:

