**2.1 Photovoltaic and electric load scenarios**

To classify PV and electric load production, yearly data-measurements from smart meters installed in Walloon region, Belgium, have been used. The smart meters communicate with the utility company server every 15-min providing the updated PV and load measurements. The 15-min datasets were merged to formulate 8760 hourly readings (365 24-hour PV generation and load profiles). The total PV capacity is 50 kVA. The original datasets are shown in **Figure 2**.

We use the scenario reduction technique introduced in [6] to construct the scenarios. A script developed in Matlab based on [6] is utilized to aggregate the two sources of uncertainty into one. That is, a discrete probability has been assigned to each one of the generated scenarios. Every scenario comprises two 24-hour vectors where each vector corresponds to a specific profile (one vector for PV production and one for load demand). Moreover, this scenario construction technique considers the potential correlation within the data. The latter is very important as, for example, a sunny day with increased PV production is expected to affect the load demand downwards and vice-versa. Moreover, one may notice that the PV profiles of **Figure 2a** look asymmetric and seem to have been shifted towards the left side of the time axis. This is due to the minimum cut-in voltage level required from the power electronics of the inverter to start being operational.

It is important that the final number of generated scenarios retain most of the relevant information on the stochastic process contained in the original scenario sets, while significantly reducing its cardinality. A very large number of scenarios

**Figure 1.** *Energy management and system configuration.*

**Figure 2.** *The 365 original profiles for (a) PV production, and (b) electric load demand.*


#### **Table 1.**

*Parameters related with the number of scenarios.*

may result in a computationally intractable associated stochastic programming problem which would require both increased time and computational resources to be solved. On the other hand, a small number of scenarios might not be representative of the original data sets. Thus, in order to decide the appropriate number of scenarios we take into consideration the total expected system cost (TESC), its standard deviation (SD), and the total computational time, as shown in **Table 1**. Simulations take place on an Intel Core i7-5500U CPU @ 2.4 GHz with 16 GB memory.

We can see in **Table 1** that the TESC decreases considerably from the 6 to 12 scenarios, and from 12 to 24. On the other hand, the cost reduction from the 24 to 48 scenarios is smaller. The standard deviation of the TESC increases somehow from the 6 to 12 scenarios, but it remains relatively constant in the rest scenario cases. Finally, one may notice that the computational time needed to obtain the optimal solution is increased around 100% in both cases, from the 12 to 24 and from 24 to 48 scenarios. Considering all the information above, the case of 24 scenarios provides a favorable trade-off between a satisfactory scenario representation and a

*Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

computationally tractable problem. One should also note that the constructed scenarios are not equiprobable, but probability weighted. The 24 scenarios for PV generation and load demand are illustrated in **Figure 3**.

For the deterministic approach, we used the average yearly profiles (obtained from the original datasets in **Figure 2**) for both PV production and the electric load demand. These profiles are illustrated in **Figure 4**.

## **2.2 EVs driving schedule**

When connected to the microgrid, the charging and discharging behaviors of the EVs make them considered as either power supplies (when discharging) or power loads (when charging). Here, the EVs selected for the fleet are used for workrelated trips and it is also assumed that the mobility behavior with the EVs remains similar as with conventional vehicles.

In this work, the mobility behavior profiles for a fleet of 30 EVs are generated. In Belgium, 82% of the population has fixed working hours and shifts [7]. Usual working hours are considered from 8 am to 6 pm but they are not binding. The arrival time distribution is fitted in the form of chi-square distribution [8] with its probability density function given by: *f t*ð Þ¼ arr,*<sup>i</sup> t* ð Þ υ�2 *=*2 arr,*<sup>i</sup>* n*e* �*t* arr,*i=*2 <sup>2</sup>υ*=*<sup>2</sup> Γ υð Þ *<sup>=</sup>*<sup>2</sup> where <sup>Γ</sup>ð Þ� is defined as <sup>Γ</sup>ð Þ¼ *<sup>a</sup>* <sup>Ð</sup> <sup>∞</sup> 0 *t <sup>a</sup>*�<sup>1</sup>*e*�1dt, *<sup>a</sup>*<sup>&</sup>gt; 0 with *<sup>υ</sup>* <sup>¼</sup> 4 degrees of freedom [9], and *<sup>t</sup>*arr,*<sup>i</sup>* is the arrival time for the *i*-th EV. The detention time of the EVs connected to the microgrid conforms to the normal distribution with a mean of 8 hours and a variance equal to 4 hours *N* 8, 22 � � assuming that the working time of most people is 8 hours. The initial state-of-energy of the EVs is decided by applying the uniform distribution with values between 0.3 and 0.8. One should also note that for the numerical

**Figure 3.** *The 24 representative scenarios for (a) PV production, and (b) electric load demand.*

**Figure 4.** *The average yearly profiles for (a) PV production, and (b) electric load demand.*

evaluation in the Results section, we used deterministic realizations of all the uncertain characteristics of the EVs (arrival, stay duration, initial state-of-energy).

#### **2.3 Simplified thermal model**

