Real-Time Building Smart Charging System Based on PV Forecast and Li-Ion Battery Degradation

: This paper proposes a two-stage smart charging algorithm for future buildings equipped with an electric vehicle, battery energy storage, solar panels, and a heat pump. The ﬁrst stage is a non-linear programming model that optimizes the charging of electric vehicles and battery energy storage based on a prediction of photovoltaïc (PV) power, building demand, electricity, and frequency regulation prices. Additionally, a Li-ion degradation model is used to assess the operational costs of the electric vehicle (EV) and battery. The second stage is a real-time control scheme that controls charging within the optimization time steps. Finally, both stages are incorporated in a moving horizon control framework, which is used to minimize and compensate for forecasting errors. It will be shown that the real-time control scheme has a signiﬁcant inﬂuence on the obtained cost reduction. Furthermore, it will be shown that the degradation of an electric vehicle and battery energy storage system are non-negligible parts of the total cost of energy. However, despite relatively high operational costs, V2G can still be cost-effective when controlled optimally. The proposed solution decreases the total cost of energy with 98.6% compared to an uncontrolled case. Additionally, the ﬁnancial beneﬁts of vehicle-to-grid and operating as primary frequency regulation reserve are assessed.


Introduction
In 2015, transportation accounted for 19% of global energy consumption, almost all of which was powered by fossil fuels (including electric vehicles (EVs) and plug-in hybrid EVs) [1]. Fortunately, the cost of EVs is drastically reducing and their market share is increasing. However, for EVs to be truly sustainable, they have to be charged from a sustainable energy source. Photovoltaïc (PV) solar energy is now being investigated as a primary energy source for EV charging due to the synergies which exist between EV and PV. As both are inherently DC, directly charging an EV from PV power increases charging efficiency and charger density. Furthermore, an EV in combination with vehicle-to-grid (V2G) can act as a storage, can reduce the intermittent character of PV, can provide ancillary services, and can act as a primary energy source for other loads [2,3]. Finally, charging an EV from local PV power reduces the stress which EV charging is imposing on the future grid.
Another significant part of global energy consumption is the built environment; In [4,5] it is stated that the built environment emits up to 40% of all global greenhouse gasses. In the future, the phasing out of natural gas will increase the electrical demand of buildings as heat pumps (HPs) will be used for building heating. However, often, the existing distribution grid is unable to provide this increase in electrical demand caused by HPs and EVs. Luckily, Battery Energy Storage (BES) the EV itself are taken into account. Summarizing the review, it can be concluded that the operational costs of EV/BES are often neglected. PV/load forecasts are only occasionally performed, often in a coarse resolution. Ancillary services are usually only taken into account for larger fleets of EVs, and most papers do not take into account a real-time control scheme. Due to the negligence of costs, coarse resolutions, and lack of error handling mechanisms, the effectiveness of the papers mentioned above is limited.

Contribution
The main contribution of this study is the combination of several components which previous studies have not combined, together maximizing the effectiveness and accuracy of the proposed solution. This is done by integrating the following: • a Lithium-ion degradation model used to accurately assess and optimize the operational costs of EV and BES. It will be shown that the degradation costs are equal to 68% of the total grid electricity costs and are therefore nonnegligible; • a two-stage model predictive controller consisting of an optimal charging algorithm and real-time controller implemented in a moving horizon control scheme to compensate forecasting and estimation errors, such as PV power or SoC estimation, at a one-minute resolution. It was found that using a moving horizon window and real-time control scheme furthers reduces the costs by 9.7% compared to the reduction in cost of only optimal scheduling; • a forecast of PV power and load demand in 15-min resolution up to 48 h ahead. Even using advanced irradiance forecasting, root mean square errors can be up to 45% [30], showing the necessity of a model predictive controller; and • Smart grid implementation in order for the system to be integrated into a future smart grid, allowing for power curtailment and optimization of available reserved capacity for primary frequency regulation, further reducing the cost by 7.8%.
Using the above components, the actual cost of energy can be accurately assessed and minimized based on forecasts and EV/BES degradation, after which possible errors are compensated and charging can be controlled up to a resolution of one minute while taking into account ancillary services to help increase the EV and PV penetration rate.

