Daniela Yassuda

Yamashita Estia
email: d.yamashita@estia.fr

Ionel Vechiu
email: i.vechiu@estia.fr

Jean-Paul Gaubert
email: jean.paul.gaubert@univ-poitiers.fr

Hierarchical Coordination of a Vehicle-to-Grid System to Improve Self-consumption in Building MicroGrids

Keywords: Model Predictive Control, Electric Vehicles, Building microgrid, self-consumption, economic analysis I

Aiming to take full advantage of Electric Vehicles' (EVs) batteries despite unpredictability in their arrival and departure time, in this paper, a two-level hierarchical model predictive controller coupled with an innovative charging-discharging scheduler for EVs in building microgrids is proposed. Besides providing a complete framework for its design, this paper also analyses different scenarios of EVs' batteries exploitation that would be beneficial for both building microgrids and EVs' owners. The simulation results conducted in MATLAB Simulink demonstrated that the proposed hierarchical controller could assure that most EVs are completely charged before their departure time while enabling building microgrids to increase their annual photovoltaic selfconsumption rate by about 3 percent point compared to the uncontrolled strategy.

INTRODUCTION

With the fast electrification in the transportation sector, Electric Vehicles (EVs) play a critical role in meeting the environmental goals to address climate change [START_REF]Global EV Outlook 0 0 -prospects for electrification in transport in the coming decade[END_REF]. However, without appropriate coordination of EV charging, the sharp increase of EV fleets can introduce harmful effects in the grid stability, such as overload of transformers and power quality issues [START_REF] Zheng | Integrating plug-in electric vehicles into power grids_ A comprehensive review on power interaction mode, scheduling methodology and mathematical foundation[END_REF]. To adapt the current grid to this new paradigm, EVs in the bidirectional Vehicle-to-Grid (V2G) configuration have emerged as a promising strategy to reduce the negative effects of EV surge [START_REF] Mendes | Energy management of an experimental microgrid coupled to a V G system[END_REF]- [START_REF] Van Der Kam | Smart charging of electric vehicles with photovoltaic power and vehicle-to-grid technology in a microgrid; a case study[END_REF]. This is because V2G technology enables EVs to be employed as both a flexible load and an Energy Storage System (ESS).

Consequently, while parked, EV's batteries can provide some grid services to assist the integration of Renewable Energy Sources (RES) into the electrical grid that struggles with volatility in the power imbalance. EVs' batteries can be discharged to supply the local demand and can be charged to avoid injection of RES energy surplus. Particularly, since EVs are parked for more than 90% of their lifetime [START_REF]Global EV Outlook 0 0 -prospects for electrification in transport in the coming decade[END_REF], their batteries can be coupled to buildings with roof-top photovoltaic (PV) panels. This grid topology -known as Building Microgrid (BMG) -facilitates EVs' owners to charge their vehicles' batteries with clean energy while at the same time reduce the drawbacks created by unpredictable RES energy generation. Nonetheless, the design of a Building Energy Management System (BEMS) is required to properly coordinate the charging-discharging of EVs to improve the BMG's PV self-consumption and assure that all EVs are completely charged before their departure time.

In the literature, there are many strategies to coordinate the charging-discharging of EVs to promote PV self-consumption in buildings [START_REF] Mendes | Energy management of an experimental microgrid coupled to a V G system[END_REF]- [START_REF] Liu | A Heuristic Operation Strategy for Commercial Building Microgrids Containing EVs and PV System[END_REF]. To assure that all EVs are fully charged and maximise the PV self-consumption, the BEMS are usually divided twofold [START_REF] Mendes | Energy management of an experimental microgrid coupled to a V G system[END_REF], [START_REF] Van Der Kam | Smart charging of electric vehicles with photovoltaic power and vehicle-to-grid technology in a microgrid; a case study[END_REF]: a central unit to optimise the BMG power flow, and a real-time module to charge and discharge each EV according to a priority order. However, in most studies, the aleatory disconnection of EVs is ignored. Additionally, when dealing with large EV fleets, the computation burden is the main issue of power flow optimisation [START_REF] Zheng | Integrating plug-in electric vehicles into power grids_ A comprehensive review on power interaction mode, scheduling methodology and mathematical foundation[END_REF], [START_REF] Mendes | Energy management of an experimental microgrid coupled to a V G system[END_REF], limiting the BMG power flow to be optimised only once a day. Alternatively, simple on-board strategies to EVs' power allocation exist [START_REF] Liu | A Heuristic Operation Strategy for Commercial Building Microgrids Containing EVs and PV System[END_REF], but they consider neither prediction data nor uncertainty in EVs' disconnection nor the use of another type of ESS.

