Performance Assessment of an Energy Management System for a Home Microgrid with PV Generation

: Home energy management systems (HEMS) are a key technology for managing future electricity distribution systems as they can shift household electricity usage away from peak consumption times and can reduce the amount of local generation penetrating into the wider distribution system. In doing this they can also provide signiﬁcant cost savings to domestic electricity users. This paper studies a HEMS which minimizes the daily energy costs, reduces energy lost to the utility, and improves photovoltaic (PV) self-consumption by controlling a home battery storage system (HBSS). The study assesses factors such as the overnight charging level, forecasting uncertainty, control sample time and tari ﬀ policy. Two management strategies have been used to control the HBSS; (1) a HEMS based on a real-time controller (RTC) and (2) a HEMS based on a model predictive controller (MPC). Several methods have been developed for home demand energy forecasting and PV generation forecasting and their impact on the HEMS is assessed. The inﬂuence of changing the battery’s capacity and the PV system size on the energy costs and the lost energy are also evaluated. A signiﬁcant reduction in energy costs and energy lost to the utility can be achieved by combining a suitable overnight charging level, an appropriate sample time, and an accurate forecasting tool. The HEMS has been implemented on an experimental house emulation system to demonstrate it can operate in real-time.


Introduction
Home battery storage systems (HBSS) and home energy management systems (HEMS) can be of significant benefit to future electricity distributions by moving household electricity usage away from peak consumption times [1] and reducing the amount of local generation penetrating into the wider distribution system. This can also potentially help to defer the cost of grid re-enforcement associated with the increasing penetration of electric vehicles (EV), the electrification of heating, and the rapidly increasing use of domestic solar panels [2]. This can also lead to reduced electricity costs for the domestic consumer. For example, employing HBSS to capture surplus photovoltaic (PV) energy or off-peak utility energy to meet demand at peak-tariff times has been demonstrated in [3], and the use of demand side management (DSM) and the evolution of real-time pricing schemes also add to the capabilities of the HEMS to economically manage domestic electricity consumption [4,5].
Home energy management can be "optimized" using approaches such as model predictive [6], mixed-integer linear programming (MILP) [7], geometric programming, and dynamic programming [8]. For example, the authors in [9] used MILP optimization to manage a home with a HBSS, a PV array, and an EV with a "vehicle to home" option. A DSM strategy based on dynamic pricing and controlling power peaks was proposed in [10] which used a MILP-based model of the structure with an EV and an energy storage system.
Reference [11] presented a MILP-based HEMS together with an artificial neural network which forecasted residential loads. The energy management systems (EMS) and the forecasting model (using an artificial neural network (ANN)) employed the sample time of one hour for the load forecast; this is a very crude indication of the load profile as these profiles vary at a much faster rate. A rule-based EMS which aimed for optimized operation of a battery for use in electricity distribution grids with renewable energy sources (RES) has been proposed in [12]. The EMS maximized the use of the RES and prevented reverse power flow into the distribution transformer. Reference [12] controlled the battery considering only the current operating conditions without taking into account any potential changes in operating conditions-this could lead to impaired system performance.
To achieve an effective control for a HBSS based on predictions of load consumption and PV generation, [13] divided a household storage controller into two levels: a global control level and a local control level. The global algorithm is formulated and solved by convex optimization to determine future charging/discharging schemes for the storage system. Reference [14] proposed an alternative energy management scheme, integrating RES, electrical battery storage, and vehicle to grid. "Accurate" results are claimed, but clearly only running the algorithm once each day and using a sample time of one hour for management will lead to lower system performance due to the uncertainty of the generation and load demand.
Forecasting methods for PV generation and electricity consumption have been examined as part of several different studies. For example, in [15] a comprehensive analysis of PV prediction methods was presented which divided forecasting into deterministic and probabilistic methods. Most of those studies used data from historical measurements and/or weather forecasts. A recent literature review categorized demand forecasting models as statistic based or artificial intelligence-based models [16]. In [17], a forecasting algorithm for home demand was presented. The forecasting algorithm used a short sample time to forecast home consumption for one day ahead. To the best of our knowledge, only a few of these studies quantify the influence of these forecasting methods on the effectiveness of HEMS for PV-battery systems [18,19].
There is a gap in knowledge for designing HEMS derived using the analysis of real load and generation data obtained from electricity prosumers. The current literature is found to include many studies which examine PV-battery systems using poorly justified assumptions concerning the HBSS model (idealistic models which can lead to significant errors in the calculated system financial returns [20]) and/or datasets with a low sample resolution [11] (which result in errors in the system design and sizing, as sharp and rapid power changes are not taken into account).
Many of the HEMS introduced in the literature (e.g., [21,22]) have not considered the effects of forecasting uncertainties or different sample times on the economic performance of the HBSS or have ignored the effect of accurately adjusting the battery's overnight charging level [23]. Furthermore, the effect of a combination of different forecasting methods on PV-battery systems is not well understood. A review [24] suggested that the impact of forecasting on economic performance has not been studied in depth. Many studies quantify the operation of PV-battery systems by employing only one forecast method or assume a perfect forecast. The literature concludes that further investigation is required into the influence of forecasting for electricity demand and PV generation on the performance of PV-battery systems.
In addition, the selection of an appropriate overnight charging level for PV-battery systems has not been properly considered in the literature [25]. A limited number of studies considered overnight charging [26,27], but the battery was fully charged overnight (during the off-peak electricity tariff period) as they did not include any intelligent overnight charging control algorithms. Selecting an appropriate overnight charging level enhances the economic performance of PV-battery systems.
This paper presents a detailed investigation of a HEMS which employs both a real-time controller (RTC) and a model predictive controller (MPC). Their performance is evaluated in the presence of forecasting errors for different control sample times and for different HBSS overnight charging levels and different tariff policies. The HEMS presented here aims to minimize home energy costs, reduce energy lost to the supply utility, improve the local consumption of PV generation (self-consumption), and decrease the system dependency on external systems for forecasting. Two types of management strategies have been used: (a) energy management based on a RTC, and (b) energy management based on an MPC. A case study for a home in the UK is presented, which has typical household appliances, rooftop photovoltaic (PV) generation and a HBSS. The key contributions of this work are:

