## 3 Proposed Strategy for Energy Management
### Control Algorithm  
The algorithm uses the input data listed below:  
* General data uploaded off-line in the form of tables of constant values:
* Energy tariff for each hour and day of the year;
* The PV generation profile for maximum solar radiation (maximum generation conditions) for each hour and day of the year;
* Maximum supplying power of the installation (based on the contract with the DSO);
* The nominal power of the EV drive inverter.
* Data regarding cloud cover obtained from the weather forecast for the next day.
* Data obtained online from the appropriate meters:
* Active power consumed by the prosumer loads;  
\begin{tabular}{l l} \(\circ\) & Active power generated by the PV; \\ \(\circ\) & Active power exchanged by the ESS converter; \\ \(\circ\) & The current energy level of the EV battery. \\ \(\bullet\) & Data entered by the prosumer EV user: \\ \(\circ\) & Introduced off-line: The minimum level of the EV battery charging, required for short distance driving and the maximum energy level, the exceeding of which shortens the battery life. It was assumed that SOC\({}_{\text{min}}\) = 20% and SOC\({}_{\text{max}}\) = 80%; \\  & however, the EV user is able to change this value, if required; \\ \(\circ\) & Introduced at each connection to the installation: The scheduled time to start the next trip and the distance of this trip. \\ \end{tabular}  
The control system starts to operate after connecting the EV to the charging circuit (wallbox--compliant with charging mode 3 [27]). First, the current day (i) and hour (t) are identified, and the input data are introduced by the driver. Then, the algorithm checks the current state of charge of the EV battery to examine whether or not the required energy reserve is secured. If not, i.e., the SOC is lower than 20%, the algorithm forces the battery to charge with all the power available in the installation, taking into account the limitations of the power supply from the supplying network. In this way, the algorithm keeps the battery charge on the level allowing short-distance driving at any time.  
The V2H service is provided only when the required energy reserve is secured. When operating in this mode, the algorithm controls the power of the EV inverter by charging or discharging the battery in a way that the supplying power has a zero value, regardless of the power of other devices in the prosumer installation. According to these assumptions, the operating range of the battery SOC is 20% \(\leq\) SOC\({}_{\text{ev}}\) \(<\) 80% of the maximum energy level.  
Due to the priority of preparing the EV for the next trip, the period of V2H operation may be lower than the period of the EV connection. The algorithm turns on the battery charging at a moment determined on the basis of the trip data introduced by the driver, in order for the EV battery to reach the planned level of SOC before the time of driving commencement. The charging process takes place in the same way as for a short-distance charging, i.e., using the maximum currently available power.  
With randomly variable generation and power consumption in the prosumer installation and the need to have the EV battery charged before driving, some amount of energy must always be taken from the supplying network. If due to the poor weather conditions the local generation is low, the energy derived from the network is bigger. From the weather forecast, the algorithm calculates the amount of missing energy, not generated by the PV source, and by appropriately controlling the power of the EV inverter, it may cause the missing energy to be taken from the power network during the low-price energy tariff.  
A flow chart for a developed control algorithm is presented in Figure 2 (divided into part A and B).  
Figure 2: _Cont._  
Figure 2: (**a**). Flow chart of the control algorithm—part A. (**b**) Flow chart of the control algorithm—part B.