To simulate the thermal performance of a building, engineers developed, among other tools, the thermal network method. Thermal networks have been used to study the internal mass effects [10], appliances, indoor air temperature and heating load [11] for different buildings. In addition, they represent a comprehensible idea about the heat transfer phenomena in buildings with a simple systematic formulation of the problem. In the thermal network method, the whole mass of the system is accumulated in finite number of nodes, which are connected to thermal capacitances. The heat transfer between two nodes occurs through thermal resistances. It has been shown, that the functionality of control systems can be improved by the implementation of the thermal network method and the system identification approach [12].

System identification is an approach to construct mathematical models of dynamic systems by means of measurements of the system's input and output signals. The system identification needs the measured input and output signals from the system, a model structure, and an estimation method to estimate values for the adjustable parameters in the selected model structure. In a dynamic system, the output signal depends on both the instantaneous values of its input signals and on the initial conditions. In fact, a model is a mathematical relationship between a system's input and output variables. Differential or difference equations, transfer functions, and state-space equations are common methods to describe a dynamic system. The RC model method describes the system with ordinary differential equations that can be easily represented with the state space method.

*Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

Obtaining a good model of the system depends on how well the measured data reflects the behavior of the system. For this purpose, the measured data must capture the dynamics of the system. It is necessary to measure the right variables with enough accuracy and duration to capture the dynamics of interest. In general, to supply an appropriate dataset, the following inputs that excite the system dynamics are important: data duration to capture the important time constants, a detailed analysis of signal-to-noise ratio, and finally measuring the outputs at appropriate sampling intervals [13].

The use of the RC model method provides the structure of the model, but not the numerical values of its parameters. Afterwards, it is possible to represent the system with a state-space model and estimate the values of its parameters from the data. This approach is known as gray-box modeling. The system identification approach refers to methods and algorithms that estimate the model parameters by minimizing the error function (cost function – the mean square error), as shown below between the model output and the measured data.

$$V(\theta) = \frac{1}{L} \sum\_{t=1}^{L} e^{T}(\theta, t)e(\theta, t),\tag{1}$$

where *L* is the number of data samples, eð Þ θ, t is a given error vector at time *t* and parametrized with θ. Then, parameters are obtainable with minimizing Vð Þθ with respect to the parameter vector *θ*. After the model is estimated, quality metrics represent the quality of identified models.

$$\text{NRMSE} = \mathbf{100} \times \left( \mathbf{1} - \frac{\sqrt{\left(\mathbf{y}\_{\text{measured}} - \mathbf{y}\_{\text{model}}\right)^2}}{\sqrt{\left(\mathbf{y}\_{\text{measured}} - \mathbf{y}\_{\text{measured}}\right)^2}} \right). \tag{2}$$

The MATLAB® system identification toolbox is used in this work to minimize the cost function of Eq. 2 and to estimate the model parameters. MATLAB uses various minimization algorithms to perform the optimization. In our case, the 'auto' algorithm is used for the search method to minimize the cost function and to estimate model parameters, as it determines the optimized trajectory among different techniques at each iteration.

The simplified thermal model presented in [14] is used in this study to obtain the thermal load for the university building. The building is simulated using TRNSYS software utilizing weather data from the Uccle meteonorm file (Belgium). It has a heavy structured envelope and the buildings material properties are presented in [14]. Here a 4R2C model is proposed and used to simulate the thermal performance of the building. The corresponding proposed thermal network is represented in **Figure 5**.

**Figure 5.** *The proposed thermal network.*

**Figure 6.** *Daily thermal load prediction.*

To determine the parameters in the thermal network, the system identification approach has been used. Data from TRNSYS have been used as the information matrix for the model to be trained. To identify the model's parameters, the Matlab system identification toolbox is utilized. The information matrix contains onemonth data. The model identification determines the values of each resistance and capacitance to achieve the highest fitness between the thermal network and the information matrix. Then, the identified model can predict the thermal performance of the building for a predetermined period of days.

To formulate a daily thermal load profile, so as it can be used by the EMS for its 24-hours scheduling horizon, the average heating load of the predicted working days is calculated. The calculated thermal load offers a temperature approximately around 22°C during working hours (from 9 am to 6 pm). The daily thermal load prediction is illustrated in **Figure 6**.

The thermal load is low during the night and the early morning hours and starts increasing around 8 am. This is necessary, so as the targeted thermal comfort level to be achieved in the office building during the working hours. The thermal load is covered by CHP's thermal production.

#### **3. Mathematical formulation**

The mathematical formulation of the EMS is presented in this Section. The objective function which minimizes the total expected system cost is given by Eq. (3) below:

Minimize

