Web-based platform for the management of citizen energy communities and their members

The appearance of citizen energy communities demands the conception, development, and testing of new management models for the community and its end-users. Citizen energy communities promote the active participation of end-users, including them in the management of the community. End-users are incentivized to participate in demand response programs and share their energy among peers, enabling a decrease in their energy costs. In this paper, it is proposed a platform for the management of citizen energy communities. The paper focuses and presents four services related to energy tariffs, end-users’ aggregation, price elasticity, and load response. The services are based on historical data and enable deep analysis of end-users’ energy profiles. As the platform allows the upload of different scenarios, it is possible to test and validate management models in multiple energy communities and scenarios and study their impact in different conditions. The paper presents a case study, where all the services are applied to a community with 996 end-users.


Introduction
The implementation of smart grids is currently advancing at a significant speed, changing the interaction between energy utilities and end-users, and providing support for the integration of renewable energy sources and energy storage (Ourahou et al. 2020). The application of smart grids also enables energy transactions among end-users ) enabling end-users with generation (e.g., generated from solar panels) to sell their surplus energy either to neighbouring consumers or to the grid (Alladi et al. 2019). In smart grids, end-users can also have an active participation in the grid management, using demand response programs (Tang et al. 2019;Faria et al. 2015), and transactive energy (Good et al. 2019;Gomes et al. 2020).
The willingness of the end-users to actively participate in smart grids is increasing, as there exist more and more reasons to do so, particularly at the economic level (Feuerriegel and Neumann 2016). The citizen energy communities, foreseen in the Directive (EU) 2019/944 of the European Parliament and of the Council, of 5 June 2019, allow end-users to voluntarily participate in community programs (European Parliament 2019). Citizen energy communities can be managed using centralized or decentralized models, similar to microgrids (Abrishambaf et al. 2021).
In an energy community, multiple types of users exist and cooperate, each one with their energy consumption and generation profiles. The profiling of users can be done using multiple methods, as clustering (El Kontar and Rakha 2018) or classification (Piscitelli et al. 2019). The profiling of users allows the aggregation of users and provides an analysis of the user's consumption.
This paper proposes a platform to manage a citizen energy community, providing multiple services to manage the community and its end-users. In this paper, four services, that are fed by the end-users' historical data are proposed. The tariffs calculation and attribution service provides an analysis of the end-users' tariffs, for consumption and generation, and provides the best tariff available in the market. The aggregation service enables the aggregation of the end-users considering similar attributes. The price elasticity service calculates the end-users' elasticity considering the variation of energy prices and their impact on the end-users' energy demand. The load response service provides energy price variations to adjust the community's energy demand, considering the current balancing needs. This paper is divided into five main sections. After the introduction, the second section will explore and, briefly, provide a state of art regarding load response services, clustering, and platforms focused on the management of tariffs and energy communities. The third section presents the proposed energy communities' platform, its architecture, and the interaction between services. A case study, and its results, are presented in section four, while the main conclusions are described in section five.