•
This paper attempts to fill the gap in the literature by employing data for energy consumption and generation collected from real prosumers across the UK.

•
It studies the importance of designing an HEMS which is able to respond quickly to changes in the system by operating with a short sample time (in this case two minutes), and analyses the resulting impact on the annual energy costs and the ratio of annual lost PV generated energy to the utility.

•
It studies the performance of a HEMS which takes its own decisions locally while minimizing its dependence on external forecasting technologies (and complex communication infrastructures).

•
It summarizes the requirements and challenges for HEMS and their impact on household energy costs; this can be considered an aid to selecting an appropriate controller for each PV-battery system.

•
It studies the effect of forecasting errors, sample time resolution, tariff policies, the battery capacity and/or PV system on the performance of the MPC.
Experimental results for using an MPC-based HEMS are then presented to assess the performance of a real system. The paper is organized as follows: Section 2 introduces the operating algorithm for the RTC-based HEMS and the influence of the charging level for the low tariff period overnight. Section 3 describes the operating algorithm of the MPC-based HEMS. This includes system modeling and the formulation of the optimization cost function (which is solved using a MILP approach). Section 4 introduces the specific cases analyzed in this paper. Section 5 shows the performance indicators which are used to assess the results obtained. Section 6 shows the simulation results obtained using RTC-based HEMS. Section 7 presents the experimental results obtained for MPC-based HEMS. Section 8 shows the annual performance analysis for MPC-based HEMS, and finally, Section 9 presents conclusions from this work.

Real-Time Controller-Based Energy Management System
For this system, the HEMS aims to minimize the daily household energy costs, reduce energy lost to the utility, and improve local PV self-consumption by controlling a HBSS using RTC. The RTC uses a rule-based algorithm to control the HBSS. During the off-peak tariff period (i.e., overnight period) the controller charges the HBSS to a preset overnight maximum charging level. During the rest of the day, the RTC discharges the HBSS-it compares the power at the point of grid connection and tries to make this power equal to zero. The main rules used for this controller are summarized as follows:

•
If the household is drawing power from the supply utility at the point of grid connection, the HBSS tries to minimize the energy purchased by discharging the HBSS.