$$\begin{split} & \underset{t,\boldsymbol{\alpha}}{\operatorname{\bf curl}} \; \underset{t,\boldsymbol{\alpha}}{\operatorname{\bf curl}} \; \underset{\boldsymbol{\sigma}}{\operatorname{\bf curl}} \; \underset{\boldsymbol{\sigma}}{\operatorname{\bf curl}} + \underset{t,\boldsymbol{\alpha}}{\operatorname{\bf curl}} \; \operatorname{\bf curl}} \; \operatorname{\bf curl}-\operatorname{p}\_{t,\boldsymbol{\alpha}o}^{\operatorname{\bf grid},\operatorname{\bf curl}} \; \operatorname{\bf curl} \bigg|\_{i,t,\boldsymbol{\alpha}} + \sum\_{i,t,\boldsymbol{\alpha}} \pi\_{o} \left( \operatorname{p}\_{i,t,o}^{\operatorname{\bf EV},\operatorname{\bf dis}} + \operatorname{p}\_{i,t,o}^{\operatorname{\bf EV},\operatorname{\bf dis}} \right) \mathrm{C}^{\operatorname{\bf EV},\operatorname{\bf def}} \; \operatorname{\bf curl} \bigg|\_{i,t} \\ & \quad + \sum\_{t,o} \pi\_{o} \left( \operatorname{p}\_{t,o}^{\operatorname{\bf PV},\operatorname{\bf grid}} \lambda\_{\mathrm{PV}} + \operatorname{p}\_{t,o}^{\operatorname{\bfESS},\operatorname{\bf grid}} \lambda\_{\mathrm{ESS}} + \operatorname{p}\_{t,o}^{\operatorname{\bf CF},\operatorname{\bf grid}} \lambda\_{\mathrm{cHP}} + \sum\_{i} \boldsymbol{p}\_{i,t,o}^{\operatorname{\bf EV},\operatorname{\bf grid}} \lambda\_{\mathrm{EV}} \right), \end{split} \tag{3}$$

where Ξ is the set that contains all the decision variables of the problem. The time horizon is 24 hours. One should notice that since the considered time step is *Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

one hour, power and energy values coincide. This is a mixed integer linear optimization problem (MILP).

The expected cost function (3) is a probability-weighted mean of all the scenarios considered. It minimizes the power requested from the grid pgrid,in t,<sup>ω</sup> at price ε buy t and the total power pCHP,tot t,<sup>ω</sup> for the CHP at a gas price equal to εgas. On the other hand, it maximizes the energy sold back to the grid pgrid,out t,<sup>ω</sup> at price εsell <sup>t</sup> , by those microgrid components that are able to generate energy (PV, ESS, EVs, and CHP). Parameter πω expresses the discrete probability assigned to each scenario ω. The second term and the third term of Eq. (3) are penalty factors. Specifically, the second term applies a small cost CEV,deg, every time an EV charges pEV,ch i,t,<sup>ω</sup> or discharges pEV,dis i,t,<sup>ω</sup> . This is to ensure that no unnecessary EV charges/discharges take place and to prevent EVs' battery degradation. The penalty is normalized for every kWh of battery charging/discharging and it does not depend on how frequently the EVs charge or discharge.

Finally, the third term of Eq. (3) introduces a prioritization mechanism in the form of a penalty factor. Parameters λPV, λESS, λCHP, and λEV obtain excessively small positive values, so that the total cost function is not affected. The values of these parameters work as an artificial penalty and are determined by assumptions depending on which source is preferred by the EMS to give priority to selling the energy back to the grid. The smaller the relative value of parameter λ for a specific resource, the higher the priority in the EMS to sell the available energy from this resource first.

#### **3.1 PV modeling**

Eq. (4) enables the actual power generated by the PV to be utilized in three different directions. A portion can be sold directly to the grid pPV,grid t,ω , another portion can be used to cover the building's load needs pPV,build t,ω , and the third option allows PV energy to be stored into the ESS pPV,stored t,ω and used at a later time frame. The sum of all the PV power variables must be less than or equal to the PV generation PPV,gen t,<sup>ω</sup> at every time step *t* and scenario ω.

$$p\_{t,o}^{\text{PV,grid}} + p\_{t,o}^{\text{PV,build}} + p\_{t,o}^{\text{PV,stored}} \le P\_{t,o}^{\text{PV,gen}} \,\,\forall t,o \tag{4}$$

#### **3.2 ESS modeling**

The ESS operation is characterized by Eq. (5)–(10). The actual power provided by the ESS when discharges can be either sold back to the grid pESS,grid t,ω or used to cover a portion of the building load demand pESS,build t,ω . as shown in Eq. (5). Eqs. (6) and (7) establish the limitations for the charging pESS,ch t,ω and discharging pESS,dis t,ω power of the ESS with the assistance of binary variable <sup>ξ</sup>ESS t,<sup>ω</sup> . Constraint (8) ensures that the total power towards the ESS does not violate its maximum charging rate. The state-of-energy (soe) for the ESS is expressed by Eq. (9) and Eq. (10), while Eq. (11) sets the minimum and the maximum allowed limits for the ESS soe to prevent a deep discharge of the battery.

$$p\_{t,o}^{\text{ESS,grid}} + p\_{t,o}^{\text{ESS,build}} = p\_{t,o}^{\text{ESS,dis}} \eta^{\text{ESS,dis}} \,\forall t, o \tag{5}$$

$$0 \le p\_{t,o}^{\text{ESS,ch}} \le \xi\_{t,o}^{\text{ESS}} P^{\text{max},ch} \; \forall t, o \tag{6}$$

$$0 \le p\_{t, \alpha^{\prime}}^{\text{ESS,dis}} \le \left(1 - \xi\_{t, \alpha^{\prime}}^{\text{ESS}}\right) P^{\text{max}, \text{dis}} \,\,\forall t, \,\alpha \tag{7}$$

$$p\_{t,o}^{\text{ESS,ch}} + p\_{t,o}^{\text{PV,stored}} + p\_{t,o}^{\text{CHP,stored}} \le P^{\text{max,ch}} \,\forall t, o \tag{8}$$

