2.2.1. Adjustment of the Low Tariff (Overnight) Charging Level

The HBSS is charged at night when the utility tariff is low. The overnight charging level is the maximum SOC that the battery should achieve during this period and should be adjusted according to operating conditions. For example, if the nighttime charging level has been set to a high value and the day ahead is sunny, the battery will be full and unable to receive any surplus PV energy during the day, which must therefore be exported to the utility (for little or no reward). On the other hand, if the next day is cloudy and the battery is not sufficiently charged during previous night, the battery may be completely discharged earlier than required and the household may have to buy energy from the supply utility at peak tariff prices. Five methods for adjusting the overnight charging level of the HBSS have been examined:


To determine the optimal overnight charging level for the yearly optimized case, the operation of the system has to be simulated using historical data and different values for the overnight charging levels for one year to find the minimum annual household energy costs and the maximum annual PV self-consumption ratio. As can be seen from Appendix A, the point which achieves minimum annual household energy costs and maximum annual PV self-consumption ratio is the point at 80% overnight charging level. This point is selected to be the yearly optimized overnight charging level for the house under study. The same procedure is followed to determine the optimal overnight charging level for the season optimized case (described next).


$$\text{Overnight charging level} = 1 - \frac{(1 - \text{C}\_{\text{PV}}) \times \text{E}\_{\text{PV}\text{gen}}e^{\text{expact}}}{\text{B}\_{\text{Capacity}}} \tag{1}$$

where BCapacity is the capacity of the battery (kWh), EPVgenexpect is the expected PV energy for the next day (this value is obtained using the forecasted PV generation pattern for the next day), and CPV is the annual PV self-consumption ratio without the HBSS: this is the average value of the ratio of the total daily PV energy directly consumed in the home to the total daily generated PV energy; this value is obtained by simulating the system for one year without using the HBSS. This value is assumed to be fixed for the whole year.

This mode eliminates export and minimizes the amount of peak tariff energy purchased since the battery is topped up using any excess PV and off-peak energy. The authors in [15] listed several effective forecasting methods for PV generation for the day ahead.

### 2.2.2. Charging Using Excess PV Energy

If the home is feeding power to the utility when there is surplus PV energy, the following rules are used to charge the HBSS.


### **3. Model Predictive Control-Based Energy Management System**

The MPC aims to optimize the control actions for the current sample. At each time step (t), the MPC performs an optimization process and computes an optimal control sequence for a finite horizon [28]. Only the first control action in the sequence is applied. Over the next time step (t + 1), the MPC receives new system measurements and recalculates the optimal control sequence for the next period.

In this paper, MILP optimization-based MPC is used to minimize the household energy costs, improve the self-consumption of PV generation and reduce energy lost through the control of the HBSS. The HBSS power settings obtained will ensure the best use of electrical energy. For every sample time, (1) forecasts for the profiles for PV generation and load demand over the next 24 h are obtained, (2) real-time measurements of the HBSS SOC are used to update the MPC, (3) MILP optimization is performed, and (4) the power references for the HBSS are updated. The time frame in which the MILP optimization is performed is t = 0:24 h. The optimization process is repeated every sample time (2 min). The HBSS control is optimized for subsequent time slots (from t = t + 1:24 h), noting that only the setting for the next time slot (t + 1) is sent to the HBSS.

### *3.1. Formulation of the Optimization Problem and Constraints*

MILP optimization is used to minimize the household energy costs [29]. MILP is an approach to optimization which solves constrained optimization problems which include an objective function and a set of variables and constraints [30]. The formulation of the problem is defined as:

> Objective : minimize = Cx Constraints : A.x ≤ b xmin ≤ x ≤ xmax

where x <sup>∈</sup> <sup>Z</sup><sup>n</sup> C, b are vectors and A is a matrix.