•
If the household is drawing power from the supply utility and the power drawn is greater than the maximum discharge power of the HBSS, the HBSS will discharge at its maximum power and the remaining power will be purchased from the utility.
• If the household is drawing power from the supply utility and the HBSS state of charge (SOC) reaches its minimum value, the HBSS will cease discharging.

HBSS Charging Mode
The HBSS is charged (a) overnight when the purchase energy tariff from the utility is low, and (b) if the home is feeding power to the utility at the grid-connection point because excess PV energy is available.

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: • Constant Full Overnight Charging: The battery charges fully during the off-peak tariff (i.e., night period from 12:00 to 7:00). There is no requirement to access the previous power profiles for load demand or PV generation. No weather forecasts or calendar timers are required [26,27]. • Yearly Optimized Overnight Charging: The battery is charged overnight to an optimized pre-set level (fixed throughout the year) depending on the battery capacity and the PV system size. This approach should yield better results than Constant Full Overnight Charging, as the battery is not always fully charged overnight and can be charged by any surplus PV generation.
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).

•
Seasonal Optimized Overnight Charging: Each season, the overnight charging level is adjusted to a different value. This value is selected based on the season and the PV and battery sizes. It is assumed that the HBSS contains a calendar timer to adjust the charging level at the beginning of each season. For example, for summer, the lowest charging level will be selected so that the HBSS is able to capture all excess PV generation during the next day. • Previous Day Modification: The overnight charging level is adjusted based on the charging pattern for the previous day. For example, the overnight charging level increases by 10% for the current day if peak tariff energy was purchased during the previous day. The overnight charge level for the current day decreases by 10% if surplus PV energy was exported to the power grid the day before.

•
Weather prediction for the next day (i.e., next day PV generation forecasting): Weather forecast data for the next day is used to adjust the overnight charging level of the battery which leaves capacity for the battery to be charged by the expected surplus PV generation the next day. Internet access is needed to download the meteorological forecast data for the next day and a PV forecasting model is needed to forecast the PV generation pattern. The weather forecast data is used to generate a forecasted PV generation pattern for the next day and then (1) is used to adjust the overnight charging level.
where B Capacity is the capacity of the battery (kWh), E PVgen expect is the expected PV energy for the next day (this value is obtained using the forecasted PV generation pattern for the next day), and C PV 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.

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.

•
If the home is feeding power to the utility, the HBSS charges to store the surplus energy. • If the home is feeding power to the utility and this is greater than the HBSS maximum charging power, the HBSS will charge at its maximum charging power and the remaining power will be fed into the utility. • If the home is feeding power to the utility and HBSS SOC reaches its maximum value, the HBSS will stop charging.

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.

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:

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 "P HBSS (t)" for the next 24 h with a two-minute resolution. These settings are then forwarded to the HBSS.
The daily household energy costs "C Home " (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).
where C Home is the daily household energy costs (£); C Home_buy is the cost of the energy purchased from the supply utility (£), C Home_sell is the revenue of the energy exported to the utility (£), ∆T is the sample time (h); TR buy (t) is the purchase tariff for electricity at time interval t (£/kWh), TR sell (t) is the sale tariff for electricity at time interval t (£/kWh), P Utility (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. P Utility (t) + P HBSS (t) = P home load (t) − P PV gen (t) (5) where P home_load (t) is the home's electrical load at time interval t (kW), P PV_gen (t) is the power generated by the home PV system at time interval t (kW), and P HBSS (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): where P bat (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); η d , η c are the efficiencies of the battery when discharging and charging, respectively (%). B Capacity 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.
where η Conv is the efficiency of the power converter (%). The HBSS power constraint (9) defines the highest power (P HBSS max ) that can be discharged/charged by the HBSS.
− P HBSS max ≤ P HBSS (t) ≤ P HBSS max (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].
SOC min ≤ SOC(t) ≤ SOC max (10) where SOC max and SOC min 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.
σ disch (t) and σ charg (t) are binary variables that ensure the HBSS power flows in one direction for a particular sample time; P HBSS disch (t) and P HBSS charg (t) are the HBSS discharge and charge power, respectively, at time interval t (kW).

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: • the previous day's load profile (L-PD). For PV forecasting for the next day, three forecasting methods have been used: • the previous day's PV generation profile (PV-PD).
• the average PV generation profile of the previous week (PV-AV). • the next day's weather prediction data + PV forecasting model to determine accurately the forecasted PV pattern for the next day (PV-FP) [15]. The next day's forecasted PV profile can be received and updated every sample time. This forecasting method needs continuous internet access. This service is available from the utility company or a retail agent for an extra cost.

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. 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. 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].  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].

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). HECIR = Actual household energy cos ts Household energy cos ts (ideal case) − 1 × 100 • 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.
PV self consumption ratio = 1 − E PVgen export E PVgen total × 100 (17) where E PVgen total is the total daily generated PV energy and E PVgen 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.
Energy lost ratio = E export E PVgen total × 100 (18) where E PVgen total is the total daily PV energy generated and E export is the total daily energy exported to the main electricity grid.

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.  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.

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.