$$\text{Score}\_{t,\boldsymbol{\mu}}^{\text{ESS}} = \text{SOC}^{\text{ESS,ini}} + \boldsymbol{\eta}^{\text{ESS,ch}} \boldsymbol{p}\_{t,\boldsymbol{\mu}}^{\text{ESS,ch}} + \boldsymbol{p}\_{t,\boldsymbol{\mu}}^{\text{PV,stored}} + \boldsymbol{p}\_{t,\boldsymbol{\mu}}^{\text{CHP,stored}} - \boldsymbol{p}\_{t,\boldsymbol{\mu}}^{\text{ESS,dis}} \,\forall \boldsymbol{\mu}, t = 1 \tag{9}$$

$$\text{Score}\_{\text{t},o}^{\text{ESS}} = \text{soc}\_{\text{t}-\text{1},o}^{\text{ESS}} + \eta^{\text{ESS,ch}} \langle p\_{\text{t},o}^{\text{ESS,ch}} + p\_{\text{t},o}^{\text{PV,stored}} + p\_{\text{t},o}^{\text{CHP,stored}} - p\_{\text{t},o}^{\text{ESS,dis}} \,\forall o, t > \mathbf{1} \tag{10}$$

$$\text{SOC}^{\text{min}} \le \text{soe}^{\text{ES}}\_{t,o} \le \text{SOC}^{\text{max}} \,\,\,\forall t, o \tag{11}$$

#### **3.3 EVs modeling**

The EVs operation is described in Eq. (12)–(18). Eq. (12) ensures that the discharge power of the EVs is either injected back to the grid *p*EV,grid *i*,*t*,ω � � and/or used to cover a part of the building load demand *p*EV,build *i*,*t*,ω � �. Constraints (13) and (14) set a limit on the charging *p*EV,ch *i*,*t*,ω � � and discharging power *<sup>p</sup>*EV,dis *i*,*t*,ω � � of the EVs with the assistance of the binary variable ξEV *<sup>i</sup>*,*t*,ω. For each EV *i* in every scenario ω, the available state can be charging, discharging, or remaining in idle state. Eqs. (15)- (18) refer to the state-of-energy of the EVs. More specifically, Eq. (15) defines the state-of-energy of the EVs for initial conditions, while Eq. (16) describes the stateof-energy of each EV for the rest time steps. In Eq. (16), the state-of-energy of the current time interval for an EV is equal to the previous state plus the energy deriving from charging the EV battery (if charging) minus the energy that is subtracted if the EV battery is discharging. The nominal capacity of an EV's battery is 24 kWh (Nissan Leaf) and the rated charging power of an individual charger deployed in the parking lots is 7.68 kW (SAE-J1772, level 2, 208–240 VAC) with a charging and discharging efficiency of 90% [15]. To avoid EVs' batteries overcharge and over-discharge, Eq. (17) limits the batteries' lowest state-of-energy at 20% of the EVs nominal capacity. Finally, constraint Eq. (18) sets the minimum state-of-energy for each EV upon its departure time.

$$p\_{i,t,o}^{\text{EV,grid}} + p\_{i,t,o}^{\text{EV,build}} = p\_{i,t,o}^{\text{EV,dis}} \eta^{\text{EV,dis}} \,\forall i, t \in \left[ T\_i^{\text{urr}}, T\_i^{\text{dep}} \right], o \tag{12}$$

$$0 \le p\_{i,t,o}^{\text{EV,ch}} \le \xi\_{i,t,o}^{\text{EV}} P^{\text{EV,max},ch} \; \forall i, t \in \left[ T\_i^{\text{arr}}, T\_i^{\text{dep}} \right], o \tag{13}$$

$$0 \le p\_{i,t,o}^{\text{EV,dis}} \le \left(1 - \xi\_{i,t,o}^{\text{EV}}\right) P^{\text{EV,max},dis} \; \forall i, t \in \left[T\_i^{\text{arr}}, T\_i^{\text{dep}}\right], o \tag{14}$$

$$\text{Score}\_{i,t,o}^{\text{EV}} = \text{SOC}\_{i}^{\text{EV,arr}} + \eta^{\text{EV,ch}} p\_{i,t,o}^{\text{EV,ch}} - p\_{i,t,o}^{\text{EV,dis}} \,\,\forall i, t = T\_i^{\text{arr}}, o \tag{15}$$

$$\text{score}\_{i,t,o}^{\text{EV}} = \text{soc}\_{i,t-1,o}^{\text{EV}} + \eta^{\text{EV,ch}} p\_{i,t,o}^{\text{EV,ch}} - p\_{i,t,o}^{\text{EV,dis}} \,\forall i, t \in \left(T\_i^{\text{arr}}, T\_i^{\text{dep}}\right], o \tag{16}$$

$$\text{LSOE}^{\text{EV, min}} \le \text{soc}\_{i, t, oo}^{\text{EV}} \le \text{SOE}^{\text{EV, max}} \text{ } \forall i, t \in \left[ T\_i^{\text{arr}}, T\_i^{\text{dep}} \right], oo \tag{17}$$

$$
\delta s e\_{i,t,\alpha}^{\rm EV} \ge \text{SOC}\_i^{\rm EV,dep} \; \forall i, t = T\_i^{\rm dep}, \; \alpha \tag{18}
$$