Paper Organization
The paper is organized as follows: In Section 2, the smart charging system and its place in the smart grid paradigm will be elaborated, after which the integration of forecasts will be presented in Section 3. The control scheme will be presented in Section 4. Finally, the obtained results are presented in Section 5.

System Description and Smart Grid Implementation
The proposed smart charging system consists of two stages: first, an optimization algorithm finds the optimal charging strategy based on a 15-min resolution. Secondly, a real-time scheduling algorithm operates in real-time within the optimization timesteps. This is integrated into a moving horizon window used to take care of forecast and estimation errors, such as PV/load power, EV arrival times, SoC estimation, etc. The smart charging system is designed to control a multi-port power converter that integrates a PV maximum power point tracker (MPPT), bidirectional BES charger, bidirectional EV charger, and grid-connected inverter on the same DC-link [31,32]; see Figure 1. By connecting these on the same DC-link, several inverting/rectifying power steps can be omitted, achieving higher efficiency and power density. All specifications are given in Table 1; the voltages of the EV and BES are based on [33,34]. Since the inverter is maintaining the power balance on the DC link, it does not require any additional setpoints from the smart charging system. Furthermore, a heat pump connects to the AC side for building heating and tap water. This study assumes that the state-of-charge (SoC) of the BES and EV are known according to the ISO 15118 standard. Finally, as part of the future smart grid, a Smart Grid Operator (SGO) is taken into account, which acts as an aggregator and intermediary between the ancillary services, wholesale market, and small-scale prosumers. This SGO provides the real-time electricity price (λ buy/sell ) as well as up/downregulation prices (λ up/dwn ). As a result, the smart charging algorithm can take place in regulatory services and can take this into account in the optimization. Finally, the SGO can also limit the grid power of the system as part of a demand-side management program, for which the user will be financially compensated afterwards.

Second-Life Batteries
Due to the increasing amount of EVs, new markets for second-life EV batteries emerge as EV batteries often have 70-80% remaining capacity left at the end of their EV lifetime [35]. These second-life batteries are then repurposed for stationary applications such as grid reinforcement or demand response systems. This reduces the cost of EV/BES ownership as well as increases the sustainability of the Li-ion batteries. In this study, the second-life value of both the EV and the BES is taken into account and used to assess the operational costs of EV/BES ownership more accurately. Additionally, in [36], it was found that second-life battery performance and state-of-health estimation is strongly influenced by its first-life performance. This motivates the use of a battery degradation model, which minimizes and monitors the degradation such that the performance of the battery in its second-life is increased and more easily assessed.

Materials and Methods
The proposed smart charging algorithm can be divided into three subsection: 1. forecasting, 2. optimal scheduling, and 3. moving horizon and real-time control scheme.

Forecasting
Solar PV and load demand forecasts are required in order to schedule the charging of EV and BES accurately. The forecasting of PV energy can be divided into three categories: statistical data-based methods such as Auto Regressive Integrating Moving Average (ARIMA) [37,38] and machine learning based methods such as neural networks. The disadvantage of the methods mentioned above is that their accuracy solely relies on historical data, as there are no environmental inputs. The third category is a hybrid method based on historical data as well as weather data and satellite images. This study uses the solar radiation forecasts of the royal dutch weather institute. The advantage of this is that the computation of the forecasts is being performed outside the moving horizon controller and is based on previous data, satellite images, weather prediction modelling, and radiative transfer modelling [39]. The forecast is a combination of a short-term forecast (0-6 h) (SEVIRI) and a long-term forecast up to 48 h (HARMONIE) and includes Global Horizontal Irradiance (GHI) and Direct Normal Irradiance (DNI) [30]. In combination with the moving horizon control, good accuracy on the short term can be obtained, while at the same time, scheduling up to 48 h ahead can be performed. Then, using the approach presented in [32], the produced PV power can be calculated based on the orientation of the solar panels. Forecasting the load demand is done based on an aggregated residential profile obtained from [40]. Here, both appliance and heating demand are taken into account. An example of the forecasted and actual powers is shown in Figure 2. Even though the forecasted trend of PV power is accurate, sudden clouding can still cause significant errors of several kilowatts. Similarly, for the load demand profile, its highly stochastic nature is not captured by the aggregated data. However, daily and seasonal variations are incorporated. Due to the existence of these errors combined with a relatively coarse resolution of 15 min in most optimal scheduling problems, significant deviations from the actual optimal solution would occur. This motivates the use of a real-time control scheme.

