## 2 Modeling of the System
### Modeling of the Smart House with the Photovoltaic-Battery Systems  
A thermal model of the smart-home is considered, able to calculate the electric energy required by air conditioning [26]. In consideration of the operating mode (summer or winter) and of the temperature set point chosen by the user, the control system adjusts the electrical power necessary for the air conditioning system so that the temperature inside the house reaches the desired value. In view of the widespread penetration of PV systems as part of distributed generation in a smart-home, it is assumed the presence of a PV generation. The production of the PV system, as known, depends on many factors, some of which are related to the constructive characteristics and to the type and place of installation; other factors, such as weather conditions, may be considered as random variables [2; 9]. In the used model, these stochastic variables are used to properly model the PV production, evaluated through the data pattern detected by the Joint Research Centre (JRC) in Ispra (Italy). This method allows treating the PV generator as a random variable in the implementation of the Monte Carlo Simulation (MCS). The electrical Energy Storage System (ESS) is connected to the air conditioning system and it is rechargeable both from the PV generator and from the grid. The characteristics of the storage system are determined basing on the configurations that optimize the overall cost of the energy consumption in the smart-home. Five possible sizes of storage capacity are considered: from 4 kWh to 8 kWh in steps of 1 kWh. Charging and discharging of the battery are controlled by EMS, taking into account the cost of energy from the grid, the power availability of PV system and the current SOC. The ESS model, in terms of power and storage capacity, is designed considering the current technologies of the batteries. In fact, the stored or delivered energy depends on the maximum (SOC\({}_{\text{max}}\)) and minimum (SOC\({}_{\text{min}}\)) charge level; consequently, the SOC is continuously monitored. In addition, in this model, to different structural characteristics it corresponds a different cost of investment. The EMS's overall operation can be synthesized through a flowchart to make the strategy of the proposed study more straightforward. The description of the algorithm can be exemplified by the following steps, as also shown in Figure 3.  
1. Data Acquisition - PV Generator: technical characteristics and initial investment; - Energy Storage System (ESS): technical characteristics and initial investment; - Building thermal characteristics; and - Shiftable Loads. 2. Calculation of the specific operating cost of the PV-battery hybrid system. This parameter allows deciding if it is more convenient to use the PV system or the grid to charge the battery. It also determines whether it is best, inside the smart-house, to absorb energy from the PV system or from the battery rather than to absorb it from the grid. 3. Monte Carlo Simulation* Generating stochastic variables: PV-Power, Initial SOC, Real Time Pricing, and Weather Conditions; and
* Simulation of Simulink and Stateflow models: economic, thermal, PV and ESS, control logic. * Output results: energy and cost values. The model for the calculation of the economic parameters such as Total Savings Cost (TSC) and Discontinued Payback Period (DPP) is then developed. The innovative proposed control logic considers the ability to manage the available energy sources, both electrically and thermally, in order to change the demand by optimizing the Total Saving Cost (TSC). To this end, the control logic is able to control the energy flows by allowing different combinations of available energy sources and by giving priority to the most economically advantageous one.