Related work
This section will address related work regarding energy communities' management platforms, end-users' tariffs attribution models and platforms, demand response, and end-users' aggregation models.
In (van Leeuwen et al. 2020), it is proposed a platform that optimizes the energy flow in a microgrid, besides implementing a bilateral trading service. It makes use of blockchain technology to create a network and enables a distributed optimization using the Alternating Direction Method of Multipliers (ADMM). In (Ku et al. 2018), a big data platform for energy is proposed. It can forecast energy consumption and generation for the optimal use of the energy grid, making use of big data analysis to create a robust demand response method. A smart energy community management platform, capable of implementing peer-to-peer (P2P) trading and managing household energy storage systems, through fuzzy reinforcement learning, can be found in (Zhou et al. 2019).
Regarding tariffs management, in (Wu and Xia 2018), it is proposed a tariff-driven demand management of a ship with a hybrid renewable energy system. It helps to achieve an optimal solution in terms of power management. In (Fridgen et al. 2018), it is proposed an empirical analysis of electricity tariffs in microgrids, where tariffs are used to complete the study of technical challenges in distributed residential power generation and its consequences on the energy grid.
In energy communities, there are many options to perform local energy management with active participation of end-users (Chen and Liu 2017). An example is the use of demand response and load response programs. Demand response programs have been deeply explored in the last years, considering the greater capacity to use them in reallife problems (Wang et al. 2017). Thus, new methodologies have been suggested, with different goals, regarding the problem context.
The use of distributed blockchain mechanisms for delivering secure and reliable energy flexibility is proposed in (Pop et al. 2018). In (De Sá et al. 2013), it is suggested an optimization of time-of-use (ToU) tariffs design, based on quadratically constrained quadratic programming, using price elasticities of demand.
There is also the possibility to develop demand response programs to maximize the profits of energy retailers (Chai et al. 2021), control retail electricity markets (Alasseri et al. 2018), cope with power outage events (Tian and Talebizadehsardari 2021), like natural disasters, and, like the work proposed in this paper, for energy communities management (Huitema et al. 2020). There are a lot of different possible approaches to this technique, always considering the problem context and the willingness of the endusers to actively participate in the market (Pinto et al. 2016).
To participate in demand response programs, it is usually needed an aggregator entity that represents a group of end-users . For this reason, end-users should be aggregated, through a clustering algorithm, according to their similarities.
In unsupervised learning, clustering has the objective to separate a finite, unlabelled dataset into a finite number of groups, named "clusters", considering data similarities (Xu and Wunsch 2008). There are multiple types of cluster algorithms, each one with its pros and cons. The most recognized ones are hierarchical (agglomerative or divisive) and partitional (distance-based, model-based or density-based) (Saxena et al. 2017). Inside each one of the types, there are a lot of algorithms, such as k-Means, Density-Based Spatial Clustering of Applications with Noise (DBSCAN), Clustering Using Representatives (CURE), and Support Vector Machines (SVM) clustering.
In energy systems, clustering algorithms are normally used to deeply analyse endusers. Through clustering, it is possible to perform end-user aggregation (Iria and Soares 2019) for the active participation in demand response programs . In (Teichgraeber and Brandt 2019) multiple clustering methods, including K-Means, are studied in the problem of optimization of energy systems, through the finding of representative periods. It is also possible to study electricity use patterns, as proposed in (Nepal et al. 2021) and optimize energy systems design (Kotzur et al. 2018).
The evaluation of clustering algorithms is possible using methods that evaluate the optimal number of clusters (or neighbourhood, in density-based clustering), such as Elbow and Silhouette. Normally, the evaluation metrics are coefficients corresponding to intra-group homogeneity and inter-group heterogeneity.
The Elbow method considers the total Within cluster Sum of Square (WSS) as a function of the number of clusters suitable for the dataset (Asri et al. 2019). It enables the choice of the appropriate number of clusters in such a way that adding more clusters does not have any impact on the data analysis results (Aggarwal and Sharma 2019). The optimal number of clusters is achieved when the function curve draws an elbow since the function stabilizes.
The Silhouette Score (SS) is a measure that assesses the cohesion of the clusters (Choi et al. 2019). It calculates not only the similarity between one point and the rest of its group but also the dissimilarity between that same element and the points of the other groups. Thus, a value between − 1 and 1 is obtained, where 1 means that there is a high cohesion in the groups and − 1 reflects that there is no conformity between members of the same group (Lengyel and Botta-Dukát 2019).
Energy-targeted systems can have completely different approaches, and all of them valid in their conditions. From all the studied platforms, none of them combines tariffs analysis and management, end-users' aggregation, and a load response program, making the platform proposed in this paper stand out.

Proposed energy communities' platform
The developed energy communities' platform is web-based and allows the community's operator to analyse end-users' historical data and execute multiple services regarding the community's management. The platform is divided into four main services, as shown in Fig. 1. The arrows specify the normal procedure of the operator from the moment he starts using the platform until all services have been successfully executed. Besides that, the platform data flow is described, and each step is explained.
The proposed platform is not data-dependent, as it allows the input of an excel file with end-users' historical data, considering possible different scenarios. In this file, a line corresponds to a single end-user and a column represents a period. In every sheet of the file is specified a parameter (attribute). There are multiple types of parameters, as some require being studied by period (consumption, generation, etc.) and others just require a numerical or categorical value (contracted power, generation type, etc.).
Then, when a dataset is already imported, all the services are unlocked, and the platform can list all the available end-users and present their historical data, giving the community's operator the ability to change it manually. In Fig. 2 it is shown, in a) and b), respectively, a locked and unlocked menu, that represents its state before and after a dataset upload.
As it is possible to see, in Fig. 2, when there is not a dataset loaded in the platform, the services are unavailable, and as such they cannot be executed. The only task available besides the dataset upload, is the platform customization, where it is possible to Fig. 1 Platform architecture change the available parameters for the end-users (add, remove, change type), add or remove tabs and charts in the players analysis page, change chart types, and more.

