*3.2. PCC Power Balance (ECO/V2G)*

In order to indicate the power balance at the Point of Common Coupling (PCC) and to verify the energy exchange between the PV source, loads, and the EV, it can established that:

$$R\_{\rm pcc} = \delta r\_G(t\_m) \left[ P\_{EV\_{E,V2G}}^\*(t\_m) + \mathcal{P}\_{\rm net}(t\_m) + \mathcal{P}\_{EV\_M}(t\_m) \right] \Delta t. \tag{7}$$

In this case, the EV is defined as the load type profile, wherein:

$$\mathcal{P}\_{\rm net}(t\_m) = \mathcal{P}\_{\rm L}(t\_m) - \mathcal{P}\_{PV}(t\_m) \tag{8}$$

$$\mathcal{P}\_{EV\_M}(t\_m) = \sum\_{\substack{M \text{ad}\varepsilon \in \mathcal{M}^\*}} P\_{EV\_{i,j} \cdot \{M \text{ad}\varepsilon\} .} \tag{9}$$

wherein M<sup>∗</sup> represents all vehicles in all modes, except the current vehicle.

In (7), *δ* 1 is the weight associated with the influence of *Rpcc* in the cost function, e.g., such that the microgrid manager could attribute an extra charge for V2G energy; *rG*(*tm*) is the purchase energy price from the external grid for sample *tm*; *P*∗ *EV* represents the optimal charging power. The variables *P*ˆ *<sup>L</sup>* and *P*ˆ *PV* are the one day-ahead demand and PV generation, respectively, which are obtained from the prediction module. The variable *P*ˆ *EVM* establishes the influence on the control law computation of all modes of the remaining vehicles. Therefore, the cost function takes the EV charging demand into account. The charging profile is calculated until the disconnection for all vehicles, regardless of the current instant. The term Δ*t* is applied to equalize units of the factors of the cost function and to obtain the energy unit.

## *3.3. Generation Surplus (ECO/V2G)*

The ECO mode is defined such the EMS commands the power stations to charge the EVs during the PV generation surplus or when the energy price is low. To accomplish this approach, a gain schedule *α* is added to the control response *P*∗ *EVE* in the PCC power balance factor. When a surplus occurs, *α* is lower than one, and the cost function prioritizes the charge of the EVs in both ECO and V2G modes. The surplus index is summarized as:

$$\alpha = \begin{cases} \alpha\_0 & \text{if } P\_{n\ell}(t\_m) + P\_{EV\_M}(t\_m) \lessapprox 0 \\ 1 & \text{otherwise.} \end{cases} \tag{10}$$

wherein *α*<sup>0</sup> < 1 must be chosen in order to increase the charging rate when the PV generation overcomes *PL* + *PEVM* .