Optimal Charging Algorithm
In this section, the optimization model is discussed. All variables are denoted and described in the nomenclature at the end of this article. The optimal charging algorithm's goal is to find the optimal charging schedule based on the forecasts of load and PV while taking into account battery degradation and ancillary services. The main contribution of the proposed optimization problem is the use of a Li-ion battery degradation model. Because of the good balance of power density, energy density, and lifetime, Nickel-Manganese-Cobalt (NMC) based batteries are being used for both vehicle and stationary applications [41]. Therefore, the same ageing model can be used for both the stationary and vehicle battery. Similarly, the costs of V2G, regulatory services, and degradation can be determined based on the actual operating conditions. Furthermore, since the model is included in the objective, the solver will minimize the degradation and the resulting costs. The non-linear behaviour of these cells makes the optimization problem a non-linear programming (NLP) model. The problem was solved using the CONOPT solver (part of BARON/Antigone [42]) using the generic algebraic modelling system (GAMS) platform on a PC with 3.6 GHz, Intel Xeon 4 core and 16 GB RAM.

Objective Function
The objective of this optimization is to minimize the total cost of energy. Here, the total cost of energy C total is made up out of battery energy storage costs C BES , electric vehicle costs C EV , PV energy costs C PV , grid energy costs C grid , and regulatory revenue C reg . Mathematically, this can be expressed as follows: The battery costs are operational costs, which are determined by assessing the remaining value of the degraded battery. This is done by calculating the degraded capacity ∆E tot BES and by subtracting this from the initial capacity E max BES , both in kWh. Next, the remaining value per kWh, V BES in euro/kWh, is calculated according to the model presented in [43]. The decay of V BES versus the remaining capacity is shown in Figure 3. This study assumes that the battery is still in its first life, which ends at 80% remaining capacity, and that the value at the start of second-life V 2nd BES equals 50% of a new BES: [43]. V BES can than be calculated according to the formula presented in Equation (2). The costs are then equal to the difference between a new BES and the degraded BES as shown in Equation (3). The costs related to the EV are related to the degradation costs of charging and V2G. A similar notation of variables as for the BES is used. Here, the degradation due to driving is not taken into account, as it is not under the control of the smart charging system. Furthermore, it is assumed that the 2nd life of an electric vehicle battery starts at 80% remaining capacity at 50% of its original value per kWh [43]. This is described in Equations (4) and (5).
In this study, the cost of PV energy is not assumed to be zero, to take into account the installation and investment costs of the PV system, or to simulate a contractual power purchase agreement. These costs are levelled per kWh to make them independent of the simulation time, without neglecting the related costs. Here, λ PV = 0.03 e/kWh [12] is assumed. The costs for PV energy are then determined according to the following: Here, P PV (t) is the generated PV power, ∆t is the simulation timestep, and λ PV is the levelized cost of PV energy. The next part of the objective function is the revenue obtained by acting as a frequency containment reserve (FCR) and demand-side management. Here, it is assumed that an SGO acts as an aggregator and mediator between the frequency regulation market and the prosumer, aggregating several flexible systems such that the combined power meets the minimum power requirements for the FCR market. Here, the revenue is obtained by reserving a part of the available power capacity for primary frequency regulation. The up/downregulation prices are λ up andλ dn , respectively. Based on these prices, the operational costs, and the current demand, the optimization will determine how much of the available capacity will be reserved for frequency regulation. The revenue obtained from this is calculated according to the following: Here, f c is the maximum forecasting error; this is taken into account to limit the error between actual and reserved capacity caused by forecasting errors. Due to the moving horizon control, a good short-term accuracy can be achieved. However, as errors will still occur, compensation factor C comp is introduced such that any difference in revenue caused by differences in actual and reserved capacity or in scheduled and used capacity is compensated using C comp . This makes C comp dependent on the bidding process in the regulation market. Therefore, it is assumed that the smart grid operator calculates this compensation factor based on the actual operation. Additionally, C comp could be the compensation obtained for curtailing PV power as part of demand-side management. Here, C comp could be equal to the curtailed energy multiplied by the energy price. Next, η inv/ch are the efficiencies of the inverter and BES/EV charger, respectively. Finally, P up/dwn reg (t) are the reserved capacities for regulation. The calculation of these capacities will be explained later in Section 4.2.2.6. The final part of the objective function is the grid energy cost. In this study, a dynamic pricing tariff is used, where the selling price λ sell (t) is 10% lower than the buying price λ buy (t). This is done to simulate a future environment where electricity prices are a function of demand and supply, optimizing costs and separating buying/selling grid energy results in energy being taken out of the grid when demand and price are low while the energy fed back to the grid is fed in during a time of high demand and high price. The calculation of grid energy costs is shown in Equation (8).
Here, P buy/sell grid (t) are the powers drawn and fed from the grid, respectively.

