## 2 Materials and Methods
### Scenarios S2\({}_{x}\)
* \(B^{j}_{L}=SOC^{j}_{L}\cdot B^{j}_{r}\), minimum value of stored energy that must be maintained at all times to avoid damage to the battery. The energy that will finally be put into circulation will be the minimum value between the energy available to help the other home and the maximum value required by the other home. If the generation capacity exceeds the sum of demanded energy, storage capacity and energy transmitted to the other home, there will be an excess of generation capacity that will not be used, resulting in a certain amount of ENU. Figure 3 shows the energy flows in S2\({}_{\rm x}\). If the generated energy is lower than demand, some demanded energy should be supplied with the energy stored in the ESS, with the efficiency \(\eta_{\rm d}\). If the energy available in the ESS (\(B^{1}-B^{1}_{L}\)) is not enough to cover the demand, a situation with a need for energy from the transmission system is reached. To improve the reliability of the supply, it is also considered the energy needed in the ESS if it does not reach the \(SOC_{\rm C}\), which is \(B^{1}_{C}-B^{1}\geq 0\). When \(SOC>SOC_{\rm C}\) energy is not demanded from the transmission system, since this energy is subjected to various actions with yields lower than 1 and, therefore, these transfers must be limited. If the sum of the own generation, the energy available in the battery and the energy received from the cooperative system is not enough to cover the demand, there will be an ENS, which will be counted and will affect the studied indices. From the demand and generation curves of each house, with the random failures generated and using a step of 1 h, the following set of equations describes the cooperative strategy to apply. The initial data needed for each dwelling are \(B^{j}_{M}\), \(B^{j}_{C}\), \(B^{j}_{L}\), \(\eta_{\text{L}}\), \(\eta_{\text{L}}\), \(\eta_{\text{L}}\), \(\eta_{\text{L}}\). Then, for each step \(i\), the values of \(G^{j}_{i^{\prime}}\), \(D^{j}_{i^{\prime}}\), \(B^{j}_{i}\) must be obtained. Next, the surplus generation \(U^{j}_{i}\) is calculated for each dwelling using Equation (1)  
\[U^{j}_{i}=G^{j}_{i}-D^{j}_{i} \tag{1}\]  
where \(U^{j}_{i}\) is the usable energy that represents the surplus energy generation. If \(U^{j}_{i}>0\), there is a net surplus generation, so the next equations must be used  
\[B^{\prime j}_{i}=B^{j}_{i}+U^{j}_{i}\eta_{\text{L}} \tag{2}\]  
\[E^{j}_{i}=B^{\prime j}_{i}-B^{j}_{M}\geq 0 \tag{3}\]  
\[B^{\prime j}_{i}=\min\Big{\{}B^{j}_{i}\text{, }B^{j}_{M}\Big{\}} \tag{4}\]  
Otherwise, when \(U^{j}_{i}<0\), Equations (2)-(4) must be substituted by the following expressions, since there is a net generation deficit  
\[B^{\prime j}_{i}=B^{j}_{i}+\frac{U^{j}_{i}}{\eta_{\text{L}}} \tag{5}\]  
Figure 3: Possible energy flows in S2x when generation is greater than demand (**a**) and when generation is smaller than demand (**b**). \[E_{i}^{j}=B_{i}^{\prime j}-B_{L}^{j}\leq 0 \tag{6}\]  
\[B_{i}^{\prime j}=\max\Bigl{\{}B_{i}^{\prime j},\ B_{L}^{j}\Bigr{\}} \tag{7}\]  
After these intermediate calculations have been computed, Equation (8) is used to calculate \(N_{i}^{j}\), which represents the energy needed to supply the demand and to increase the energy stored up to \(B_{C}^{j}\). Figure 2:0  
The available energy to be sent to another participant, \(P_{i}^{j}\), also called pool energy, can be derived from Equation (9) as  
Figure 2:1  
With these values, the following equations must be used. Figure 2:2  
Figure 2:3  
where \(T_{i}^{\prime j\to k}\) is the energy that will be sent from Dj to Dk, and \(T_{i}^{k\to j}\) is the energy received by Dj from Dk. At the end of step \(i\), the energy stored in the battery, \(B_{i}^{\perp j}\), in Dj is calculated using Equation (12)  
Figure 2:4  
For the next step \(i+1\), the battery level will be updated as \(B_{i+1}^{j}:=B_{i}^{\perp j}\). Finally, the following two parameters are computed for each dwelling to evaluate the results of the simulation  
Figure 2:5  
Figure 2:6