**7. 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.

**Author Contributions:** Conceptualization, W.V., G.R.C.M., and P.B.; formal analysis, W.V. and G.R.C.M.; funding acquisition, G.R.C.M. and P.B.; investigation, W.V.; methodology, W.V. and G.R.C.M.; project administration, G.R.C.M. and P.B.; resources, W.V., G.R.C.M., and P.B.; software, W.V.; supervision, G.R.C.M. and P.B.; validation, W.V. and G.R.C.M.; visualization, W.V.; writing—original draft, W.V.; writing—review and editing, W.V. and G.R.C.M. All authors have read and agreed to the published version of the manuscript.

**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.