Lithium-Ion Degradation Model
The battery degradation model is valid for both the EV and the BES, and therefore, the identifier X = EV = BES is used. In order to calculate the capacity lost per time step (∆E tot X (t)), the battery degradation model presented in [44] is used. The model is semi-empirical based on 18650 Nickel-Manganese-Cobalt (NMC) cells. It takes into account temperature, current rate (I cell X (t)), and ampere-hours processed (I cell X (t)δt). In this study, the cell temperatures are assumed constant at 35 • C, assuming that the EV has a battery temperature control system and because the inside ambient temperature setpoint of the heat pump varies between 18 • and 20.5 • C [45]. A distinction between cyclic and calendar ageing is made, denoted as ∆E cycle X (t) and ∆E cal X (t). Since calendar ageing is mostly dependent on time and temperature [44] and cell temperature is assumed constant, the equation can be simplified to a constant degradation per time step. Here, a minimum lifetime of 5 years is assumed. This is shown in Equation (12).Furthermore, the model is based on the behaviour of a single cell. Therefore the EV/BES power needs to be scaled into the voltage and current of a single cell. To do this, the open-circuit voltage of an NMC cell is used, which can be described by the curve fitted equation shown in Equation (9) [46]. Here, SoC x (t) denotes the state of charge of x at time t. The resulting curve is shown in Figure 4. Furthermore, it is assumed that N parallel X by N series X of these cells are placed in parallel and series respectively, such that the total open-circuit voltage V oc,X resembles existing EV/BES systems [33,34].
Then, using the calculated cell voltage and current from Equation (9) and (10), the lost capacity per cell can be calculated according to Equations (11) and (13) [44]. Note that the model presented in [44] calculates the percentage of lost charge in ampere hour and is therefore multiplied with E max BES 100 in order to get the actually lost capacity. The values of the curve fitted parameters in Equations (9)-(13) can be found in Table 2.

Battery Energy Storage Constraints
The BES power P BES (t) is limited between [−10, 10] kW. Additionally, the maximum power P max BES (t) is SoC dependent such that the maximum power drops linearly below a SoC of 10% (D dis = 0.1) and above a SoC of 80% (D ch = 0.8), representing the constant-current constant-voltage regions of a battery. This is ensured using Equations (14)- (20). The round-trip efficiency is considered constant over power and lifetime and is equal to 95 % [34]. Therefore, the efficiency of a single charge/discharge cycle equals η ch/dis = √ 0.95 = 0.975. Due to this efficiency, the model recognizes the loss of energy and therefore prevents both P neg BES (t) and P pos BES (t) from having nonzero values at the same time.
In the above constraints as well as all the following constraints, the superscripts "max", "min", "pos", "neg", and "rated" declare the maximum allowable, minimum allowable, actual positive, actual negative, and rated powers.The energy stored inside the BES E BES (t) can then be calculated according to Equation (21). Here, the BES capacity is fixed for t = 1 and t = t f inal at capacities BES , respectively, in order to have a fair comparison between costs.
Furthermore, the SoC of the BES is calculated using Equation (22). Here, E limit BES (t) is a variable which represents the actual maximum capacity at time t, which equals the initial maximum capacity E max BES minus the capacity lost by cycling for that time step ∆E BES (t). This is modelled using Equation (23) and Equation (24).

