# A Methodology for Exploiting Smart Prosumers' Flexibility in a Bottom-Up Aggregation Process
## 2 Day-Ahead Management Phase Algorithm  
As described in [23], during the configuration phase, the EMS forecasts the prosumer's load diagram for the following day, based on a Monte Carlo approach previously tested for similar applications [25], and corrected considering the real profiles measured each day. The process leads to the assessment of the flexibility contribution that can be provided by each controllable device in every hour of the following day. The day-ahead management phase starts when the DSO sends a flexibility request to the VAE. This action activates all EMSes of the prosumers that, according to the DSO information, can participate in the DR action for providing the requested flexibility (e.g., if the flexibility request is the reduction in the power peak downstream a secondary substation, only the EMS of the prosumers supplied by that substation are activated). Every EMS evaluates and sends to the VAE a list with all the feasible flexibility contributions that the prosumer can provide in the specified time period, indicating, at the same time, the involved flexible devices and the desired tariff (economic offer). The overall flexibility contributions are obtained using the rules of combinatorial calculation by combining the flexible powers associated with each controllable device. If \(n\) is the number of flexible devices and \(k\) is the number of devices combined in order to provide the desired power variation, the number of possible combinations that a given prosumer can offer is:  
\[C_{nk}=\frac{n!}{(n-k)!k! }=\left( \begin{array}{c}n\\ k\end{array} \right) \tag{1}\]  
The total number of combinations is calculated by varying the number of combined devices \(k\) from 1 to \(n\), therefore:  
\[C_{n,tot}=\sum_{k=1}^{n}C_{nk} \tag{2}\]  
For each combination of devices and for each potential flexibility contribution, the EMS calculates a flexibility tariff. The tariff \(\text{T}_{\text{FL}}\) accepted by the prosumer as an adequate remuneration for the service is calculated as:  
\[\text{T}_{\text{FL}}=\text{DF}_{\text{t}}+\text{C}_{\text{E}}+\text{C}_{\text {BESS}} \tag{3}\]  
where \(\text{DF}_{\text{t}}\) is the disutility function, \(\text{C}_{\text{E}}\) is the energy price for the prosumer in the specific time interval and \(\text{C}_{\text{BESS}}\) the degradation cost of the batteries used for providing flexibility. The disutility function is introduced with the aim of taking into account the prosumer's dissatisfaction due to the change in the forecasted consumption and is given by:  
\[\text{DF}_{\text{t}}=|\Delta\text{P}|\cdot\Delta\text{t}\cdot\text{d} \tag{4}\]  
where:  
* \(\Delta\text{P}\) is the difference between the power consumption that would have been if the prosumer had not participated in the DR action and the power consumption required to satisfy the DR request;
* \(\Delta\text{t}\) is the time slot of the DR request;
* \(\Delta\text{t}\) is the \"dissatisfaction cost per kWh\", and it is a parameter that can be set by the prosumer during the configuration phase, depending on the hour of the day and taking into account the prosumer's habits and preferences. \(\text{C}_{\text{E}}\) is given by:\[\text{DF}_{\text{t}}=|\Delta\text{P}|\cdot\Delta\text{t}\cdot\text{d} \tag{5}\]  
where c is the energy cost expressed in \(\epsilon\)/kWh. If the energy cost changes during the time slot where the offer is formulated, c is the average of the costs calculated during the time interval \(\Delta\text{t}\). The battery degradation cost is given by:  
\[\text{C}_{\text{BESS}}=\frac{\text{N}_{\text{d}}}{\text{N}_{\text{max}}}\cdot \text{C}_{0} \tag{6}\]  
where C\({}_{0}\) is the purchase and installation cost of the storage system, N\({}_{\text{g}}\) is the number of charge/discharge cycles of the battery per day for providing flexibility and N\({}_{\text{max}}\) is the maximum number of charge/discharge cycles during the useful life of the battery.