**1. 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) systems, EV/V2G, and locally produced PV power can help in providing this power and therefore can reduce the grid stresses while at the same time increase the renewable energy consumption. However, getting the most out of these mutual benefits requires complex charging algorithms based on load and PV power forecasts.

In this paper, a real-time building smart charging algorithm is presented, which, based on forecasts and Li-ion battery degradation, minimizes the operational costs of a PV-EV-BES-HP system while at the same providing a supporting role in the future smart grid by ancillary services and demand-side management.

### *1.1. Literature Study*

The most straightforward control scheme of any EV/BES-PV system is to use a rule-based control scheme, where the current state of the system determines the next action, such as that presented in [6,7]. However, the effectiveness of rule-based schemes is limited, as future supply or demand is not anticipated and their operation is not close to optimal. Therefore, these systems are not investigated further. In [8–13], residential building-based smart charging systems are presented in which the energy costs are minimized. In [8,9], a time-series model is used to predict PV power and residential electrical demand; however, a coarse resolution of 1 h is used, which can lead to significant forecasting errors. In [9,10], also thermal storage and shiftable appliances are taken into account. In this study, these are considered non-flexible due to the low amount of flexibility which can be obtained and the high amount of comfort which is compromised. In [14], a mixed-integer linear programming problem that minimizes the charging costs with 30 min time steps is presented. However, forecasts or battery degradation costs are not taken into account. A hierarchical distributed smart charging station is proposed in [15]. Here, the individual systems try to stabilize their average available capacity of the battery storage bank, while the objective of a single EV is to maximize their charging power. Also, here, no regard for forecasting or degradation is taken into account. In [16], first, a two-stage optimization problem day-ahead scheduling is performed based on stochastic programming. Next, a deterministic optimization is performed in a moving horizon. However, the accuracy of a day-ahead forecast using a one-hour resolution and, therefore, the effectiveness of the optimization is limited. A real-time stochastic programming approach is presented in [17], which can be used to overcome the uncertainty of the PV forecast. Also, in [18], a real-time control is incorporated in an algorithm that tries to maximize the customer satisfaction-involved operational cost while balancing the supply and demand by scheduling EVs, battery storage, grid power, and other flexible loads. Battery degradation is not taken into account here. A range anxiety approach is taken in [11], which penalizes low state of charges (SoC). Here, battery ageing is calculated based on energy throughput. However, no regard has been given to PV/load forecasting. Also, in [12], residential energy costs are minimized with battery degradation taken into account. However, optimized using a one-hour resolution assuming perfect forecasts without adjusting for errors as a result comprising the effectiveness of the optimization. In [19], a method where the charging of EVs at a parking station is controlled based on real-time electricity prices and PV forecast is presented. Here, battery degradation costs are taken into account using a levelized cost of energy approach.

Another important aspect of EV-PV integration in the future smart grid is the provision of ancillary services based on EV storage. This is investigated in [20–27], where fleets of EVs are used as storage and where the scheduling of ancillary services or demand-side managemen<sup>t</sup> is optimized. However, all of these studies do not take battery/EV degradation into account, and therefore, a significant part of the operating costs is neglected. In addition, scheduling will be skewed after a while when the actual capacity is smaller than taken into account. In [28], the operational costs of V2G are calculated using a simplified battery degradation calculation but are not minimized by the optimization. In [29], an accurate BES degradation model incorporated in a dynamic programming problem is used to optimize the power flows in order to minimize the costs in a PV-EV-BES nano-grid. However, only one BES stress factor is taken into account at the same time. Furthermore, no V2G and no degradation of 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.