Electric Vehicle Constraints
The electric vehicle constraints are given in Equations (25)- (36), where the constraints up to Equation (34) are similar to the BES constraints. The electric vehicle is assumed to be unavailable from t depart = 08:00 till t arrive = 18:00 during the day; this is denoted by the binary parameter EV av (t), which equals 0 for t depart ≤ t ≤ t arrive . These departure and arrival times are based on the distribution, as presented in [47]. During that time, it is estimated that the EV is commuting between work and home, where a single trip is 30 km with an efficiency of 15 kWh/100 km [48], resulting in a 9 kWh decrease in charge at arrival; note that the arrival time and charge are only estimations and that possible errors will be compensated after arrival as a result of the moving horizon window.
Finally, the user can state a minimum departure charge E depart and departure time t depart , which ensures that the EV always has enough charge at the time of departure. This is modeled using Equation (36):

Power Balance Constraints
For the given system (Figure 1), two power balances exist: 1. on the DC link of the multi-port converter. Here, a positive inverter power P inv (t) equals feeding power to the grid. 2. The second power balance exists on the AC side between the inverter and the meter. This is modeled using Equations (37) and (38).
Here, the total load P load (t) consists of the load from all appliances in the building P appl (t) and the power required for heating P heat (t), in the form of a heat pump. In this study, both P appl (t) and P heat (t) are considered non-flexible.

Grid Constraints
The resulting grid power P grid (t) differentiates between positive and negative grid powers since both have different prices. This is done using the efficiency η cable , which models the power loss in the cable between the meter and converter. This efficiency is assumed to equal 99%. However, more importantly, it ensures that the P buy grid (t) and P sell grid (t) do not have nonzero values simultaneously, as the efficiency loss is recognized. This allows for grid power arbitration without the use of binary variables, drastically increasing the solving time. Here, P max grid is the maximum power of a 3-phase 25A connection.

Regulation Market Constraints
Part of the objective function is the revenue obtained from reserving the capacity for primary frequency regulation. Here, it is assumed that the system is part of a smart grid as described in Section 2. Using Equations (43)- (47), it is ensured that the maximum available capacity for regulation does not exceed the actual maximum capacity in the system. Here, it is important to note that the maximum available EV/BES capacity is SoC dependent. Therefore, the available up/down capacity per converter port P x up/dwn (t) (x = EV/BES/PV) is denoted using P max/min In case of symmetric reserve offers, Equation (54) should also be used.

Inverter Constraints
To account for the efficiency of the inverter, the inverter power is also split into positive and negative parts. The inverter efficiency is assumed equal for both directions of power: 97% and over the entire power range [24].

Photovoltaic Constraints
As part of demand-side management as well as for cases with a negative feed-in tariff, it should be possible to curtail PV power. Therefore, in order to allow PV power curtailment, Equation (58) is introduced. Here, the efficiency of the maximum power point tracker is assumed to be η mppt = 98% [49].
Here, P f orecast PV (t) denotes the forecasted PV power. This concludes the optimization model section.
In the next section, the proposed real-time control is discussed.

Moving Horizon Window and Real-Time Control
In Section 4.2, the optimal charging algorithm is discussed. The goal of the optimal charging algorithm is to find the optimal charging schedule within a 24-h optimization window while anticipating future demand and supply based on forecasts and taking into account battery degradation, and primary frequency regulation reserve. However, as shown in Figure 2, the resulting forecasting errors can still be in the range of several kWs. To minimize the effect of these errors, a moving horizon model predictive controller is implemented, which reoptimizes every 15 min (i.e., one optimization timestep). Additionally, a new forecast is obtained every hour to improve accuracy. To compensate for the errors within these 15-min timesteps, such as PV power, SoC estimation, and EV time of arrival, a real-time control scheme is implemented. Here, a rule-based control scheme is implemented such that it can act almost instantly. It should be noted that the real-time control only deals with the errors on top of what is optimally scheduled. For example, if the battery is directly charging from PV power in the optimal solution but the PV power turns out to be less than forecasted, the battery power can be changed accordingly. If no real-time control is implemented, this error needs to be compensated using grid power to maintain the power balance on the DC-link inside the multi-port converter, which could lead to nonoptimal solutions. Figure 5 shows the flowchart of the moving horizon control and the real-time control scheme. First, the irradiance forecasts are obtained, and the resulting PV power is calculated. Then, after the optimization, the output at t = 1 is saved and the sample rate is increased 15 times, such that the resolution is now one minute. The interpolated variables are indicated with index k. Furthermore, superscripts f c and act denote the forecasted and actual powers, respectively. In practice, the resolution can be as small as computation time allows to get actual real-time operation. The new real-time charging schedule is determined based on the amplitude of the error, the available EV/BES power, and the current electricity price. The error is calculated according to Equations (59)-(61).
Here, a positive error means an excess of power. For example, when the actual PV power is higher as forecasted (i.e., ∆P PV (k) > 0) while the actual load is lower as anticipated (i.e., ∆P load (k) < 0), the resulting error is positive P error (k) > 0. Next, the power limitations of the EV/BES converter at time k are determined based on power rating, SoC, and power balance inside the multi-port system. This is done using Equations (62)-(65). A rule-based control scheme then determines how the error should be compensated based on P error , the power limitations, current electricity price, and the mean electricity price calculated according to Equation (66), as shown in Figure 5. The goal of the real-time control scheme is to prevent feeding in power to the grid at times of low electricity prices or drawing power during high electricity prices. For example, when the error is positive (meaning an excess of power) and the electricity price λ buy is above average (λ mean ), the power is fed to the grid. If the price would be below average, the control first checks whether the BES can absorb the power and, if not, whether the EV can absorb the power; if both are not able to absorb the excess power, it is fed to the grid. After the real-time powers have been calculated, the actual degradation is calculated and the corresponding variables are adjusted. This will then be used for initializing the next optimization instance. P max,neg BES (k) = max 0, min P max BES , P max,pos BES (k) = max 0, min P min BES , P max,neg EV (k) = max 0, min P max EV ,