#### **3.4 CHP modeling**

The utilization of small-sized CHP turbines is typical for covering thermal load demand and has been often proposed in literature as a distributed energy resource [16]. *Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

The equations that describe the operation of the CHP microturbine are presented in Eqs. (19)-(24) below.

$$p\_{t, \alpha}^{\text{CHP,el}} + p\_{t, \alpha}^{\text{CHP,th}} = p\_{t, \alpha}^{\text{CHP,tot}} \eta^{\text{CHP,ovrl}} \,\forall t, \alpha \tag{19}$$

$$p\_{t,o}^{\text{CHP,el}} = p\_{t,o}^{\text{CHP,tot}} \eta^{\text{CHP,el}} \,\,\forall t, o \tag{20}$$

$$p\_{t,o}^{\text{CHP,th}} = p\_{t,o}^{\text{CHP,tot}} \eta^{\text{CHP,th}} \,\forall t, o \tag{21}$$

$$P^{\rm CHP, min} \le p\_{t,o}^{\rm CHP,tot} \le P^{\rm CHP,max} \; \forall t, o \tag{22}$$

$$P\_{t,o}^{\text{CHP,th}} \ge P\_t^{\text{build,th}} \,\,\forall t,o \tag{23}$$

$$p\_{t,o}^{\text{CHP,el}} = p\_{t,o}^{\text{CHP,grid}} + p\_{t,o}^{\text{CHP,build}} + p\_{t,o}^{\text{CHP,ESS}} \,\forall t,o \tag{24}$$

Constraint (19) states that the total power *p*CHP,tot *<sup>t</sup>*,<sup>ω</sup> generated by the CHP consists of its electrical *p*CHP,el *t*,ω � �, and its thermal *<sup>p</sup>*CHP,th *t*,ω � � production. Eqs. (20) and (21) relate the electrical and thermal production of the CHP with their corresponding efficiencies. Constraint (22) imposes the limits to the CHP's minimum and maximum operation state. Eq. (23) ensures that the thermal load demand is met at any time by the CHP operation, while Eq. (24) describes the possible directions towards the electrical production of the CHP can be directed. More specifically, Eq. (24) states that a portion of the electric power produced is used to cover the building's electrical load demand, another portion can be stored to the ESS for later exploitation, while an amount of CHP energy can be directly sold back to the grid. The main criterion based on which the CHP size has been selected, is its ability to fully cover the thermal load of the building during the whole day, including the peak time periods.

#### **3.5 Power constraints**

The total power injected to the grid is described in Eq. (25). The total power injected to the grid at time *t* and for each scenario ω consists of the power provided by the PV, the ESS, the CHP, and the sum of the power derived from EVs discharging and intended for the grid. In this work it is assumed that all the available energy to be injected into the grid can be acquired by the utility serving company at the time it is produced.

$$p\_{t,o}^{\text{grid,inj}} = p\_{t,o}^{\text{PV,grid}} + p\_{t,o}^{\text{ESS,grid}} + p\_{t,o}^{\text{CHP,grid}} + \sum\_{i} p\_{i,t,o}^{\text{EV,grid}} \,\forall t,o \tag{25}$$

The power balance equation is defined in Eq. (26) below.

$$p\_{t,o}^{\text{grid,in}} + p\_{t,o}^{\text{PV,build}} + p\_{t,o}^{\text{ESS,build}} + \sum\_{i} p\_{i,t,o}^{\text{EV,build}} + p\_{t,o}^{\text{CHP,build}}$$

$$= P\_{t,o}^{\text{build}} + p\_{t,o}^{\text{ESS,ch}} + \sum\_{i} p\_{i,t,o}^{\text{EV,ch}} \,\forall t,o \tag{26}$$

Constraint (26) forces the balance between the input and the output electric power of the EMS in each time interval. More specifically, it is stated in Eq. (26) that the total load consisting of the office-building electric load demand, the charging needs of the ESS and the sum of the charging needs for the EVs is covered by the power requested from the grid and/or by the combined procurement of power provided by the PV, the ESS, the sum of discharging power of the EVs, and the CHP. Finally, Eq. (27) and Eq. (28) realize the logic of power exchange.

$$p\_{t,o}^{\text{grid,in}} \le L \, \xi\_{t,o}^{\text{grid}} \,\,\forall t,o \tag{27}$$

$$p\_{t,o}^{\text{grid,out}} \le L\left(1 - \xi\_{t,o}^{\text{grid}}\right) \,\forall t,o \tag{28}$$

When the EMS needs to draw power from the grid, power is not allowed to be injected into the grid at the same time, and vice versa. The limitations in power exchange are imposed by parameter *L* which corresponds to the local line capacity. To avoid the installation of extra power facility infrastructure for the EMS, the potential limits of the university-building dedicated medium-voltage to low-voltage (MV/LV) transformer are used. The apparent power of the transformer is 160 kVA with MV input 10.5 kV and LV output 400 V. Assuming a whole building's power factor of 0.9, the actual (useful) power that can be drawn from the grid at any time is 144 kW. This constraint can be also time-dependent and be imposed to lower values, for example, by an aggregator responsible for coordinating multiple microgrids owning EMS or by the utility company itself responsible for the smooth operation of electrification in the area.