Case
Overnight Charging Mode Annual HECIR (%) Annual PVSCR (%) 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.

MPC Based HEMS-Experimental Results
A laboratory system has been constructed to evaluate the performance of the MPC using a real HBSS in a typical operating environment. The MPC-based HEMS was tested experimentally for one day at the FlexElec Laboratory in the University of Nottingham, using the "Smart Home Rig" (SHR) shown in Figures 3 and 4.   This SHR comprises: • Home battery storage system comprising (a) BYD lithium-ion battery pack, 6.4kWh [44]     This SHR comprises: • Home battery storage system comprising (a) BYD lithium-ion battery pack, 6.4kWh [44]    • Smart meter: a three-phase smart meter used to measure PV generation, load demand, and the power imported/exported by the house from/to the supply utility. The smart meter uses a two minute sample time [50]. • PC: Core i3-7100 CPU, 3.91 GHz PC: the PC is used to run the HEMS. • Raspberry Pi: used as a Modbus communication interface between the smart meter and the battery management software on the PC. It is also used as a communication interface between the battery management software on the PC and the battery power converter to send the optimal power settings to the SMA converter of the HBSS, and read the actual SOC of the battery.

•
Software used: (a) MATLAB-to execute the optimization algorithm and perform the forecasting process, and (b) LABVIEW software package-to control the programmable load emulator.
The HEMS-based MPC was implemented experimentally. At each sample time (every two minutes): (1) the Raspberry pi measures the SOC of the HBSS (from SMA converter in the HBSS) and sends it to the HEMS; (2) a MATLAB script is used to execute the MILP optimization and calculate the optimal power setting for the HBSS; (3) the Raspberry Pi receives the HBSS optimal power setting for just the next sample and passes it to the HBSS's SMA inverter; (4) these steps are repeated every two minutes. Figure 5 shows the performance of the MPC-based HEMS for one day. The TOU tariff scheme and a fixed export electricity tariff were used in this experiment. The methods used for forecasting demand and generation are the previous week same day load profile (L-PWSD) and the previous day generation profile (PV-PD), respectively. The mean absolute percentage error (MAPE) for the load and generation forecasts were 29.3% and 22.66%, respectively. A two-minute sample time has been used-the MPC updates the HBSS references every two minutes and it can therefore respond to relatively fast disturbances in the system. The HEMS-based MPC was implemented experimentally. At each sample time (every two minutes): (1) the Raspberry pi measures the SOC of the HBSS (from SMA converter in the HBSS) and sends it to the HEMS; (2) a MATLAB script is used to execute the MILP optimization and calculate the optimal power setting for the HBSS; (3) the Raspberry Pi receives the HBSS optimal power setting for just the next sample and passes it to the HBSS's SMA inverter; (4) these steps are repeated every two minutes. Figure 5 shows the performance of the MPC-based HEMS for one day. The TOU tariff scheme and a fixed export electricity tariff were used in this experiment. The methods used for forecasting demand and generation are the previous week same day load profile (L-PWSD) and the previous day generation profile (PV-PD), respectively. The mean absolute percentage error (MAPE) for the load and generation forecasts were 29.3% and 22.66%, respectively. A two-minute sample time has been used-the MPC updates the HBSS references every two minutes and it can therefore respond to relatively fast disturbances in the system. A sample time of two minutes is the shortest sample time that can be used in this experiment. When a one-minute sample time was attempted for MPC operation, it was found that the MPC takes 5.62 min to perform just the optimization process, making a sample time of less than two minutes unfeasible for this experiment. A sample time of two minutes is the shortest sample time that can be used in this experiment. When a one-minute sample time was attempted for MPC operation, it was found that the MPC takes 5.62 min to perform just the optimization process, making a sample time of less than two minutes unfeasible for this experiment. Figure 5a shows that the HEMS/BESS matches the household demand from 16:00 to 20:00 (during peak-tariff hours) so the home did not have to import energy from the main utility during this period. The PV generation was used in the home (including charging the HBSS) instead of being exported to the utility. From 00:00 am to 07:00 am (off-peak tariff time), a greater amount of energy was drawn from the supply utility at the low tariff rate (5 pence/kWh) to cover the home energy demands and charge the HBSS. It is clear from Figure 5b that the HBSS was charged from both the surplus PV generation during daytime and the imported energy from the supply utility during the off-peak tariff time.
Unwanted export power can be seen in Figure 5a (negative values of the utility power (black) profiles). The reason for this unwanted export was the errors associated with the load and generation forecasts at certain points in the day (i.e., when there is a sudden increase or decrease of the load or generation/export at power levels higher than the BESS can manage). The unwanted export power was one of the reasons for the lost energy when using the MPC for HEMS. The HECIR and ELR were 27% and 14%, respectively.
It is clear from Figure 5b that the HBSS charged to 67% overnight (i.e., not to its maximum limit of 90%) because this overnight charging level (a) enables the HBSS to provide the expected load demand during the morning period (i.e., no energy is purchased from the supply utility from 7:00 to 10:00), and (b) leaves space for the surplus PV generation during the following day to be stored in the HBSS (i.e., no energy is exported to the main utility from 9:00 to 15:00). The battery is fully charged at 16:00hrs, ready for the peak tariff period.