Tariff calculation and attribution model
There are multiple energy providers with different energy tariffs, adapted to the distinct types of end-users. As the consumption and generation profile of an end-user can change, it may exist the necessity to change their energy tariffs, to ones adapted to their energy profiles.
The tariffs of end-users are individual, and not by community, meaning that multiple tariffs can be used in a single community. The tariffs calculation service provides an analysis of the available tariffs to each end-user, intending to find the most costeffective tariff for each one.
This service requires the input of a file with different consumption and generation tariffs, that can be applied to the end-users. Then, these tariffs will be analysed individually for each one of the end-users, calculating its total cost (in case of consumption tariffs) or profit (in case of generation tariffs), considering their consumption and generation historical data. In the case of the consumption tariffs, the objective is to minimize the cost, and relatively to the generation tariffs, the objective is to maximize the profit. In Eqs. (1) and (2) is described the tariff cost/profit calculation: where n is the number of periods available on the dataset, ct p is the consumption tariff price in period p, in EUR/kWh, gt p is the generation tariff price in period p, in EUR/ kWh, c p is consumption value in period p, in kWh, and g p is the generation value in period p, in kWh.
The most profitable tariff will be assigned to the end-user, and, after the execution of the service, the operator will have the ability to apply them to the end-users. The attribution can be made in two different ways: All tariffs: All the assigned tariffs will be applied to the end-users, existing the possibility of the original tariff being kept, in the case of being advantageous to the enduser. Selected end-user: Only the tariffs from the selected end-users will be applied. The users are selected by the operator in the platform graphical interface through a list of the available end-users.
After applying the desired tariffs, is possible to save the dataset with the applied changes on the end-users. The saving functionality is available at any time.

End-users' aggregation model
The objective of the aggregation service is to group end-users by similar attributes, and then present the results to the operator. The aggregations have special importance since the introduction of the demand response programs.
The clustering algorithm used in the proposed service is K-Means, also known as Centroid-Based Clustering. Because this algorithm only accepts numerical data, the categorical parameters are encoded to numerical values. The aggregation service receives as arguments the dataset, the minimum number of clusters, and the maximum number of clusters.
Even though the platform backend is developed in Python, the used aggregation service is developed in R. The K-Means algorithm will run one time for each possible number of clusters, saving the results of each one. It should be noted that this is a semi-random algorithm, so it is executed several times and the best execution is chosen. The used K-Means method allows you to define how many times it will run through a parameter.
The operator has the possibility to choose which parameters should be included in the aggregation service, and it is suggested every possible combination of the chosen parameters. Figure 3 represents the selection panel. It is also possible to assign a weight to each parameter, between 0 and 10, if needed to give more importance to some parameters.
After selecting the parameters, the operator must choose all the pretended combinations between the parameters. For each combination, the K-Means algorithm will be executed, and the results can be studied individually for each chosen possibility. Figure 4 shows the panel where the operator can combine the parameters for the aggregation service.
This service is implemented with a task queue, which allows that time-consuming tasks can be performed in the background, without interrupting the proper functioning of the platform. In this way, it is possible to request the aggregation by multiple combinations and perform other platform's services while this one is executing.
After the algorithm execution, it is possible to check the clustering results, and the Elbow and Silhouette evaluations.

Price elasticity model
The price elasticity is the measure of the consumers' response to price changes. It is important because it helps to understand the correlation between consumption and price and gives an idea of the implications that a price (tariff) change brings to the community's energy demand.  Price elasticity (Pe) is defined as the ratio of consumption variation over the price variation before and after the load response program, as proposed in (Faria and Vale 2011): where ΔQ represents the difference between the final energy quantity (Q), in kWh, and the energy quantity of the last period. Relatively to ΔP, the same logic is applied, but it represents the difference between the final energy price (P), in EUR/kWh, and the last period's energy price. This equation, when applied to all the periods of the available dataset, results in points that can be placed in a scatter chart. Then, multiple regressions are be applied to those points, to create a complete end-user's profile relative to the price elasticity rate. The available regressions, in the proposed platform, are linear and quadratic. The metric used to compare the regressions and evaluate which is the most adequate, is the coefficient of determination, denoted R 2 .
Both regressions can be analysed graphically, through the representation on a chart, or analytically, through the regressions' equation.