#### **4. Numerical results and discussion**

To examine the effectiveness of the proposed EMS algorithm, the impact of different case studies on total system cost is evaluated. The proposed EMS framework is a mixed integer linear problem modeled in GAMS v.24.7.1 and solved by the IBM CPLEX Optimizer v.12.6. The time required to find the optimal solution varies from a few seconds to several minutes, depending on the model. The optimality gas has been set at 1.0E-04.

The electric load demand and PV scenarios are given in **Section 2.1** along with the deterministic day-ahead (DA) forecasts. The thermal load demand prediction is shown in **Section 2.3**. It should be noted that as the PV generation data came from actual smart metering measurements, no study regarding the positioning and the installation of the PV panels was performed.

The bidirectional energy flows between the utility company and the end-user (the building-microgrid manager in this case) assume the utilization of smartmetering approach. The day-ahead time-varying price signal which represents the electricity cost at each time interval *t* is depicted in **Figure 7**. A time-varying rate has also been applied for the energy sold back to the grid. This rate is 20% lower

**Figure 7.** *Day-ahead electricity price forecast.*

### *Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

than the aforementioned time-varying price signal, based on the assumption that the utility company would not buy energy at a more expensive rate than it would sell it. In this study, no other incentive-based scheme (e.g., selling green certificates for renewables) apart from the utility company price signal is applied.

The ESS consists of a battery group with a total capacity of 80 kWh. The maximum charging/discharging rate is 40 kW with corresponding power electronics efficiency of 0.88. The minimum allowed state-of-energy of the ESS has been set to 10 kWh (12.5% of max ESS capacity) to prevent deep battery discharging. The initial state-of-energy of the ESS is 40kWh.

The thermal efficiency ηCHP,th of the CHP microturbine is 0.51 and the electric efficiency ηCHP,el 0.36 resulting in an overall efficiency ηCHP,ovrl of 0.87. The overall efficiency of the CHP is kept constant regardless its load for sake of simplicity. The rated power of the CHP is 150 kW, and to avoid start-up costs, a minimum state of 10 kW has been set for the CHP operation.

As mentioned earlier, a bidirectional energy flow concept for EVs and their potential V2B and V2G capabilities could significantly reshape the current perception of power systems. The first step is their integration into the smart grid (or microgrid). The EVs are equipped with constantly bigger battery capacities increasing thus their potential contribution as DERs. The EVs could either be granted to (University's or a company's) personnel for commuting purposes under the form of a third-party contract and/or they could be privately owned. In both cases, it would make sense to assume that the EV users would be willing to allow the building-microgrid operators to use their batteries' capacity but they would not prefer to have a lower state-of-energy upon departure compared to their arrival. In addition, in the case of self-owned EVs, possible monetary benefits for the EV owners may be needed for motivating them to opt-in the EMS scheme.

In our base case study, the first business model is considered, namely the EVs are provided to the personnel and, in exchange, the EVs' users have to participate in the EMS framework. It is considered here that the final state-of-energy of the EVs should be at least equal to their initial one. We have also considered λPV < λESS <λCHP <λEV assigning a higher priority to the energy coming from PV to be sold to the grid, afterwards the energy from ESS, then the energy from CHP, and finally the energy from the EVs. The reason that the lowest priority has been assigned to EVs is to have as few charging/discharging cycles for the EVs as possible to prevent battery degradation.

First, we consider the total system cost (TSC), as shown in **Table 2**.

The first case corresponds to an operation of the microgrid without the presence of an EMS and thus, no optimization takes place. That is, the loads cannot be shifted and are always met. In addition, as the EVs should depart at least having the same battery state of energy as the one they had when arrived, charging/discharging of the EVs are not activated. The ESS operation is also omitted, as its charging / discharging cannot be coordinated due to the absence of an EMS. Finally, when


**Table 2.** *Total system cost across all case [\$].* there is a net energy consumption at time *t*, electricity is bought at price ε buy *<sup>t</sup>* , while when there is a net supply of energy to the grid, it is sold at price εsell *<sup>t</sup>* . The second case corresponds to the minimization of the total system cost for one day of microgrid operation. The annual average values of the PV and electricity load historical data have been considered, among others, as input parameters. The third case minimizes the expected mean cost considering the 24 PV and electricity load probability-weighted scenarios, as these are determined in **Section 2.1**. A cost distribution for all scenarios considered in case 3 is shown in **Figure 8**. Finally, the fourth case minimizes the total system cost for the microgrid considering the most probable scenario (scenario 23 out of the 24). It should be noted that all cases apart from case 1 assume the presence of an EMS in microgrid's operation.

The importance of considering an EMS in microgrid's operation is depicted in the TSC results across all cases, as shown in **Table 2**. First, the total system cost of case 1, where no EMS is assumed, is 340% higher compared to case 2, where an EMS is present coordinating the microgrid operation (from \$13.51 to \$59.47). The expected TSC for case 3 is 23% higher compared to case 2 due to the impact of some extreme scenarios on the final result. Moreover, the total cost distribution across all the different scenarios (**Figure 8**) implies that the final total system payoff for the majority of the scenarios is positive in terms of cost (a positive value declares a cost, while a negative one declares a profit). Finally, one may notice that the TSC for the most probable scenario, as seen in case 4, is much higher compared to the other two cases (case 2 and 3) in which an EMS is also present on microgrid's operation. The reason is that for this particular scenario, the PV generation and the building load demand are very different compared to the corresponding annual average values, as these are considered for case 2 (**Figure 4**). More specifically, the projected PV generation in the most probable scenario is much lower than the yearly average, as presented in case 2. On the contrary, the building load demand is higher than the average. Therefore, the results presented in this Section should be interpreted taking this context into account.