Performance Analysis for the MPC-Based HEMS
This section will analyse the performance of the MPC-based HEMS over a one-year period.

Sample Time Resolution
With a sample time of 60 min for the MPC operation, the HBSS power settings received from the MPC optimization will stay fixed for 60 min. As a result, any change in generation and/or load in this period will be compensated by the supply utility to balance the total active power in the home (4) and this may affect the total energy costs. If a sample time of two-minutes is selected for the MPC, it will update the HBSS references every two minutes and therefore will respond to fast changes in load and generation to minimize the home's energy costs and reduce lost energy. Figure 6 compares the use of a 60 min sample time and a two minute sample time for the MPC. Figure 6a shows the HBSS power settings obtained using 60 min (red settings) and two minutes (blue settings), respectively. Figure 6b shows the power drawn from the supply utility when using 60 min (red) and two minutes (blue), respectively. Figure 6c shows the load and the generation profiles for a two-minute sample time.
It can be seen from Figure 6a that when a 60 min sample time was used for the MPC, the HBSS references remained constant for 60 min and changes in load and generation were compensated by the supply utility, as can be seen in Figure 6b. Energy is purchased from the supply utility during the peak-tariff period, and there is also unwanted export to the supply utility during the late afternoon. This export could be captured in the HBSS. Figure 6a shows that when the MPC updates the HBSS power settings (blue line) every two minutes, it can respond appropriately to fast changes in load and generation (seen in Figure 6c).  Table 3 shows the effect on the operation of the MPC using different sample times. An ideal forecast of load and generation was used for these tests so that the effect of sample time only was studied. The best case is where a two-minute sample time was used. Table 3. Effect of sample time on the MPC computational time, the annual HECIR, and the annual energy lost ratio (ELR). It can be seen that the computational time of the optimization process can pose a problem if too short a sample time is used. For example, it is seen that if a one min sample time is used, the MPC takes 5.62 min to perform just the optimization process (a much larger time for computation than the rolling step size itself). This makes the use of this sampling time resolution unfeasible. In addition, if a very short sample time is used, this will force the controller to respond to each and every change in the load or generation. The controller action then has a high frequency content which can affect the  Table 3 shows the effect on the operation of the MPC using different sample times. An ideal forecast of load and generation was used for these tests so that the effect of sample time only was studied. The best case is where a two-minute sample time was used. It can be seen that the computational time of the optimization process can pose a problem if too short a sample time is used. For example, it is seen that if a one min sample time is used, the MPC takes 5.62 min to perform just the optimization process (a much larger time for computation than the rolling step size itself). This makes the use of this sampling time resolution unfeasible. In addition, if a very short sample time is used, this will force the controller to respond to each and every change in the load or generation. The controller action then has a high frequency content which can affect the lifetime of the HBSS: the battery will be exposed to high operational stresses if it changes between charging and discharging too quickly.