Use Case and Price Mechanism
The system specifications can be found in Table 1 above. The proposed optimal control scheme can be applied to any building with an EV, solar panels, heat pump, and BES. In this study, a residential building has been chosen as a use case. The building appliance load is obtained from a Dutch distribution system operator and represents a building with a medium to high demand. Both heating and appliance loads are assumed to be non-flexible such that no compromise is given to the user. The power profile of the heat pump is interpolated hourly data obtained from a study performed by the Dutch Organization for Applied Scientific Research [45]. Here, a medium isolated residential building is used with an inside temperature setpoint that varies between 18 • C and 20.5 • C during night and day, respectively. It is assumed that a time-varying electricity price is obtained from the SGO. The price signal is equal to the Amsterdam Power Exchange market [38,50] only averaged around 0.20 e/kWh, see Figure 6. Additionally, up/downregulation prices λ up/down are obtained from the SGO and shown in Figure 7. The model has been formulated such that it can operate with any kind of regulation market. In this case, the German primary frequency control market was chosen because it resembles the Dutch frequency control market. The German Frequency Regulation market is a symmetrical market, so both up-and downregulation are equally priced. Figure 7 displays the prices obtained for every week in 2018 [51].

Results and Discussion
The results for summer and winter days are shown in Figures 8-11, respectively. Here, the electricity buying price and forecasted and actual PV/load powers are included as well. From both Figures 8 and 10, it is clear that the optimal charging stage trades energy in between times of high and low prices. Similarly, it decides when to store PV energy and when to feed it back to the grid. During winter, the energy demand is much higher, mainly because of the increased heating demand. Additionally, the PV production is much lower and, therefore, less energy is fed to the grid. Without an appropriate control scheme, the BES would only be used in case of excess PV energy, therefore resulting in poor utilization of the BES. However, the proposed model still fully utilizes the available BES capacity in order to reduce the cost of energy. This is also shown in Figures 9 and 11. The EV is charged at night above the required departure charge of 50 kWh, such that it can utilize V2G when prices are high in the morning and again in the evening up to the point where prices are low again at the end of the day. Note that the usable EV capacity is not completely utilized, as the inverter power rating limits the possible power exchanged with the grid, whereas outside the instances of peak/valley prices, the difference between feed-in and retail price is probably not enough to overcome the additional losses caused by the degradation of charging at higher powers. The role of the real-time control scheme can be seen in Figure 8; as PV forecasting errors occur, the algorithm decides whether to use the BES, EV, or grid to compensate for these errors. The grid is used for positive errors (excess of power) and high prices, while the BES/EV is used when errors are positive but prices are low (if possible to store energy) and vice versa for high prices and negative errors. Finally, the effect of the degradation model is seen by the peak powers of the EV/BES. Both are rated at 10 kW. However, their powers only exceed the [−6 kW, 6 kW] range at 3.44% of the time (at 1-min resolution).