To analyze a few more aspects of the optimization results and examine the individual scheduling of each DER, as it is decided by the EMS, we compare the microgrid's operation under two different case studies: case 2, which from now on

**Figure 8.** *Total system cost distribution for the 24 scenarios.*

#### *Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

will be referred to as simply the **deterministic** case, and case 4, which will be referred to as the **most probable scenario**. (**Figure 9**).

**Figure 10** presents the total power requested by the EMS from the grid and injected back to it for the deterministic approach and the most probable scenario.

There are many observations one might make regarding **Figure 10**. First, notice that the power requested from the grid is zero during the whole 24-hour time horizon for the deterministic approach. This implies that the microgrid can fully cover its electric load demand using its own distributed energy resources. In addition, it is able to inject a great portion of its produced energy back to the grid. From 1 pm to 4 pm though, the microgrid neither requests nor injects power back to the grid. This means that the produced energy is entirely used to cover the local microgrid load demand.

On the other hand, we can see that during the most probable scenario, the microgrid draws power from the grid from around 9 am to 5 pm which indicates that the microgrid's distributed energy resources cannot fully cover the load demand during that period. This is mostly due to the limited daily PV production assumed in this scenario in combination with a higher than average electric load demand. In addition, one may notice that the total power injected back to the grid is much lower in the most probable scenario.

To better understand how EMS coordinates the operation of the microgrid's components, **Figure 11** presents the decomposition of the total power injected to the grid for the involved DERs (PV, ESS, CHP, and EVs).

In both the deterministic and the most probable scenario, CHP is the DER that injects most of the power back to the grid. We can see that in the deterministic case PV also contributes, especially during the noon hours. The ESS is more active in the case of the most probable scenario, while one might notice that the EVs are not used at all as a potential source for energy to be injected to the grid. This happens mainly due to the lowest prioritization factor EVs have for selling energy back to the grid as

**Figure 9.** *Most probable scenario for (a) PV production, and (b) electric load demand.*

**Figure 10.** *Power requested from and injected to the grid for the most probable scenario and the deterministic approach.*

#### **Figure 11.**

*Decomposition of power injected to the grid for the (a) deterministic approach, and (b) the most probable scenario.*

described earlier, but also due to the penalty that has been set to prevent EVs battery degradation. Finally, we can observe that in both the deterministic and the most probable scenario, the EMS tries to inject most of the power back to the grid

*Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

during the peaks of electricity price (around 7 am and 6 pm as shown in **Figure 7**) to maximize the reward.

**Figure 12** shows the decomposition of the projected PV generation for the deterministic approach and the most probable scenario.

In the deterministic case study, PV production is mostly sold to the grid (early and noon hours) or stored in the ESS for future exploitation (afternoon hours). Only a small portion at 1 pm is used to cover the building's load demand. On the contrary, in the most probable scenario, all the produced PV energy is used to meet the building's load demand.

**Figure 13** shows how the electric power produced by the CHP is divided among the grid, the ESS, and the local building load. Like the PV, most of the CHP electric production in the most probable scenario is used to cover the building's load. Moreover, we can see that the EMS tries to inject most of the CHP's produced energy back to the grid, during the electricity price peak hours. Finally, in both cases a smaller amount of the CHP's produced energy is stored in the ESS for future implementation. The thermal load demand parameter *P*build,th *<sup>t</sup>* is not an uncertaintyrelated parameter and thus, remains the same in each scenario. The thermal load demand is met by variable *p*CHP,th *<sup>t</sup>*,<sup>ω</sup> , as stated in Eq. (23).

Storage is an important distributed energy resource for the system. As stated in Eqs. (9)-(10), the ESS can either be charged from the grid, the PV, and the CHP. When discharging, its energy can be either injected into the grid and/or cover a portion in building's load demand. **Figure 14** shows the decomposition of the ESS available energy for the deterministic approach, as well as for the most probable scenario.

**Figure 14** can be better analyzed taking into account **Figure 15**, which demonstrates the evolution of the ESS state of energy for the two aforementioned case studies.

We can see that in both deterministic and most probable scenario cases, the ESS is mainly active during two distinct period of times, in the morning (between 7 am and 8 am), and in the afternoon (between 5 pm and 7 pm). There are two main

**Figure 12.** *Decomposition of PV production for the (a) deterministic approach, and (b) the most probable scenario.*

**Figure 13.** *Decomposition of CHP electric produced power for the (a) deterministic approach, and (b) the most probable scenario.*

**Figure 14.** *Decomposition of ESS provided power for the (a) deterministic approach, and (b) the most probable scenario.*

observations one may make regarding the ESS operation. First, the ESS uses two discharge cycles in the deterministic approach, while it only discharges once in the most probable scenario. The relatively high PV generation considered in the deterministic scenario is responsible for this second cycle of charge/discharge. Looking at **Figure 12**, we notice that PV production during the afternoon hours is mostly directed to the ESS. Second, the ESS covers mainly the building's load demand in the deterministic case, while in the most probable scenario the ESS injects most of its energy back to the grid.

*Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

#### **Figure 15.**

*State of energy for the ESS for the (a) deterministic approach, and (b) the most probable scenario.*

EVs constitute the third available DER in the microgrid but contrary to the rest DERs (PV, ESS, and CHP), they are not actively involved in microgrid's energy exchange. The EVs battery degradation cost on the one hand, and the lowest energy prioritization factor that has been assigned to them on the other hand, do not make the an attractive alternative power source for the EMS (in terms of cost). Nevertheless, the EVs can always be used as a back-up ancillary power source in case of an emergency situation.

#### **5. Sensitivity analysis**

Sensitivity analysis is used to study the robustness of the solution to a linear programming model. If there is cause for concern regarding the accuracy of the data used, sensitivity analysis is undertaken to determine the way the solution might change if the data were different. When the solution does not change (or when the nature of the solution does not change, as when the basis remains optimal), one may assume that the proposed solution is appropriate.

**Dual variables**, also known as *shadow prices*, are of great interest in the solution of a linear optimization problem. A dual variable is reported for each constraint. The dual variable is only positive when a constraint is binding. The dual price can be defined as "*the improvement in the objective function value if the constraint is relaxed by one unit*". In the case of a less-than-or-equal constraint, such as a resource constraint, the dual variable gives the value of having one more unit of the resource represented by that constraint. In the case of a greater-than-or-equal constraint, such as a minimum production level constraint, the dual variable gives the cost of meeting the last unit of the minimum production target. The units of the dual prices are the units of the objective function divided by the units of the constraint. To obtain the values of the dual variables, we first solve the MILP to find the optimal allocation. Next, we remove the integrality constraints and insert equality constraints that force the integer variables to assume their optimal values in the resulting linear program [17].

The following example presents how the dual variable of a constraint can be used for the sensitivity analysis. **Figure 16** shows the dual prices of constraint Eq. (4) for the 24 hours of the daily time horizon. One should recall that this is a

**Figure 16.** *Value of sensitivity factor: Dual variable corresponding to the upper bound of constraint (4) [\$/kWh].*

resource constraint, and specifically it bounds the actual power generated by the PV to be less-than-or-equal-to the maximum PV generation, as this is defined by parameter *P*PV,*gen <sup>t</sup>* . Also note that this example refers to the EMS operation of case 2, as presented in **Table 2**.

This value implies the sensitivity of the system cost with respect to the actual PV power utilized by the system. Note that the positive value for this dual variable means that the total system cost decreases with the additional availability of PV power. More specifically, it indicates the decrease in the total system cost that corresponds to the increase of the available PV generation by 1 kWh. The fact that the value of the dual variable is positive during the whole day implies that additional PV potential has always positive impact on the total system cost, regardless the time of the day. However, one might also notice that there some time periods (7 am, from 5 pm to 9 pm), where the extra PV power would be more beneficial for the system compared to the rest time periods. In a similar way, one could evaluate the impact of the relaxation of the rest important resources to the total system cost.

### **6. Conclusion and future work**

The transition to the new "smart" era requires the utilization of smart technology through comprehensive and efficient energy management functions. We propose in this study, a two-way communication energy management framework for a microgrid in a university campus including local renewable energy sources, a storage system, a combined heat and power small turbine, and a fleet of EVs used for work-related trips. Two-way energy exchange is allowed using net metering technology. The developed MILP framework incorporates an optimizer which decides the power exchange among the DER components of the microgrid and the grid, exploiting the V2B and V2G capabilities of the distributed energy resources. It also provides a specific level of thermal comfort to the building's occupants by meeting the predicted heating load. The formulation of an EMS model which takes into account the PV and load variability is very important if we want to consider the impact of planning for one scenario, and having another scenario occurs.

*Energy Management and Optimal Power Scheduling in a Smart Building under Uncertainty DOI: http://dx.doi.org/10.5772/intechopen.94989*

To overcome this challenge, actual smart metering data for a period of one year have been used to construct a number of potential scenarios. The PV and load demand data are classified using a scenario construction technique, leading to the formulation of 24 different PV and electric load scenarios, each one represented by a designated probability. The importance of considering an EMS in microgrid's operation is depicted in the total system cost across all cases. Results confirm that the EMS substantially decreases the total system cost by optimally coordinating and scheduling the microgrid operation. An additional significant remark is that the majority of the total daily system's cost is due to the natural gas expenses required for the operation of the CHP microturbine. Finally, we compare the optimal scheduling of the microgrid's DERs under the deterministic case and the most probable scenario. The most probable scenario assumes a lower PV production and a higher building electric load demand than the average values considered in the deterministic case, resulting in a substantially different energy scheduling for the DERs. It is worth noting that under the deterministic approach and the current design, the microgrid seems to be self-sufficient in terms of covering its energy demand. However, this is not the case under the most probable scenario approach, where the microgrid relies also on grid energy to meet its load demand, on top of the energy production of its own DERs. Suggestions for future work include the introduction of additional stochasticity parameters (e.g., electricity price) and the integration of power flow constraints into the optimization problem.
