## 1 Introduction  
The energy transition is one of the great challenges of our society at the beginning of this millennium. To this, it must be added that the latest international socio-political events have exacerbated the energy crisis, evidencing the need for an acceleration in this transition. The electrical grid, as it has been known so far, is changing. It is evolving from a centralized to a more decentralized layout [1], where priority is given to the consumption of energy coming from renewable energy sources. It has been shown that a restructuring of the electrical grid into local micro-grids makes it possible for greater integration of the amount of energy from renewable [2, 3]. In particular, given its great potential for installation on building roofs, photovoltaic (PV) energy is becoming the most widely extended one [4]. In this context, due to the increasing price of electricity and government subsidies for financing PV installations, these facilities are paying for themselves more quickly than ever, especially in the frame of self-consumption. Self-consumption or collective self-consumption (CSC), as its name suggests, is related to the consumption of local electricity production. In the Spanish state, according to data recorded by the Spanish Photovoltaic Union (UNEF), 1203 MW of new PV capacity was installed in 2021 in self-consumption facilities. This figure represents an increase in 101.8% compared to 2020 when 596 MW were commissioned [5]. This research study has been developed in the framework of the EKATE project, an InterregPoctefa type program. EKATE is a project for PV electricity management and CSC in the France-Spain cross-border area, using Blockchain and Internet of Things (IoT) technologies [6]. One of the pilot projects being developed within the framework of EKATE takes place in the Izarbel technology park in Bidart (France), involving the buildings of ESTIA Technology Institute. This Izarbel pilot project aims to implement innovative energy management in buildings in a CSC operation. In order to maximize the self-consumption rate and, as far as possible, energy efficiency, two types of energy management systems (EMS) are being designed and developed to be applied in the ESTIA2 building. To achieve the aforementioned objectives, these EMSs act on flexible loads (FL). What is known as demand side management (DSM) or demand response (DR)? For that, two types of FL have been considered, the Heating, Ventilation, and Air Conditioning (HVAC) system and the energy consumption behavior of the building users. Regarding the two EMSs designed:  
(1) The first one is based on simple logic rules that act on the ON/OFF status of the internal HVAC units and/or on the temperature setpoints of the system and also influences the ESTIA2 user's behavior in real-time according to the instantaneous surplus of PV energy. (2) The second one is an intelligent EMS based on predictive models of ESTIA2 consumption and ESTIA1 PV production, a thermal model of ESTIA2 and HVAC, and an optimization algorithm. This work complements a previously developed one, as shown in [7], where three prediction models based on artificial intelligence (AI) are developed to predict the consumption of the ESTIA2 building. The prediction of energy generation from renewable sources is not a new challenge. Different strategies can be found in the literature. Some works choose to predict the meteorological variables that influence energy production, such as solar radiation, temperature, or the clear sky index [8; 9]. Afterward, in some cases, they use equations to calculate the corresponding energy generation. Whilst other works propose to directly predict the PV generation [10; 11]. Another possible criterion for classifying prediction techniques is according to the type of model used. They are generally divided into three types: physical or analytical methods, recurrent methods, and AI-based methods. A physical method describes the atmospheric dynamics and physical states by a set of mathematical equations.