Load response model
The load response model is a direct consequence of the price elasticity model, due to the use of the created regressions in that service. The objective is to predict new consumption values for each end-user considering a determined price change.
The main objective is to change the community's consumption (i.e., reduce or increase) through the variation of the energy price based on the end-users' price elasticity. This service requires as input the expected consumption variation needed, and it will return the necessary price change to achieve it, and the estimated variation per end-user. The max reduction that can be applied is the sum of the end-users' consumption, which will take the community's consumption to zero. In the opposite case, in which an increase in consumption is requested, the limit is reached by the decrease of 100% of the price (i.e., the price is equal to zero). None of these situations is what is intended with the service, but they serve as validation.
The regression with the highest score is applied to find the new consumption, which will result in a more accurate result, and consequently in a more realistic approach.

Case study
The case study for the platform services was realized using a dataset based on the one used in (Silva et al. 2019). The dataset contains information on 996 end-users, considering 5 full days, with a granularity of 15 min. The dataset contains information regarding: Consumption Profile: energy consumed during each period, in kWh; Generation Profile: energy generated during each period, in kWh; Consumption Type: type of end-user, i.e., domestic, small commerce, medium commerce, large commerce, or industrial; Generation Type: type of generation of the player, i.e., photovoltaic, wind, biomass, or hydrogen; Consumption Tariff: energy consumption tariff applied, in EUR/kWh; Generation Tariff: energy generation tariff applied, in EUR/kWh; Flexibility: the percentual value of consumption flexibility for each period; Contracted Power: power defined in the consumption tariff contract, in kVA.
The data must be uploaded through an excel file, with n sheets, each one of them with x rows and y columns, where n is the number of parameters, x is the number of players, and y is the number of periods.
Some of the considered parameters are not measured by periods, as the contracted power or the generation type, as they are characteristics of the end-user and do not change between periods.
For this case study, the main services of the platform were analysed, in terms of results obtained and response times. A sequence of models was used to test and validate the use of the proposed platform: tariff calculation and attribution model, end-user aggregation model, price elasticity model, and load response model.

Energy tariffs
To enable the execution of the tariff calculation and attribution model, the developed platform demands the input of an excel file with a set of available consumption and generation tariffs. The used tariffs were generated considering hourly prices based on the MIBEL market. The tariffs file contains five consumption tariffs and five generation tariffs.
After the tariffs are loaded to the platform, it is possible to calculate the best tariff, by type (consumption or generation), to each one of the end-users. Depending on the characterization of the end-user, only one tariff may be attributed, for instance, producers will not have consumption tariffs. After the calculations are finished, the operator can visually analyse the original and the most profitable tariff to each end-user, through a comparative graph, shown in Fig. 5. It is also possible to check if the bestcalculated tariff is better than the original, considering the cost or profit. Above the tariffs graph is displayed an information box, with a contextualized colour, demonstrating the positive or zero profit, in the case of the original tariff is the best for the current end-user, reflecting the tariff assignment.
Besides the comparison between the most profitable tariff and the original one, it is also possible to compare all the calculated tariffs in terms of total cost/profit. When comparing the consumption tariffs, as seen in Fig. 6, the best tariff is the one with the smallest bar, in other words, the one with the smallest cost. Concerning the generation tariffs, is the opposite, the biggest bar represents the most profitable tariff.
The last step of the tariffs service is the update of end-users' tariffs. The operator can assign the best tariffs to each end-user, according to their consumption or generation profile. The assignment can be simultaneous to the whole community, or just to the pretended end-users.
Regarding the response times of the service, it is surprisingly quick. It takes 2.9 s to read a file with 10 tariffs, with 5 days of prices information, and it takes 2.5 s to execute the calculations, considering all the tariffs, to the 996 end-users.