Sampling Time Resolution (min) HECIR (%) ELR (%) MPC Computation
Usually, it is desirable to use a short sample time for the MPC. It can be seen from Table 3 that when a small sample time is used, this results in a lower energy cost increment ratio and a lower lost energy ratio. For a 60 min sample time for the MPC, the HECIR increases by 35.19% and the lost energy ratio increases by 29.86% compared with the smaller sample time. If a short scanning and response time is used, the MPC controller can respond to rapid changes in load and generation, and this therefore guarantees better performance and a greater reduction in costs for the householders. The compromise is that a longer computation time is required for the MPC optimization process.

The Effect of Forecasting Errors
To measure the accuracy of the forecasting methods for load and generation for the following day, the mean absolute percentage error (MAPE) is calculated (19).
where A t is the actual point, F t is the forecast and N is the number of forecasts considered. Table 4 shows the MAPE values for the forecasted load and generation for the next day using the forecasting methods listed in Section 3.2. The forecasted load and generation profiles using the methods (i.e., L-PD, L-PWSD, L-AV, PV-PD, and PV-AV) were found using the historical dataset available.  When using the PV-FP forecasting method, as historical data has been 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) is obtained from the results available from the Sheffield solar website for PV generation forecasting for the following day [46].
For the next day household demand forecasting using the L-FP case, an adaptive neuro-fuzzy inference system (ANFIS) forecasting method, developed in [51], was used. Other load demand forecasting techniques could be used to potentially obtain better results. Figure 7 shows the effect of forecasting uncertainty for both the load and generation on the annual HECIR and the annual lost energy ratio using the TOU purchasing tariff scheme. The sample time used in these calculations is two minutes and is fixed in all the cases to investigate the effect of the forecasting uncertainty only. It can be seen from the results that the forecasting uncertainty for the load demand and PV generation for the following day greatly affect the household energy costs and the lost energy ratio. The HECIR approaches 67.98% when using the L-AV and PV-AV forecasting methods (i.e., more than half of the cost that would be achieved when using ideal forecasting). Ideal forecasting is the perfect forecasting (100% accurate) of generation and load profiles for the next 24-h period, which can be created as we are using historical data profiles. The ELR also approaches 32.33% for the same case. This lost energy should be saved in the HBSS and used at the appropriate time period rather than being lost to the utility with little reward. From Figure 7 it can be seen that using a forecasting method such as L-FP and PV-FP achieves lower HECIR and ELR. It is worth noting that the actual HECIR and ELR will be higher than the values shown in Figure 7 if a longer sample time is used for the MPC.  Tariff   Table 5 shows the annual household energy costs calculated using the three purchasing tariff schemes shown in Figure 1. The sample time used in this section is two minutes and perfect forecasting was used for both the load demand and PV generation as we are using historical data.    Tariff   Table 5 shows the annual household energy costs calculated using the three purchasing tariff schemes shown in Figure 1. The sample time used in this section is two minutes and perfect forecasting was used for both the load demand and PV generation as we are using historical data. It can be seen from the results in Table 5 that lower home energy costs can be achieved using the TOU tariff compared to using the Economy 7 or the real-time tariff schemes. The TOU tariff offers lower energy prices during off-peak periods (i.e., 4.99 pence/kWh as shown in Figure 1), compared to the Economy 7 tariff (8.4 pence/kWh for the same off-peak period). Lower energy prices during off-peak periods give the HBSS a chance to store as much energy as needed at low cost to cover the home demands through the day. The TOU tariff also offers lower prices during the off-peak periods compared to the real-time (half-hourly) pricing scheme which can offer high prices at night (as can be seen in Figure 1). This is an area of ongoing research. Table 6 shows the impact of changing the capacity of the HBSS on the annual household energy cost and the PV self-consumption ratio using the TOU tariff scheme and 1.4 kW peak PV system. It can be observed that as the battery capacity increases, the household energy costs decreases and the PVSCR increases. The PVSCR also increases at a high rate when the battery capacity changes from 0 kWh to 4.8 kWh. However, the increment rate in the PVSCR is low when the battery capacity increases from 6.4 to 13.5 kWh. This is related to the rated size of the PV system (1.4 kWp); when the battery capacity increases beyond a certain size, this additional storage capability cannot increase the capture of PV generation (the remaining excess PV generation is at a power level above the power rating of the HBSS), and it therefore cannot improve the PVSCR. Table 6. Effect of changing battery storage's capacity on the annual household energy cost and the PV self-consumption ratio using TOU purchasing tariff scheme and 1.4 kW (peak) PV system. It is worth noting that as the battery capacity increases, the initial investment cost of the battery system increases as well. An optimization technique is required to select the best battery size which minimizes both battery investment cost and the annual household energy costs, as discussed in Section 4 and [42]. Table 7 shows the effect of changing the size of the PV system on the annual household energy cost and PV self-consumption ratio using the TOU purchasing tariff scheme and a 6.4 kWh battery. Different PV system sizes, from 1 kW to 5 kW, were used by scaling the PV data accordingly. It is clear from Table 7 that as the PV system size increases, the household energy costs decreases. Furthermore, it is observed that the PVSCR decreases instead of moving to 100% as the PV system size increases. The reason for this is due to the battery power limit (2.5 kW in this case); the additional PV generation is at a power level higher than the battery system's converter and therefore much of the surplus PV energy is exported to the main electricity grid. The appropriate PV system size for the house should be selected according to the household needs and in coordination with the power limits of the HBSS to improve the PVSCR and minimize the overall household energy costs. Table 7. Effect of changing PV system size on the annual household energy cost and the PV self-consumption ratio using TOU purchasing tariff scheme and 6.4 kWh battery.