Aiming at maximising PV self-consumption in BMG under stochasticity in prediction data, a two-level Model Predictive Controller (MPC) empowered with a light Electric Vehicle Power Allocation (EVPA) module was designed. Contrary to many studies [START_REF] Mendes | Energy management of an experimental microgrid coupled to a V G system[END_REF], [START_REF] Tavakoli | A two stage hierarchical control approach for the optimal energy management in commercial building microgrids based on local wind power and PEVs[END_REF], the innovation of the proposed controller is that no parameter needs to be tuned to maximise the self-consumption rate and guarantee the full charging of EV fleets. Through one-year simulation in MATLAB Simulink of a real-sized residential BMG equipped with PV, Li-ion batteries, and an EV parking with 4, 20, or 40 vehicles, the capabilities and robustness of the proposed hierarchical controller were assessed. Furthermore, this paper quantifies the additional degradation rate of EVs' batteries when they are discharged to supply the building energy demand and identifies a type of remuneration to foster EVs' owners to authorise using their EVs' batteries to promote self-consumption in BMGs.

The remainder of this paper is structured as follows. Section II presents the hierarchical MPC design. Section III details the proposed EVPA algorithm by highlighting its interaction with the two-level MPC. Section 4 presents the simulation results with discussions over the system performance. Finally, Section V concludes the paper.

II. HIERARCHICAL MODEL PREDICTIVE CONTROLLER