Comparison
From the literature review presented above, it can be concluded that most of the existing studies only discuss the optimal scheduling of EV/BES charging. However, within a 15-min forecasting resolution, large forecasting errors can occur due to the fast changing intermittent character of PV power. Additionally, other estimations such as t arrival can lead to more errors. Therefore, a moving horizon window including real-time control scheme is an important part for a smart charging algorithm, as errors are compensated and the optimization is iterated. In order to assess the effectiveness of all the different components, several case studies are performed over a half-year period: • case 1: Uncontrolled case (only EV, PV, and load) • case 2: Proposed optimal and real-time control scheme • case 3: Proposed optimal control and error compensation using grid power • case 4: Proposed optimal and real-time control scheme without V2G. • case 5: Proposed optimal and real-time control scheme without up/downregulation.
Here, it is assumed that a half-year simulation period is enough to capture all seasonal variations and that the forecasting error f c = 0 in order to assess the maximal potential of acting as a FCR. Furthermore, the moving horizon control will operate with a 24-h window in a 15-min resolution. The first uncontrolled case consists only of a PV installation, EV charger, and load. Here, it is assumed that the EV starts charging upon arrival with a 3 kW charger for 3 h to meet its daily demand. The second case is the complete proposed control scheme. The third case is similar to having only an optimal scheduling algorithm; here, all deviations from the obtained optimal solution are compensated using grid energy. The fourth case does not utilize V2G, and the fifth case does not take into account a primary frequency regulation reserve revenue. Figure 12 shows the resulting grid power for use case 2 and 3. Here, case 3 is comparable with having only an optimal control scheme (no real-time control). It can be seen that the errors are dealt with differently, in the end, increasing costs. In Figure 13, the total cumulative costs for every use case over a half year period is shown. Using the proposed control scheme (case 2), the total costs can be reduced by 98.6% compared to the uncontrolled case. A breakdown of all cost components is shown in Figure 14 and Table 3. Here, it can be seen that the optimized EV and BES degradation costs for case 2 are still equal to 91.87 euro and 64.6 euro, respectively. Similarly, the total cost of PV energy equals 168.15 euro. From this, it can be concluded that all these costs are a nonnegligible part of an objective function when minimizing the total cost of energy in an EV-PV-BES-HP system. However, although these costs are relatively high, from Figure 13 and Table 3, it can be concluded that V2G still is a cost-effective method for storing renewable and demand-side management, as the revenue obtained from trading energy exceeds the costs of degradation. Furthermore, it can be seen that the EV charging costs of case 1 are actually the lowest. This is because the average charging power for case 1 is lower compared to the other cases, resulting in lower degradation, however, resulting in more grid electricity costs.   Besides operating as a primary frequency regulation reserve, the smart charging algorithm is also capable of power curtailment. For example, when the smart grid operator foresees an over-voltage occurring in the near future, it can choose to limit the grid feed-in power of the system. An example of this is shown in Figure 15. Here, the SGO reduces the maximum allowable feed-in power to 5 kW between 09:30 and 18:00. A comparison with the same day without power curtailment is shown in Figure 16.

Conclusions
In this paper, a building smart charging algorithm was presented for a multi-port system integrating EV, PV, BES, and a HP. Here, the HP and appliance load were assumed fixed. Then, based on forecasts of PV production and load, the smart charging algorithm minimizes the total cost of energy incorporating grid electricity costs, PV investment and installation costs, EV/BES operational costs, and revenue obtained from operating as primary frequency regulation reserve. It has been shown that the proposed algorithm is very effective as it reduced 98.6% of the total cost of energy compared to an uncontrolled EV-PV-HP case. Additionally, the potential of V2G and the importance of forecasting error handling using a real-time moving horizon control scheme are discussed. Finally, it has been shown that EV/BES degradation costs as well as PV investment/installation costs are nonnegligible parts of an objective function which tries to minimize the total cost of energy in an EV-PV-BES-HP system. Funding: This research was funded by the FLEXgrid project, part of TKI urban energy, with contributions from Stedin, Alfen, and Power Research Electronics.

Acknowledgments:
The authors would like to acknowledge the project partners at Power Research Electronics, Stedin and Alfen, and the GAMS support team for their prompt responses and help in the project.

Conflicts of Interest:
The sponsors had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript; or in the decision to publish the results.

Abbreviations
The following abbreviations are used in this manuscript:       [18]