Conclusions
This paper has assessed the performance of two home energy management systems based on (a) a real-time controller and (b) a model predictive controller over a one-year period. Using the real-time controller, the effect of adjusting the overnight charging level on the overall performance has been studied. The results showed that the lowest value for household energy cost increment ratio and the highest value for PV self-consumption ratio (i.e., 8.1% and 89.70%, respectively) could be achieved using a weather prediction for the next day to adjust the overnight charging level, but this would incur additional operational costs.
Load demand and PV generation forecasts can be made relatively easily using methods such as L-PWSD, L-PD, L-AV, PV-PD, and PV-AV, i.e., methods which use historical data only and do not require any complex forecasting model or meteorological data (i.e., temperature, irradiation, humidity, etc.), compared to using accurate prediction methods such as L-FP and PV-FP which require up-to-date weather prediction and complex modelling. L-FP and PV-FP forecasting packages achieve greater reductions in household energy costs and lower lost energy compared to simple prediction packages. However, these forecasting packages require a good communication infrastructure and also additional costs for complex modelling.
The performance of the MPC has been studied considering the effect of forecasting errors (this technique requires forecasting for its fundamental operation), the sample time, and different purchasing tariffs. The results show that with appropriate selection of the forecasting method for load demand and PV generation, a significant reduction in household peak energy demand from the supply utility and also the cost of home utility bills can be achieved. Using a 60 min sample time for MPC operation increases the household energy cost increment ratio by 35.2% and the lost energy ratio by 29.8% compared to using a two-minute sample time. Using a short scanning and response time of two minutes, the MPC controller can respond to changes in load and generation that occur over a short time, and therefore guarantees better performance and a higher reduction in costs for the householders. Using the time of use tariff scheme with a PV-battery system reduces the household energy costs even further compared to the other tariff schemes considered. Funding: This work is supported by the University of Nottingham, the Egyptian Government-ministry of higher education (cultural affairs and missions sector) and the British Council through Newton-Mosharafa fund.

Conflicts of Interest:
The authors declare no conflict of interest.