As shown in Fig. 1, the BMG counts on Li-ion batteries and parking with up to 𝑁 𝐸𝑉 EVs to supply its local demand as much as possible with PV energy generated locally. The proposed hierarchical BEMS is composed of three control levels, namely: Economic MPC (EMPC), Tracking MPC (TMPC), and EVPA. Considering the fluctuations in the internal power imbalance, the EMPC determines State-of-Charge (SoC) references of stationary batteries (𝑆𝑜𝐶

With this formulation, the BMG uses its ESS to maximise the PV self-consumption (𝜏 𝑠𝑐 ) and coverage (𝜏 𝑐 ) rates defined by (2), avoiding importing (𝐸 𝑔𝑟𝑖𝑑,𝑘 𝑖𝑚𝑝𝑜𝑟𝑡 ) and exporting energy (𝐸 𝑔𝑟𝑖𝑑,𝑘 𝑒𝑥𝑝𝑜𝑟𝑡 ). The EMPC is an asynchronous control unit updated every midnight or when the gap between the expected grid exchange calculated by the EMPC internal models and the real one measured by the smart meter is higher than a predefined threshold (i.e. 7%). The errors in the EMPC's prediction states can come from either stochasticity in the power imbalance, imprecisions in the ESS's internal model, or unexpected EVs disconnection. For further information, the proposed two-level MPC is an extension of its previous version for BMGs without EVs [START_REF] Yamashita | Real-time Parameters Identification of Lithium-ion Batteries Model to Improve the Hierarchical Model Predictive Control of Building MicroGrids[END_REF].

𝜏 𝑠𝑐 = 1 - ∑|𝐸 𝑔𝑟𝑖𝑑,𝑘 𝑖𝑚𝑝𝑜𝑟𝑡 | ∑ 𝐸 𝑝𝑣 ; 𝜏 𝑐 = 1 - ∑|𝐸 𝑔𝑟𝑖𝑑,,𝑘 𝑒𝑥𝑝𝑜𝑟𝑡 | ∑ 𝐸 𝑐𝑜𝑛𝑠 (2)
Meanwhile, TMPC follows 𝑆𝑜𝐶 𝑏𝑎𝑡 𝑟𝑒𝑓 and 𝐸 𝐸𝑉 𝑟𝑒𝑓 determined by the EMPC. It calculates the power references for batteries (𝑃 𝐵𝐴𝑇 𝑐ℎ and 𝑃 𝐵𝐴𝑇 𝑑𝑖𝑠 ) and the entire EV parking (𝑃 𝐸𝑉𝑠 𝑐ℎ and 𝑃 𝐸𝑉𝑠 𝑑𝑖𝑠 ) based on the updated prediction data and measurements. Therefore, TMPC optimises hourly the cost function defined by (3). This cost function is normalised to make the error of each reference tracking between 0 and 1 by dividing each tracking error by its maximum values (i.e. 𝐸 𝐸𝑉,𝑘 𝑚𝑎𝑥 and 𝑆𝑜𝐶 𝑏𝑎𝑡 𝑚𝑎𝑥 ). Additionally, aiming to give more importance to the instantaneous references than the upcoming references, the quadratic errors are multiplied by the term (𝑁 ℎ 𝑇𝑀𝑃𝐶 -𝑘 -1) 2 , where 𝑁 ℎ 𝑇𝑀𝑃𝐶 is the TMPC horizon and 𝑘 is the time within the horizon window.

Both MPC objective functions are constrained to keep the safe operation of ESSs and respect the grid code for small prosumers in France [START_REF]Enedis l'électricité en réseau[END_REF]. Therefore, as defined in (4) and ( 5), the charging and discharging of EV parking are limited by the maximum power rate of the aggregation of EVs (𝑃 𝐸𝑉 𝑚𝑎𝑥𝐶ℎ and 𝑃 𝐸𝑉 𝑚𝑎𝑥𝐷𝑖𝑠 ) that is provided by the EVPA module. To avoid taking advantages from fluctuations of electricity price, stationary batteries can be charged only with PV power surplus (-𝑃 𝑝𝑣 + 𝑃 𝑐𝑜𝑛𝑠 ≤ 0), as specified in [START_REF] Liu | A Heuristic Operation Strategy for Commercial Building Microgrids Containing EVs and PV System[END_REF]. Meanwhile, they can only be discharged to supply the local power demand ( 𝑃 𝑐𝑜𝑛𝑠 ) or charge EVs ( 𝑃 𝐸𝑉,𝑘 𝑐ℎ ), as expressed in [START_REF] Yamashita | Real-time Parameters Identification of Lithium-ion Batteries Model to Improve the Hierarchical Model Predictive Control of Building MicroGrids[END_REF]

Remarkably, as in [START_REF] Tavakoli | A two stage hierarchical control approach for the optimal energy management in commercial building microgrids based on local wind power and PEVs[END_REF], to reduce computation burden, the two MPCs in cascade estimate the total energy stored in the aggregation of EVs ( 𝐸 𝐸𝑉,𝑘 ) rather than individual EVs. Therefore, only two inequalities constraints are embedded in the MPCs formulation, as expressed in [START_REF] Chung | Ensemble machine learning-based algorithm for electric vehicle user behavior prediction[END_REF]

To assure that all EVs are fully charged (i.e. SoC = 80%) before their scheduled departure, EMPC and TMPC modify their SoC boundaries (𝑆𝑜𝐶 𝐸𝑉 𝑚𝑖𝑛 and 𝑆𝑜𝐶 𝐸𝑉 𝑚𝑎𝑥 ) to force both to be 80% when any EV is planning to disconnect to the BMG. In other words, the maximum boundary (𝑆𝑜𝐶 𝐸𝑉 𝑚𝑎𝑥 ) is always equal to 80%, whereas the minimum boundary (𝑆𝑜𝐶 𝐸𝑉 𝑚𝑖𝑛 ) is adjusted following equation [START_REF]JRC Photovoltaic Geographical Information System (PVGIS) -European Commission[END_REF], where 𝑛 𝑘 𝑑𝑒𝑝 is the number of EVs that are going to disconnect at hour 𝑘.

𝑆𝑜𝐶 𝐸𝑉 𝑚𝑖𝑛 = { 20%, 𝑖𝑓 𝑛 𝑘 𝑑𝑒𝑝 = 0 𝑆𝑜𝐶 𝐸𝑉 𝑚𝑎𝑥 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 (10)
Notably, in equation ( 9 These three values can be easily calculated using a simple EV schedule table based only on the current number of EVs connected, the next EV connection, and disconnection time inputted by EVs' owners. Nevertheless, this mechanism can be improved by including an analysis of EV's behaviour, as proposed in [START_REF] Chung | Ensemble machine learning-based algorithm for electric vehicle user behavior prediction[END_REF]. The EV arrival energy formulation (equation ( 15)) considers that all EVs have the same nominal capacity ( 𝑄 𝐸𝑉 𝑛𝑜𝑚 ). The SoC of future EVs arrivals ( 𝑆𝑜𝐶 ̂𝐸𝑉𝑠,𝑘 𝑎𝑟𝑟 ) are estimated through the average SoC of all past EV connections. On the other hand, the total energy lost due to EV departures (𝐸 𝑘 𝑑𝑒𝑝 ) corresponds to a proportion of the average charge of all EVs. This assumption is reasonable because the EVPA algorithm, detailed in section III, assures almost equitable SoC among all EVs.

𝐸 𝑘 𝑑𝑒𝑝 = 𝑛 𝑘 𝑑𝑒𝑝 • 𝐸 𝐸𝑉,𝑘 𝑛 𝐸𝑉,𝑘 ⁄ (11)

III. ELECTRIC VEHICLE POWER ALLOCATION ALGORITHM

The EVPA operates as a router of energy to assure that all EVs are charged up to 𝑆𝑜𝐶 = 80% before their departure time using as much as possible renewable energy. Based on equation ( 9), neither EMPC nor TMPC have any information about the energy stored in each EV, but only the total energy of the entire EV parking, named 𝐸 𝐸𝑉 . Due to the incomplete information about the SoC of each EV, the full charging of individual EVs cannot be guaranteed with only the Hierarchical MPC (HMPC) power assignation, especially when EVs connect at a different time or with different SoC.

To tackle this problem without raising the computation cost, HMPC operates synchronously with EVPA algorithm. This light adjunct module determines the portion of EV parking power reference calculated by HMPC (𝑃 𝐸𝑉 𝑟𝑒𝑓 = 𝑃 𝐸𝑉 𝑐ℎ + 𝑃 𝐸𝑉 𝑑𝑖𝑠 ) that must be assigned to each EV. It also updates the maximum charging ( 𝑃 𝐸𝑉 𝑚𝑎𝑥𝐶ℎ ) and discharging ( 𝑃 𝐸𝑉 𝑚𝑎𝑥𝐷𝑖𝑠 ) power rate of equations ( 4) and [START_REF] Van Der Kam | Smart charging of electric vehicles with photovoltaic power and vehicle-to-grid technology in a microgrid; a case study[END_REF] for the next periods. The sharing of these two variables among the hierarchical control layers avoids losing performance because adjusting the power boundaries according to the real EV parking capacity prevents HMPC from charging EVs that are already fully charged or discharging EVs that are already empty.

The EVPA algorithm shares the EV parking power reference (𝑃 otherwise, it is equal to 0. As shown in Fig. 2, the EVPA algorithm is a recursive algorithm composed of four steps. The first step -named Measurement -processes the three-input data mentioned above to calculate all necessary variables for the next step. Using the user's input departure time (𝑡 𝐸𝑉 𝐼𝐷 𝑑𝑒𝑝 ), the minimum time to charge the 𝐸𝑉 𝐼𝐷 up to 𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 𝑚𝑎𝑥 = 80% (𝑡 𝐸𝑉 𝐼𝐷 𝑚𝑖𝑛𝐶ℎ𝑎𝑟𝑔𝑒 ) can be calculated through [START_REF] Li | Data-driven health estimation and lifetime prediction of lithium-ion batteries: A review[END_REF]. This formulation considers that each 𝐸𝑉 𝐼𝐷 will be charged with its maximum charging power rate ( 𝑃 𝐸𝑉 𝐼𝐷 𝑚𝑎𝑥𝐶ℎ ) during the smallest sample time of HMPC, i.e. TMPC sample time (𝑇 𝑠 = 1ℎ ). Similarly, the remain time in which 𝐸𝑉 𝐼𝐷 will stay connected to the BMG ( 𝑡 𝐸𝑉 𝐼𝐷 𝑐𝑜𝑛 ) is calculated through [START_REF]la réalisation et l'exploitation d'Installations de production d'électricité à partir d'énergies renouvelables en autoconsommation et situées en métropole continentale[END_REF], where 𝑡 𝑐𝑢𝑟𝑟𝑒𝑛𝑡 is the current time.

Using the margin time ( Δ𝑡 𝐸𝑉 𝐼𝐷 𝑐ℎ ) defined by ( 17), the power-sharing weights ( 𝜔 𝐼𝐷 𝑐ℎ and 𝜔 𝐼𝐷 𝑑𝑖𝑠 ) are determined as expressed in (18). The Boolean variable 𝛿 𝐸𝑉 𝐼𝐷 𝑎𝑣𝑎 is equal to 1 when the 𝐸𝑉 𝐼𝐷 is waiting for a power reference assignation, and it is equal to 0 when a power reference has already been attributed to it. Since in the first iteration, no EV received a power reference, 𝛿 𝐸𝑉 𝐼𝐷 𝑎𝑣𝑎 equals 1 for all plugged 𝐸𝑉 𝐼𝐷 . Based on equations (15), when the EV parking is charging, EV power references (𝑃 𝐸𝑉 𝐼𝐷 ,𝑘 𝑐ℎ

) will be more important for EVs that has a small margin time Δ𝑡 𝐸𝑉 𝐼𝐷 𝑐ℎ . Conversely, according to (16), when discharging, EV power references (𝑃 𝐸𝑉 𝐼𝐷 ,𝑘

𝑑𝑖𝑠

) will be more intense for EVs that have a large margin time Δ𝑡 𝐸𝑉 𝐼𝐷 𝑐ℎ .

Once determined the fraction of power that needs to be allocated to each plugged EV, the next step of the EVPA algorithm depends on the accuracy of the power-sharing weight of the previous step. As expressed in (19), if the

Power Allocation

Eq. ( 15) -( ), check Eq. ( 19)

Retry

Update

and Eq. ( 20)

Boundaries Definition

Eq. ( 21

Measurement

Eq. ( 13) and ( 14) Fig. 2

IV. RESULTS

To evaluate the performance of the proposed HMPC coupled with the EVPA algorithm, a real-sized residential BMG with technical specification shown in Table 1 was simulated for one year. The PV power generation was modelled using solar profiles [START_REF]JRC Photovoltaic Geographical Information System (PVGIS) -European Commission[END_REF]. Similarly, the building's power consumption refers to a medium-sized residential building scaled from [START_REF] Lee | Electricity Demand Profile of Australian Low Energy Houses[END_REF]. The simulations were conducted to assess two aspects: the potential of the hierarchical BEMS in maximising PV self-consumption using EV parking batteries, and the economic advantages of discharging EVs to supply the building demand. These two main points are investigated in Section A and B, respectively.

A. Performance of the hierarchical EMS

To assess the performance of the proposed controller in exploiting the EV's batteries to increase the PV selfconsumption, the proposed EVPA was confronted with the uncontrolled strategy. The uncontrolled approach charges EVs with their maximum power rate as soon as they are plugged into the BMG. Since the objective is to charge EV's batteries as much as possible from renewable energy, the metrics of comparison are the annual self-consumption rate, the annual coverage rate, and the number of EVs completed charged. Notably, the self-consumption and coverage rates are maximised if the BMG reduces the grid energy exchange.

The performance of the two strategies was assessed through a comparison between an ideal and a realistic scenario. In the ideal scenario, all EVs connect to the BMG as specified in their schedule table. Furthermore, there is no error in the power imbalance prediction data, and all EVs arrive every day with SoC=40%. On the contrary, the realistic scenario includes inaccuracies in the power imbalance, the energy that EV batteries have stored when they plug into the BMG, and the planned departure and arrival time. Additionally, they were shifted in time randomly up to 3h. Similarly, the noise in the initial EV SoC follows a Gaussian distribution of a standard deviation of 5% and mean that depends on the user behaviour. Four types of users were considered. Consequently, four mean values were used, namely 30%, 40%, 50%, and 60%. Finally, the noise in the departure and arrival times are bounded to 4h.

The results in Table 2 show that the proposed hierarchical BEMS in the ideal scenario assured the annual selfconsumption rate up to 3 percent point (p.p.), and the coverage rate 2 p.p. higher than the uncontrolled strategy. Thanks to the periodic optimisations of TMPC and of EMPC explained in section II, the proposed hierarchical BEMS proved robust against power imbalance prediction data, keeping the same annual coverage rate and reducing by only 1 p.p. the annual self-consumption. Furthermore, Fig. 3 shows that HMPC coupled with EVPA can guarantee that more than 99% of 262 daily connections of 4 EVs with SoC of more than 75% before their departure even subjected to prediction data errors. According to Table 2, even though the uncontrolled approach charged all EVs to SoC=80%, less than 2% were provided by PVs, compared to more than 12% with the proposed BEMS. The power flow shown in Fig. 4a for the realistic scenario proves that EVPA charges and discharges EV's batteries to avoid energy injection (negative) and to reduce electricity purchase (positive), contrary to the uncontrolled strategy (b). Additionally, the building storage is sometimes used to charge EVs (indicated by black arrows). Fig. 4a reveals that EVs reduce grid energy exchange more actively during weekends than weekdays. This is because EVs stay plugged for longer periods, enabling the controller to discharge EVs without compromising their fully charging. It is noteworthy that during weekdays, EVs are plugged mostly during non-business hours, which is mostly between 5 PM to 8 AM. Consequently, EVs are connected to the BMG during periods of energy deficit (positive) and disconnected from the BMG when there is an energy surplus (negative). Hence, the BMG usually must purchase electricity from the grid to charge EVs. According to Table 2, 70% of EV energy demand is provided by the grid with both strategies.

It is important to highlight that these conclusions were drawn from the simulation of the BMG with four EVs. To verify the impact of the EV parking size, scenarios with 0, 20, and 40 EVs were also evaluated. As shown in Table 3, with the enlargement of EV parking, the charging of EVs with energy coming directly from PV panels is limited to 6 MWh/year. Likewise, with more EVs, the Li-ion battery pack is discharged more frequently to charge the EV's batteries, but they are limited to discharge up to 7 MWh/year. For this reason, the total energy imported from the main grid tends to increase, and the coverage rate tends to decrease with the enlargement of EV parking. Following the same reasoning, the self-consumption rate can be increased in up to 3 p.p. compared to the case with only batteries (column 0 EV), but it is limited to around 72%. These results reveal that there is an optimal number of EVs that a BMG can have connected to increase the annual self-consumption rate without reducing drastically the coverage rate.

B. Technical-economic analysis of discharging electric vehicles' batteries

To evaluate the economic advantages of discharging EV batteries to support the BMG energy needs, the case where 4 EVs can be discharged was compared to the case where they cannot be discharged. These two scenarios were also confronted with the case where only batteries are installed (named '0 EV') to verify the consequences of having or not EV parking. The graphs in Fig. 5 show some metrics obtained after a one-year simulation. The battery degradation cost considers a capital cost of 500 €/kWh [START_REF] Kim | Field study on operational performance and economics of lithium-polymer and leadacid battery systems for consumer load management[END_REF] with end-of-life when it loses 20% of its nominal capacity [START_REF] Li | Data-driven health estimation and lifetime prediction of lithium-ion batteries: A review[END_REF]. Remarkably, the French energy policy [START_REF]la réalisation et l'exploitation d'Installations de production d'électricité à partir d'énergies renouvelables en autoconsommation et situées en métropole continentale[END_REF] to financially encourage selfconsumption in small prosumers is considered in this technical-economic analysis. This policy is based on a reward-penalty mechanism to favour the internal load match and avoid grid energy injection. It provides a higher additional income for small annual maximum power injected and an elevated annual self-consumption rate. According to the results shown in Fig. 5, from the point of view of the BMG, the discharging of EVs implies a reduction in the annual electricity bill of 79 €/year. In this study, a time-of-used tariff of 0.09 €/kWh was used. Although the annual self-consumption rate was higher when allowing the EV discharging, the additional income was lower due to the increase in the maximum power injection. By comparing the degradation cost of batteries, the discharging of EV parking reduces the use of the building batteries pack, decreasing its degradation cost by 4 €/year. This is because the load shaving implemented by stationary batteries is partially covered by EV charging and discharging.

Therefore, the total savings when allowing the EV discharging -being equal to the sum of electricity and battery degradation costs minus the additional income -are 282 €/year. Compared to the total BMG expenses (more than 21587 €/year), these savings are minimal. Due to the power imbalance profile, EV schedule time and sizing of the battery pack, EVs can be rarely discharged. According to Table 3, EV discharging represents less than 2% of annual building energy consumption for 4 EVs.

From the perspective of the EV's owners, the discharging of their EV's batteries increases the degradation rate of EV's batteries. As shown in Fig. 6, the average capacity of EV's batteries (𝑄) at the end of the year is smaller when allowing discharging them than not allowing it. According to the website of Renault, the current price of batteries of Renault Zoe ® costs on average 00 € depending on the country. Taking this value to estimate the equivalent cost of discharging the EV's batteries, the additional loss of batteries' capacity of 5 mAh/year means 4.57 €/year (or 0.025 €/kWh) for each EV's owner. Considering the hypothesis that the BMG would refund the degradation provoked by the additional degradation cost of EV batteries, the BMG profit would be only about 143.72 €/year. Therefore, the differences between both sides when allowing or not discharging EV batteries are small compared to the annual building expenses. From the perspective of EV users, discharging their EV batteries may be a disadvantage because their batteries would be degraded faster than in normal operating conditions without contributing substantially to the performance of the BMG or the use of renewable energy. Fig. 5, also illustrates that having EV parking installed in the BMG increases the electricity expenses on average of 5 6.50 €/year. This is because, despite all, EVs are still a load that consumes energy. With the sizing of the BMG and the connection profile of EVs, the BMG must purchase electricity to charge its EVs, which increases the total electricity costs by 8%.

V. CONCLUSION

The proposed hierarchical control structure has proved effective to fully charge EVs before their departure time while promoting PV self-consumption. Compared to the uncontrolled strategy, the proposed BEMS increased by 3 percent point the annual self-consumption. Besides reducing the complexity of the controller design, the EVPA guaranteed EV's state-of-charge over 75% even when subjected to data prediction inaccuracies. Nonetheless, due to the raw net power imbalance, sizing of battery packs, and the daily connection and disconnection profiles of electric vehicles, the charging of electric vehicles from renewable energy is saturated to 9% of annual photovoltaic energy generation. Consequently, with the enlargement of the EV parking, the annual self-consumption rate is saturated to 72%. Electric vehicle parking also results in a considerable increase in electricity expenses, increasing the purchased energy by about 8% of the annual building consumption with 4 EVs, and 91% with 40 EVs. Additionally, the economic advantages of discharging EVs to promote self-consumption represents only 1.3% of the annual building expenses. From the point of view of EV's owners, the monetary reward may not be enough to encourage them to authorise the discharge since their batteries would be degraded faster without substantial impact on the use of renewables.

VI. ACKNOWLEDGEMENT

Fig. 1 :

 1 Fig. 1: Hierarchical building energy management system

Fig. 3 :

 3 Fig.3: Distribution of the state-of-charge of four electric vehicles just before disconnecting from the building microgrid.

Fig. 4 :

 4 Fig. 4: Sample days of power flow with 4 electric vehicles with data prediction errors with the proposed EVPA and the uncontrolled strategy.

Fig. 5 :

 5 Fig.5: Key performance indicators when four EVs are allowed (4 EVa) and not allowed (4 EVna) to be discharged, and when no EV exist (0 EV)

Fig. 6 :

 6 Fig.6: Comparison of the level of degradation of batteries when electric vehicles are allowed and not allowed to be discharged.

  . In this equation, 𝑄 𝐸𝑉 𝑛𝑜𝑚 is the nominal capacity of an EV, 𝑣̅ 𝐸𝑉,𝑘 is the average voltage of EVs connected at instant 𝑘, and 𝜂 𝑑𝑖𝑠 and 𝜂 𝑐ℎ are the batteries discharging and charging efficiency .

	𝐸 𝐸𝑉,𝑘 𝑚𝑖𝑛 = 𝑄 𝐸𝑉 𝑛𝑜𝑚 • 𝑆𝑜𝐶 𝐸𝑉 𝑚𝑖𝑛 • 𝑛 𝐸𝑉,𝑘 ≤
	𝐸 𝐸𝑉,𝑘 -	𝜂 𝑐ℎ •𝑇 𝑠 𝑣 ̅ 𝐸𝑉,𝑘	𝑃 𝐸𝑉,𝑘 𝑐ℎ -	𝑇 𝑠 𝑣 ̅ 𝐸𝑉,𝑘 •𝜂 𝑑𝑖𝑠	𝑃 𝐸𝑉,𝑘 𝑑𝑖𝑠 + 𝐸 𝑘 𝑎𝑟𝑟 -𝐸 𝑘 𝑑𝑒𝑝
	≤ 𝑄 𝐸𝑉 𝑛𝑜𝑚 • 𝑆𝑜𝐶 𝐸𝑉

𝑚𝑎𝑥

• 𝑛 𝐸𝑉,𝑘 = 𝐸 𝐸𝑉,𝑘 𝑚𝑎𝑥

  ), the stochastic arrival and departure of EVs are considered through the variables 𝐸 𝑘

	𝑎𝑟𝑟
	𝑑𝑒𝑝 , representing the energy arrived with new EVs and 𝐸 𝑘 𝑎𝑟𝑟 ) and the energy departure with EVs when connection (𝐸 𝑘 𝑑𝑒𝑝 ). Calculated through equations they are disconnected (𝐸 𝑘 (11) and (12) 𝐸 𝑘 𝑑𝑒𝑝 are estimated based on the total 𝑎𝑟𝑟 and 𝐸 𝑘 𝑑𝑒𝑝 ) and number of EVs plugged (𝑛 𝐸𝑉,𝑘 ), EVs departures (𝑛 𝑘 EVs arrivals (𝑛 𝑘 𝑎𝑟𝑟 ).
	𝐸 𝑘 𝑎𝑟𝑟 = 𝑛 𝑘 𝑎𝑟𝑟 • 𝑄 𝐸𝑉 𝑛𝑜𝑚 • 𝑆𝑜𝐶 ̂𝐸𝑉𝑠,𝑘 𝑎𝑟𝑟

:

  Summary of the EVPA module algorithm HMPC power reference is completely allocated, the Boundaries Definition state is implemented; otherwise, the Retry state is executed. Based on equations (15) and (16), the Retry is executed if there would be EVs fully charged or fully discharged, or if the shared power would be limited by the power rate boundaries (𝑃 𝑝𝑒𝑣 𝐼𝐷 𝑚𝑎𝑥𝐶ℎ and 𝑃 𝑝𝑒𝑣 𝐼𝐷 𝑚𝑎𝑥𝐷𝑖𝑠 ).Afterwards, the fourth and last step -named Power Boundaries Definition -is executed. In this step, the HMPC power boundaries for EV charging and discharging (𝑃 𝐸𝑉 𝑚𝑎𝑥𝐶ℎ and 𝑃 𝐸𝑉 𝑚𝑎𝑥𝐷𝑖𝑠 ) are calculated based on the estimated future SoC (𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 ,𝑘+1 ) and the power reference calculated in the Power Allocation step (𝑃 𝐸𝑉 𝐼𝐷 𝑑𝑖𝑠 and 𝑃 𝐸𝑉 𝐼𝐷 𝑐ℎ ). First, the future

	𝑃 𝐸𝑉,𝑘 𝑟𝑒𝑓 ≠ ∑ (𝑃 𝐸𝑉 𝐼𝐷 ,𝑘 𝑁 𝑃𝐸𝑉 𝑐ℎ 𝐼𝐷=1	+ 𝑃 𝐸𝑉 𝐼𝐷 ,𝑘 𝑑𝑖𝑠	)	= {	True ⇒ 𝑅𝑒𝑡𝑟𝑦 𝐷𝑒𝑓𝑖𝑛𝑖𝑡𝑖𝑜𝑛 False ⇒ 𝐵𝑜𝑢𝑛𝑑𝑎𝑟𝑖𝑒𝑠	(19)
	Therefore, in the Retry state, the EVs that would be fully
	charged or fully discharged by applying the power reference
	𝑟𝑒𝑓 through (15) and (16)) calculated in the previous step (𝑃 𝐸𝑉 𝐼𝐷 𝑎𝑣𝑎 to one, are identified by setting the Boolean Variable 𝛿 𝐸𝑉 𝐼𝐷 whereas all other EVs are identified to 𝛿 𝐸𝑉 𝐼𝐷 𝑎𝑣𝑎 = 0 .
	Additionally, the power to be reallocated is the difference
	between the initial power reference calculated by HMPC
	( 𝑃 𝐸𝑉,𝑘 𝑟𝑒𝑓 ) and the shared power that has already been well
	allocated, as expressed in (20). Subsequently, the Power
	Allocation step is reimplemented. This process is repeated
	until the condition of equation (19) is satisfied, or the number
	of retries surpasses a maximum threshold (𝑁 𝑟𝑒𝑡𝑟𝑦 𝑚𝑎𝑥 ).
	𝑃 𝐸𝑉,𝑘 𝑟𝑒𝑓 = 𝑃 𝐸𝑉,𝑘 𝑟𝑒𝑓 -∑(𝑃 𝐸𝑉 𝐼𝐷 𝑐ℎ + 𝑃 𝐸𝑉 𝐼𝐷 𝑑𝑖𝑠 )	• (1 -𝛿 𝐸𝑉 𝐼𝐷 𝑎𝑣𝑎 )	(20)
		𝐼𝐷
	SoC at 𝑘 + 1 of each plugged EV is calculated through (21).
	Afterwards, the EV power boundaries are calculated using
	equations (22) and (23) and transmitted to HMPC.
	𝑚𝑎𝑥𝐶ℎ and Remarkably, the EV power boundaries (𝑃 𝐸𝑉 𝑃 𝐸𝑉 𝑚𝑎𝑥𝐷𝑖𝑠 ) are the sum of maximum power rate that each EV
	can support for the next hours.
	𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 ,𝑘+1 = 𝑆𝑜𝐶 𝐸𝑉,𝑘 -𝑃 𝐸𝑉 𝐼𝐷 𝑑𝑖𝑠	𝑇 𝑠 𝑇𝑀𝑃𝐶 𝑣 𝐸𝑉 𝐼𝐷 𝜂 𝑑𝑖𝑠	-𝑃 𝐸𝑉 𝐼𝐷 𝑐ℎ 𝜂 𝑐ℎ 𝑇 𝑠 𝑇𝑀𝑃𝐶 𝑣 𝐸𝑉 𝐼𝐷	(21)
	𝑃 𝐸𝑉,𝑘+1 𝑚𝑎𝑥𝐶ℎ = ∑ max (𝑃 𝐸𝑉 𝐼𝐷 𝑚𝑖𝑛 ; 𝐼𝐷	𝑚𝑎𝑥 𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 ,𝑘+1 -𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 𝜂 𝑐ℎ • 𝑇 𝑠 𝑣 𝐸𝑉 𝐼𝐷 ⁄	)	(22)
	𝑃 𝐸𝑉,𝑘+1 𝑚𝑎𝑥𝐷𝑖𝑠 = ∑ min (𝑃 𝐸𝑉 𝐼𝐷 𝑚𝑎𝑥 ; 𝐼𝐷	𝑚𝑖𝑛 𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 ,𝑘+1 -𝑆𝑜𝐶 𝐸𝑉 𝐼𝐷 𝑇 𝑠 (𝜂 𝑑𝑖𝑠 𝑣 𝐸𝑉 𝐼𝐷 ) ⁄	𝑑𝑖𝑠𝐴 ) • 𝛿 𝐸𝑉 𝐼𝐷

TABLE 1 :

 1 TECHNICAL SPECIFICATION OF THE BUILDING MICROGRID.

	Component	Technical Description
	Photovoltaic panels	Annual energy generation: 131 MWh (100 kWc)
	Building load	Annual energy consumption:307 MWh
	Li-ion batteries	Nominal capacity: 167 Ah
		Maximum power rate: 60 kW
	EV parking (Zoe of	Maximum power rate: 7 kW (slow mode)
	Renault ® )	Nominal capacity (𝑄 𝐸𝑉 𝑛𝑜𝑚 ): 130 Ah

TABLE 2 :

 2 ONE-YEAR SIMULATION RESULTS TO EVALUATE THE ROBUSTNESS

	OF DIFFERENT CONTROL STRATEGIES
	Metrics	Uncontrolled.	Hierarchical EMS
		Ideal	Realistic	Ideal	Realistic
	Self-consumption	68%	67%	71%	70%
	Coverage rate	27%	27%	30%	30%
	Charge EVs from PVs	1.1%	1.8%	12.2%	13.7%
	Charge EVs from	23.6%	28.2%	14.9%	15.0%
	building storage
	Charge EVs from grid	75.3%	70.0%	72.9%	71.3%

Obs: Building microgrid with 4 Electric Vehicles and Li-Ion batteries

TABLE 3 :

 3 ONE-YEAR SIMULATIONS WITH A DIFFERENT NUMBER OF ELECTRIC VEHICLES USING THE PROPOSED HIERARCHICAL EMS.

	Metrics	0	4	20	40
		EV b	EV b	EV b	EV b
	Self-consumption (%)	69	71	72	72
	Coverage rate (%)	29	30	28	25
	Grid energy import a	217	234	314	416
	Grid energy injection a	41	38	37	37
	Energy to charge EVs a	0	27	127	249
	-from grid a	0	19	114	237
	-from PV panels a	0	4	6	6
	-from batteries a	0	4	7	6
	Energy discharged from EVs a 0	5.4	18.3	32.7
	a Annual values in MWh		b With Li-ion batteries

The authors would like to thank Region Nouvelle Aquitaine (Agreement: AAPFO424953) for their financial support.