The objective function which needs to be minimized is the cost function in (2), which aims to minimize cost of energy and maximize the local use of the PV generation. The optimization finds the best solution to the objective function (2) from a set of potential solutions that meet the constraints, i.e., the equality constraints (5) and inequality constraints (9)–(15). A feasible solution is one that satisfies all constraints. The variables determined from the solution to the optimization problem are a set of optimal control settings "PHBSS(t)" for the next 24 h with a two-minute resolution. These settings are then forwarded to the HBSS.

The daily household energy costs "CHome" (2) that need to be minimized are comprised of payments (3) (e.g., for electricity purchased from the supply utility), and incomes (4) (e.g., for the energy exported to the supply utility) [31]. The constraints are divided into: (a) the equality constraint function (5), and (b) the inequality constraint functions (9)–(11).

$$\mathbf{C}\_{\text{Home}} = \mathbf{C}\_{\text{Home\\_buy}} + \mathbf{C}\_{\text{Home\\_sell}} \tag{2}$$

$$\mathbf{C\_{I\text{Home\\_buy}}} = \begin{cases} \begin{aligned} \stackrel{\text{T}}{\sum} \Delta \mathbf{T} \times \mathbf{TR\_{buy}}(\mathbf{t}) \times \mathbf{P\_{U\text{Lift}}}(\mathbf{t}) \end{aligned}, \mathbf{P\_{U\text{Lift}}}(\mathbf{t}) \ge 0\\ \begin{aligned} \text{0\text{ }P\_{\text{U\text{Lift}}}(\mathbf{t}) < 0 \end{aligned} \end{aligned} \tag{3}$$

$$\mathbf{C\_{Home\\_sell}} = \begin{cases} \begin{aligned} \sum\_{\mathbf{t}}^{\mathrm{T}} \Delta \mathbf{T} \times \mathbf{TR\_{sell}}(\mathbf{t}) \times \mathbf{P\_{Utility}}(\mathbf{t}), \mathbf{P\_{Utility}}(\mathbf{t}) < 0\\ 0, \mathbf{P\_{Ubility}}(\mathbf{t}) \ge 0 \end{aligned} \tag{4}$$

where CHome is the daily household energy costs (£); CHome\_buy is the cost of the energy purchased from the supply utility (£), CHome\_sell is the revenue of the energy exported to the utility (£), ΔT is the sample time (h); TRbuy(t) is the purchase tariff for electricity at time interval t (£/kWh), TRsell(t) is the sale tariff for electricity at time interval t (£/kWh), PUtility(t) is the electrical power drawn from the utility by the household at time interval t (kW): a negative value represents exporting power, whereas a positive value represents importing power.

(5)–(9) represent the model and the constraints of the home microgrid:

(5) describes the balance for the total active power in the home.

$$\mathbf{P\_{Utility}}(\mathbf{t}) + \mathbf{P\_{HESS}}(\mathbf{t}) = \mathbf{P\_{homo\_{hud}}}(\mathbf{t}) - \mathbf{P\_{PV\_{ym}}}(\mathbf{t}) \tag{5}$$

where Phome\_load(t) is the home's electrical load at time interval t (kW), PPV\_gen(t) is the power generated by the home PV system at time interval t (kW), and PHBSS(t) is the HBSS (battery + converter) power charged/discharged at time interval t (kW): a negative value denotes that the HBSS charges; a positive value denotes that the HBSS discharges.

The model of the HBSS is represented by (6) and (7):

$$\mathbf{E}(\mathbf{t}) = \begin{cases} \mathbf{E}\left(\mathbf{t} - \mathbf{1}\right) - \frac{\Delta \mathbf{T} \times \mathbf{P}\_{\text{bat}}(\mathbf{t})}{\eta\_{\text{d}}} \, \big|\, \mathbf{P}\_{\text{bat}}(\mathbf{t}) \ge 0\\ \mathbf{E}\left(\mathbf{t} - \mathbf{1}\right) - \Delta \mathbf{T} \times \eta\_{\text{c}} \times \mathbf{P}\_{\text{bat}} \, \big|\, \mathbf{P}\_{\text{bat}}(\mathbf{t}) < 0 \end{cases} \tag{6}$$

$$\text{SOC(t)} = \frac{\text{E(t)}}{\text{B}\_{\text{Capacity}}} \tag{7}$$

where Pbat(t) is the power charged/discharged by the battery at time interval t (kW); E(t) and E (t − 1) are the energy stored in the HBSS at times t and t − 1, respectively (kWh); η<sup>d</sup> , η<sup>c</sup> are the efficiencies of the battery when discharging and charging, respectively (%). BCapacity is the energy capacity of the battery (kWh), whilst SOC(t) is the state of charge of the battery at time t (%).

(8) represents the power converter model. The power converter receives its instruction from the HEMS and is used to control the HBSS.

$$\mathbf{P\_{HBSS}}(\mathbf{t}) = \begin{cases} \begin{array}{c} \mathbf{P\_{bat}(\mathbf{t})} \times \eta\_{\text{Conv}}, \text{ P\_{bat}(\mathbf{t})} > 0 \\ \frac{\mathbf{P\_{bat}(\mathbf{t})}}{\eta\_{\text{Conv}}}, \text{ P\_{bat}(\mathbf{t})} \le 0 \end{array} \tag{8}$$

where ηConv is the efficiency of the power converter (%).

The HBSS power constraint (9) defines the highest power (PHBSS max) that can be discharged/charged by the HBSS.

$$1 - P\_{\text{HABS max}} \le P\_{\text{HESS}}(\mathbf{t}) \le \|P\_{\text{HESS max}}\tag{9}$$

The HBSS SOC constraint (10) specifies the minimum and maximum SOC level of the HBSS. This constraint is used following the recommendation of the Institute of Electrical and Electronics Engineers (IEEE) [32], where the SOC constraints prevent deep discharge or overcharging of the HBSS to maximize the HBSS lifetime. Deep discharging and overcharging of the HBSS substantially reduce the battery life [33].

$$\text{SOC}\_{\text{min}} \le \text{SOC}(\mathbf{t}) \le \text{SOC}\_{\text{max}} \tag{10}$$

where SOCmax and SOCmin are the SOC limits (%) of the HBSS.

The battery power is classified as charging power and discharging power. The following constraints (11)–(15) are used to enforce the connection restrictions and make sure that the HBSS power is unidirectional during each sample time.

$$
\sigma\_{\text{disch}}(\mathbf{t}) + \sigma\_{\text{chang}}(\mathbf{t}) \le 1 \tag{11}
$$

$$\sigma\_{\rm{disch}}(\mathbf{t}) = \begin{cases} \ 1 \ \text{,} \ P\_{\rm{HBSS}}(\mathbf{t}) > 0 \\ \ 0 \ \text{,} \ P\_{\rm{HBSS}}(\mathbf{t}) \le 0 \end{cases} \tag{12}$$

$$\sigma\_{\text{char}}(\mathbf{t}) = \begin{cases} \text{1 }, \text{P}\_{\text{HESS}}(\mathbf{t}) < 0\\ \text{0 }, \text{ P}\_{\text{HESS}}(\mathbf{t}) \ge 0 \end{cases} \tag{13}$$

$$\mathbf{P\_{HBSS}}^{\text{disch}}(\mathbf{t}) \le \sigma\_{\text{disch}}(\mathbf{t}) \text{ . } \mathbf{P\_{HBSS \text{ max}}}^{\text{v}} \tag{14}$$

$$P\_{\rm HBSS} \stackrel{\text{charge}}{\text{(t)}} \text{(t)} \ge \sigma\_{\text{charge}}(\text{t}) \text{ . (} -P\_{\rm HBSS \, max} \text{ )}\tag{15}$$

σdisch(t) and σcharg(t) are binary variables that ensure the HBSS power flows in one direction for a particular sample time; PHBSSdisch(t) and PHBSScharg(t) are the HBSS discharge and charge power, respectively, at time interval t (kW).

### *3.2. Forecasting Methods*

The operation of the MPC requires the use of forecasting for load demand and PV generation. In this research, the load profile and PV generation profile forecasted for the next 24 h are used in the optimization process to find the optimal reference values for the HBSS. The following methods have been used to forecast the demand profile for the household for the next day:


For PV forecasting for the next day, three forecasting methods have been used:

• the previous day's PV generation profile (PV-PD).


### **4. Case Study**

The analysis undertaken is based around a typical UK house. It comprises common household appliances, rooftop PV generation and a HBSS. The house is connected to the supply utility. The household load profiles used are real measurements made in a UK based house [35]. This data is sampled with a one-minute resolution for a whole year. The total annual energy consumption for the home is 4104 kWh: this value is close to 4200 kWh which is the UK average for a medium sized house [36]. Measured data is also used for PV generation, obtained from the PVOutput.org website [37] for a 3.8 kW rooftop PV located in Nottingham. The data is for a full year with a sample time of one minute. The PV generation profile was scaled down to be equivalent to the PV generation of a 1.4 kW peak system, which was considered appropriate for the home under study.

Three electricity purchase tariff schemes were considered, namely: (a) Economy 7 (E7), (b) time of use (TOU), and (c) real-time pricing (RTP). The householders also have to pay a standing charge (24 pence per day) to account for distribution infrastructure costs. When selling surplus energy to the main utility, a fixed export sale price of 3.79 pence/kWh is used. The E7 purchase tariff values are from RobinHood Energy, UK [38]. The TOU purchasing tariff values are from Green Energy, UK [39]. The real-time pricing tariff values are derived from a dataset based on the total UK electricity consumption, available from New Electricity Trading Arrangements (NETA) [40], and lists the price per MWh associated with half hour timeslots. The export tariff values are from the Office of Gas and Electricity Markets (OFGEM) [41]. Figure 1 shows the different tariff schemes used in this research.

**Figure 1.** Values for Economy 7, time-of-use Tariff, and real-time pricing scheme.

The approach presented in [42] for determining the best size for an energy storage system was used to select an appropriately sized battery (in terms of energy and power rating) and to optimize the charging-discharging boundaries for the system presented in this paper. Investment costs were set at £135/kWh [43] for energy, £300/kW [41] for power. These investment costs include the installation cost of the HBSS. The parameters of the HBSS used in this research are shown in Table 1 [44,45].


**Table 1.** The parameters of the home battery storage systems (HBSS).

### **5. Performance Indicators**

Three performance indicators were used to quantify the performance of the HEMS:

• **Household energy cost increment ratio (HECIR):** The HECIR is the ratio of the actual household energy costs to the household energy costs that would be achieved in the ideal case, (16). If the value of the HECIR is 0, this means the system has ideal performance. As the value of the HECIR increases, this will indicate higher energy costs and lower system performance. The actual household energy costs are calculated using Equations (2)–(4). The ideal case for the household energy cost when using RTC will occur when the overnight charging level is determined accurately with zero forecasting error for PV generation. The ideal case for the household energy cost when using the MPC will occur when there is zero forecasting error for PV generation and load demand, and the lowest sample time of two minutes is used for the MPC implementation. For both of these cases the actual load/PV data is used for the forecast (i.e., there is an "ideal" forecast).

$$\text{HECIR} = \left(\frac{\text{Actual householder energy cost}}{\text{Household energy cost (ideal case)}} - 1\right) \times 100\tag{16}$$

• **PV self-consumption ratio (PVSCR):** This metric is used to calculate the quantity of the PV energy used in the home either directly or via the HBSS. The PVSCR is calculated by dividing the PV energy used in the house by the total PV energy generated, (17). A value of 100% indicates all the PV energy generated is used in the house and there is no export to the supply utility.

$$\text{PV self consumption ratio } = 1 - \frac{\text{E}\_{\text{PVgen}} \, ^{\text{expport}}}{\text{E}\_{\text{PVgen}} \, ^{\text{total}}} \times 100 \tag{17}$$

where EPVgen total is the total daily generated PV energy and EPVgen total is the total daily exported PV energy to the main electricity grid.

• **Energy lost ratio (ELR):** The ELR is determined by dividing all the "lost energy" by the all PV energy generated (18). The "lost energy" is the exported energy to the supply utility because of (a) errors in forecasting, (b) larger sample times which lead to inaccurate power settings for the HBSS, (c) periods when the HBSS is fully charged and no further surplus energy can be stored. Ideally this lost energy should be stored in the battery to be used at peak tariff periods. This ratio is used to assess the performance of the MPC operation, with 0% meaning no lost energy. As the value of the ELR increases, more lost energy will accrue, leading to higher energy charges. The ELR index incorporates both the (unwanted) export resulting from inaccurate HBSS reference settings and from any surplus energy from the PV generation system: note that the complement of the PVSRC only quantifies the exported energy from the PV generation system during the day.

$$\text{Energy lost ratio} = \frac{\text{E export}}{\text{Eept}\_{\text{\%en}}^{\text{total}}} \times 100\tag{18}$$

where EPVgen total is the total daily PV energy generated and E export is the total daily energy exported to the main electricity grid.

### **6. RTC-Based HEMS—Results**

### *6.1. Simulation Results for the RTC-Based HEMS for Two Days*

The operation of the RTC-based HEMS was simulated over two days to help with understanding the real-time dynamic performance of the RTC-based HEMS. The simulation process used the rule-based control algorithm defined in Section 2, as well as the different adjustment techniques for the overnight charging level, to assess the daily performance of the RTC.

Figure 2 shows the performance of the RTC for two consecutive days using the following overnight settings. Case 1: constant full overnight charging, Case 2: yearly optimized overnight charging, Case 3: seasonal optimized overnight charging, Case 4: previous day modification, and Case 5: weather prediction for the next day. A new, Case 6 (Ideal case), was also created to be used as a reference case. Case 6 is similar to Case 5, the only change is that the PV generation forecast in Case 6 is assumed ideal, i.e., zero forecasting error.

In Case 1, it is clear from Figure 2(b)-case 1 that in each of the two days, the HBSS was charged up to its maximum limit (90%) during the night while the days were sunny, so that much of the surplus PV energy was exported to the grid, as shown in Figure 2(c)-case 1, and not stored in the HBSS as shown in Figure 2(a)-case 1. The HECIR and the PVSCR for the two days were 43.67% and 62%, respectively, which were poor.

In Case 2, a yearly optimized overnight SOC level was selected (i.e., 80%). Figure 2(b)-case 2 shows that the HBSS was charged up to 80% overnight and then supplemented with the surplus PV generation available during the day. The HECIR and the PVSCR for the two days were 35.6% and 70.8%, respectively, which was an improvement on case 1.

In Case 3, selecting a seasonal overnight charging setting allowed the HBSS to be charged by surplus PV energy through the day. This achieved a lower HECIR (14.7%) and higher PVSCR (92.8%) compared to case 1 and case 2. It is clear from Figure 2(c)-case 3, compared to (c)-case 1 and (c)-case 2, that the exported energy to the main electricity grid decreased, which means higher PVSCR. Generally speaking, for summer the best overnight charging level should be the lowest one to maximize the PVSCR. These settings ensure lower household energy costs and higher PVSCR, if appropriately sized HBSS and PV systems have been selected in advance. For smaller battery capacities, the best charging level over the four seasons was found to be the maximum available.

In Case 4, it is assumed that the overnight charging level set for the first day was 60% as can be observed from Figure 2(b)-case 4. The first day was sunny and surplus PV energy was exported to the grid as is clear from Figure 2(c)-case 4. The RTC decreased the overnight charging level for the second day to 50% (i.e., decrease by 10%) to reduce the exported PV energy during the second day. The HECIR and the PVSCR for these two days were found to be 15.88% and 92.8%, respectively—these values are similar to the values observed in case 3.

In Case 5, weather prediction for the next day was used to accurately adjust the overnight charging level. For the house under study, it can be seen that 65% of the total generated PV energy was directly used in household consumption without contribution from the HBSS. The overnight charging level for each day was adjusted according to (1). The overnight charging levels for the two days were 48% and 52.5%, respectively, as can be seen in Figure 2(b)-case 5. The HECIR and the PVSCR for these two days were found to be 4.41% and 96.7%, respectively. It is clear from Figure 2(c)-case 5 that accurately adjusting the overnight charging level for each day minimizes the exported excess PV energy and maximizes the PVSCR.

**Figure 2.** The performance of the real-time controller (RTC)-based home energy management systems (HEMS) for two consecutive days using Cases 1–6, respectively; (**a**) the HBSS power settings obtained from the RTC, (positive—HBSS is discharging, negative—HBSS is charging); (**b**) the resultant state of charge (SOC) curve of the HBSS; (**c**) the resultant power from the supply utility, (positive—house is importing power from the utility, negative—exporting) and the associated E7 tariff values; (**d**) the household consumption and PV generation profiles for two consecutive days.

In Case 6, the ideal case, it is assumed that the PV generation for the next day was known perfectly (which is possible as we were using historic data) and was used to accurately adjust the overnight charging level (i.e., as discussed in case 5). This case is used as a reference case. The HECIR and the PVSCR, in this case, were found to be 0.68% and 98.8%, respectively—almost perfect.

### *6.2. Annual Performance Analysis for the RTC-Based HEMS*

The performance of the RTC-based HEMS was then tested for a one-year period to consider the yearly financial effect and to consider all four seasons of the year. This section assesses how the annual household energy costs and the annual PVSCR were affected using the five overnight charging modes, i.e., discussed in Section 2.2.1. Table 2 shows the annual HECIR and the annual PVSCR using the different overnight charging levels. The simulation results obtained in this section are for a full year to take into consideration all the seasons of the year.


**Table 2.** The annual Household energy cost increment ratio (HECIR) and the annual PV self-consumption ratio (PVSCR) obtained using different overnight charging levels while using the E7 purchasing tariff.

\* The next day PV forecast using the weather prediction is discussed more in Section 8.2.

The results presented in Table 2 are for the case in which the RTC-based HEMS is used to manage the household energy. No forecasted load demand or PV generation profiles were required in any of the five cases in Table 2 as RTC-based HEMS depends on the real measurements and a rule-based algorithm rather than predicated profiles to determine the HBSS settings for each time step. Only in case 4 is the PV generation forecast for the next day used (using weather prediction for the next day) but only to adjust the overnight charging level of the battery.

In case 4, the forecasted PV generation would normally be obtained for one time only (it is not updated at each time step) using the meteorological forecast data for the next day and a PV forecasting model. In this work, as historical data is being used, the forecasted PV generation profile was created by adding Gaussian noise to the actual PV generation profile of the current day. The Gaussian noise represents the MAPE for the forecasted profile. The value of the MAPE (14% in this case) was obtained from the results available from the Sheffield solar website for the forecasting of PV generation for the next day [46].

It can be seen from the results in Table 2 that accurate adjustment of the overnight charging level for the HBSS is very important and affects both the annual home energy savings and the PV self-consumption. If the appropriate overnight charging level is selected for each season (i.e., as in case 3), a lower home energy cost is achieved compared to case 2 and case 1. Case 5 (i.e., weather prediction for the next day) achieves the lowest annual HECIR compared to the other cases. It is also worth noting that in case 5, a continuous connection to the internet is required to download the weather forecast for the next day to be able to determine the overnight charging level of the HBSS. Additional costs may be required for a contract for a suitable forecasting package that updates the system with up-to-date weather prediction data.