Aggregation
For the aggregation service, multiple parameter combinations were studied, considering equal weights. The chosen parameters were Consumption Profile (C), Consumption Type (CT), Generation Profile (G), Generation Type (GT), and Contracted Power (CP). The operator is responsible to select the pretended combinations, while the proposed service has the responsibility to execute the end-users' aggregation model for each combination. The executed combinations are presented in Table 1. The whole process took, approximately, 1 h and a half to be concluded. Because the used K-Means algorithm is a semi-random algorithm, and to ensure that the results are reliable and accurate, it runs 25 times for each parameter combination, and the best results are the chosen ones.
Besides the chosen combinations shown in Table 1, one more was tried in the aggregation service. This one, only containing the parameter Contracted Power, had the objective to show that the service validates the input parameters with the selected number of clusters. As, in the case study dataset, only exists 3 different values for this parameter, and the cluster interval was one to ten, the service has thrown a validation error, as shown in Fig. 7. It is not possible to execute the service if the maximum number of clusters is smaller than the unique column values of the chosen combination.
To examine the details on the aggregation service, the results for the combination Generation and Generation Type are analysed individually. The optimal number of clusters obtained by the Elbow method was 3, and by the Silhouette method was 8. In Fig. 8, it is possible to analyse the generated evaluation graphs by those methods, as well as the optimal results.
Considering the Elbow method result as optimal, the data will be divided into three different groups. In Fig. 9 is possible to analyse the created clusters. The first cluster is composed totally by the end-users without energy generation (generation type is None). The second cluster contains the end-users with wind-generated energy, and the last one contains all the other end-users. It is an interesting separation because it does not split any of the end-users with the same generation type into more than one cluster, being helpful to future analysis. However, it also is an expected division, considering that the non-producers (i.e., consumers) have an exclusive group, and the wind generation is in majority on the dataset (254 end-users).
If the considered evaluation method is Silhouette, the optimal number of groups is eight. It is an expected number since there are eight different generation types on the dataset. In Fig. 10 is possible to observe that with eight clusters, it is made a perfect division, considering that each one of the clusters is exclusive to one generation type.
Both considered number of clusters provides a good division to the dataset. The chosen number of groups will always depend on the context and the goal of the division since there are multiple possible applications for both obtained cluster numbers.

Price elasticity regressions
The first step of this service is to calculate the price elasticity for each period of the dataset, to each of the end-users. Then, all the calculated points are plotted in a scatter plot, where it is possible to analyse the elasticity of each user. An example of a scatter plot, only with 2 end-users for the points to be readable, is represented in Fig. 11. The platform takes around 6 s to calculate the price elasticity of 995 end-users considering each period, and to load the graphic.  Besides, the scatter plot, the operator has the possibility to consult a table where is displayed the linear and quadratic equations from the regressions, and the respective scores. An example extracted from the table is shown in Table 2. The regressions scores were calculated, as previously stated, with the R 2 metric.
With the analysis of the table, it is noticeable that all the regression coefficients are negative. It is an expected result since consumption and price should have opposite directions. This because, if the end-users' profiles are explored, it is normal to decrease the energy consumption when there is a price increase, and the same happens for the opposite situation.
The regressions calculations of 995 end-users take about 9.5 s to be complete. As expected, none of the linear regressions achieved a greater score than quadratic regressions. Even so, the linear regressions in the graph were maintained for purposes of comparison and testing. The average score for linear regressions was 0.498, and for quadratic was 0.688.

Load response service
The load response service has the goal to reduce the end-users demand, with an increase in the energy tariff. In a price-based demand response program, to decrease energy peaks, the operator knows how much the peak should decrease, but to the endusers only is communicated an energy price change.
Considering that the developed platform has the goal to analyse end-users' historical data, it does not have a mechanism to, after the reduction is requested, wait for the response of the end-users. Instead, the load response service predicts the end-users' response considering their elasticity profile, made available by the price elasticity model.  To achieve the pretended reductions the price is incremented by 0.01% in every iteration, and if with that increase the pretended reduction is reached, the service returns the results. The maximum possible reduction is the sum of all end-users' consumption, and the platform notifies the percentage of the requested reduction towards the max one. The studied reductions are represented in Table 3.
To complement the information for the operator is displayed a graph where is possible to observe the applied reductions by the service. It can show the reduction applied to the whole community, or a single end-user. The graph for all end-users is shown in Fig. 12.
Despite not being the main goal of the service, it is also possible to request a consumption increase, through a tariff price decrease. This functionality of the service was also tested, and the results are displayed in Table 4.

Conclusion
This paper proposes a web-based platform to manage local energy communities. With the increasing interest in smart grids and local communities, there is a need for platforms capable of dealing with the most important services related to the communities, such as the services proposed in this paper.
This platform can run with multiple scenarios, being able to manage multiple communities or periods in the same system. It is very useful to analyse the effect of the available services on the most diverse type of end-users and communities. Besides that, the combination of multiple services can provide community operators with vital tools.
The results of the case study validated the proposed services for a community with 996 end-users, reaching economic benefits for end-users, through the application of new tariff, and enabling price-based demand response programs to promote the community energy balancing. The promising results show the potential of such a platform. However, future services must be developed, such as peer-to-peer transaction models, resource optimization algorithms, and grid simulations, enabling the development of a complete platform for the operation and management of citizen energy communities.