## 2 Modeling of the System  
### Modeling of the Energy Management System  
In this paper, an Energy Management System (EMS) is developed, with the aim of managing the electric power demand of a residential user (Smart-Home). The objective is to optimize the use of electric power produced on site from renewable sources, by assuming a rational behavior of end-users and by considering energy cost variations in the distribution energy market. The EMS considers a PV generation and an energy storage system (battery). Concerning the mode of operation, the control is based on different main aspects, as in the following list and as shown in Figure 1:  
* Control of shiftable loads;
* Control of the air conditioning (thermal storage);
* Control of the electric storage system. To obtain a complete and effective management of the devices in a smart-home, an ICT infrastructure is an essential requirement allowing the EMS to communicate with devices in order to vary the user power demand. The EMS control logic selects the energy source and establishes the energy flow as shown in Figure 2. As regards the AC-DC coupling, different system configurations are possible, for example [5; 7; 13; 14; 15]. Figure 1: EMS (Energy Management System) control logic. EMS output signals have the following functions:  
* Enable controllable devices, such as shiftable loads and air conditioning, thus modifying their power demand; and
* Absorb the necessary amount of power from available sources to guarantee the energy requirements of the households. EMS input signals provide information on the operational state of the devices; at the same time, load power demand and environmental variables, such as temperature, lighting and presence of people are monitored. Furthermore, signals from the user interface named Human Interface Device (HID) can be acquired in order to satisfy the end-user needs and preferences, regarding the mode of operation of the system. In particular, the input data can be classified as:  
* External to the Smart-Home, such as energy price, and outdoor temperature;
* Internal to the Smart-Home, such as indoor temperature, presence of people, and State Of Charge (SOC) of the energy storage system;
* Data from a local generation system: PV production;
* Data set by the end-user: temperature set-point, priority list of programmable electrical loads, and presence of not programmable electrical loads. Air conditioning, shiftable loads, PV generator and energy storage system are all controlled by a specific logic implemented according to designed mathematical model of computation based on state machines. The EMS is designed by using a state machine method and implemented using Matlab-Stateflow. The model considers the following implemented functions:  
1. Shiftable loads;
2. Battery storage charging and selection of energy sources; and
3. Thermal storage of electrical PV energy. The objective of the shiftable loads function is to plan the use of shiftable loads in order to minimize their energy cost [24; 26]. The decision about the period of operation related to shiftable loads requires the knowledge of the following information: the list of priorities by which the user requests the operation; the electric characteristics such as absorbed electrical power and operating time; the hourly price of the energy that will be purchased and absorbed from the grid. As regards with the battery storage charging and selection of energy sources, the designed model involves the use of the storage system to mainly feed the air conditioning system. The control system  
Figure 2: Energy flow model. managing the storage system ensures the real time compliance with the battery characteristics and the technical constraints, also related to the state of charge (SOC) limits [9; 23].