Energy Management of a PV-SB HPGS Based on Model Predictive Control

Background: Hybrid Power Generation Systems (HPGSs) always introduces the solutions for many problems of the power systems such as; poor power quality and the highly generation costs. Usually, these systems have high opportunity of utilizing the renewable sources, where they are installed so near to the customers. In some times, the customers whom have installed these systems, have the ability to purchase or sell the required or the surplus energy, respectively. Therefore, the concept of the energy management should be implemented in these situations, which means providing energy to the consumers while respecting the demand and optimizing the production cost. Supplying power has become more and more complex in a growing network. Several ways exist to adapt to the steadily increasing energy demand. The energy efficiency of the buildings/generators could be improved, or new electric supply units could be built. However, smarter techniques of managing the grid from the demand side receive an increasing attention by research and industry for a promising economic potential. Methods: The proposed HPGS in this paper is the combination of the Photovoltaic (PV) and the Storage Battery (SB). The Demand Response (DR) is the main philosophy for the energy management for PV-SB HPGS, while the Model Predictive Control (MPC) is applied to control the energy from the HPGS to the smart home, which was incorporated with an electrical heater in each room. The DR strategy has also been applied using other control techniques, such as thermostat and Proportional-Integral (PI) controller, for the purpose of comparing between the techniques. Results: Simulation results for the three controllers were implemented. A comparison between the results was carried out. to verify the proposed system, which proved the superiority of the MPC. Conclusions: A smart method for optimizing the comfort temperature inside the rooms by using a MPC strategy with a PV panel and a battery was proposed. DR allowed benefits on both system operation and market efficiency. MPC evidenced to provide economic benefits with respect to other compared controllers.


Introduction
The classical grid system is unidirectional and operates from the utility to the consumer [1].
Contractors usually bill a fixed price to their customers at the end of the month. A limited number of generators try to constantly supply enough energy to respect the demand. During a typical day, two peak consumption occur around lunch time and in the evening. These rush hours are difficult to manage for the grid which must mobilize more resources to satisfy the energy consumed by the households. Therefore, the utility cost is higher, which impacts on the customers' bill. This issue becomes even more complex with the unpredictability of renewable energy [2]. The research nowadays turns toward the demand side with an intelligent way to influence the loads. Indeed, the trend tends to the reduction and management of the loads instead of the construction of new generators. Demand side management allows to optimize the human comfort and health in the building while using the grid efficiently and inexpensively. To achieve this purpose, several techniques exist as in Figure 1. Every strategy applied in a large scale of buildings has a significant impact on the grid and allow to modify the supply/demand balance. The x-axis represents the time to activate the strategy whereas the y-axis evidences the impact on the household comfort. Energy Efficiency improvement is permanent in a building and is achieved by installing better isolation or less high energy devices. Time of Use (TOU) involves a change in the contract/tariffs to penalized consumption during certain hours. The DR influences the grid less than one day in advance and is therefore more flexible. There are two types of DR; Market based, or Physical/Incentive based. The DR based on the market consists of transmitting the price to the consumers, who would adapt their consumption and use the energy when the price is favorable. The consumption pattern is usually planned one day ahead according to the electricity price forecasts. Concerning the Physical/Incentive DR, the utility sends shedding requests to the households. This method is used in prevention of shortage or grid failure and is planned a few minutes ahead. In return, the households receive an economic benefit for the comfort inconvenience. The last category is the Spinning Reserve (SR). When the frequency drops in the grid, it means the energy supply is too low compared to the demand. SR devices measure this change in frequency and consequently adapt the load consumption in the house. A large-scale communication protocol is necessary to coordinate which households shed their loads.
MPC has been applied to many energy systems. A review on the usage of MPC to control renewable systems such as PV and wind has been presented in [3] to help in the controller design. Optimization for the daily operation to minimize the operation cost has been also studied using the same approach in [4]. A hybrid photovoltaic-wind-diesel-battery standalone system was optimized using actual forecasts of wind speed, temperature, irradiation and load. A model for the battery degradation estimation was involved in the proposed model. Extra costs were considered in case of diesel generator maintenance or replacement in up normal conditions. Based on Genetic Algorithm optimization, the total operation cost was compared with a cost found for a whole year yielding in 7.8% savings. Also, when compared to a -load flow‖ control strategy, it resulted in 37.7% savings. HPGS optimization in smart grid frame was studied in [5] in order to maximize the usage of the renewable energy and reducing utility grid supply. A realtime electricity pricing related to renewable energy was used in the optimization system to meet the demand based on a specific consumer performance. The approach was capable to select the prober renewable source to feed the demand optimally with robustness against uncertainties. The MPC approach improved the energy management and reduced the delay cost of energy demand from the utility.
A MPC along with a nodal pricing method was introduced by the authors in [6] for a novel load arrogation approach. It controlled a battery storage system, an electric vehicle, air condition, and a water heater for an energy management system (EMS) of a residential building, then tested on 15,000 buildings of a 342-node residential building IEEE distribution network. The results showed 21% generation cost reduction, 17% peak load reduction. Also, the same authors [7] studied that residential building energy cost savings in a year for TOU, hourly, and real time pricing, achieving 42% saving for building energy management in real time pricing. The authors in [8] also introduced a MPC method on a single family home to control a hot water and space heating simultaneously along with a SB. The model proposed showed a reduction of 11.6% in the operation cost per year when compared with a proportional-integral-derivative (PID) controller.
A PV-SB system is studied in [9] using a MPC algorithm for energy management purpose.
Optimum power generation was delivered to the system from the microgrid different sources.
The MPC also controlled the battery charging. Actual solar radiation and load profile were used in simulation results, which showed the reliability of the system with disturbances such as load variation and PV shading. A similar EMS was proposed based on a neuro-fuzzy inference system [10]. It was compared to a rule-based control strategy to test its reliability.
A home energy management (HEM) of a microgrid operating with a AC/DC bus was presented in [11] with a MPC algorithm. It incorporated two energy storage devices, renewable sources, and common Brazilian house loads. The model allowed user demand satisfaction and also economic benefits from the microgrid via reducing the purchased electricity. It also increased the lifetime of the used storage devices considering demand side management. Also, a HEM method was introduced in [12] for the same goals. It used an optimization based-rolling horizon technique for optimal determination of the storage devices settings considering real-time measurements with two minutes' interval to update those settings.
A prototype was presented in [13] incorporating both battery and load management systems. The battery management system decides either to connect to load or to charge while the load management system decides either the connection to the battery or to the grid, which is based on load type, charge, or the availability of the grid. That was obtained using Fuzzy logic. The energy consumed improvement with and without that system was presented.
Both Maximum Power Point Tracking (MPPT) and voltage regulation using a single-stage DC-DC converter with high gain was obtained in [14] for a grid-connected PV system. During fault, DC loads was still able to be supplied from a DC bus even with the inverter disconnection. Due to conversion stage reduction, the system efficiency increased. MPC was used also for simultaneous MPPT and voltage regulation in a two-stage grid-tied PV system [15]. MPPT algorithm was based on DC-DC boost converter while voltage regulation was needed to inject the proper value of PV output to the grid with high quality. Improvements as fast response and low overshoot were shown by the results.
In this work, DR is the strategy of interest. This involves the installation of a more enhance equipment such as smart meters [16]. These devices allow a two-ways/real-time communication between the grid and the households to transmit the requests, household consumption, or electricity tariffs. Many DR programs are ongoing on the European scale and in the U.S. significant economic savings were proven thanks to peak demand flattening that reduces the energy costs. Lack of interoperability between smart grid elements and technological immaturity of certain smart grid components represent the most common technical obstacle for the DR technologies. This paper assumes that the DR equipment is available in the household.
Electricity tariffs forecast is transmitted from the grid one day ahead. According to this prediction, a price-based DR strategy is carried out for one single building. For a large scale, if many households consume energy when the price is low, the DR purpose is achieved, and the power peak consumption flatten. This paper aims to maximize the temperature comfort in the building using a MPC technique while minimizing the electricity bill. Other techniquesthermostat controller and PI controller-were also implemented with a comparison between them for the proposed model verification.
The system description including the building model, the battery model and the PV model is described in section 2. Controllers used like thermostat controller, PI controller and MPC are introduced in section 3. Section 4 contains simulation results and discussion. Finally, the conclusions are in the last section.

System Description
A building containing many rooms with electrical heaters is considered as in Figure 2. The building uses one or several batteries to store energy and a PV panel generates electricity along the day. To develop a DR strategy minimizing the household bill, the electricity price, temperature and irradiance predictions are required. These variables are available through the smart meters or the weather forecast. A basic energy management consists of preheating the room when the price is low, charging the battery with the energy generated by the PV panel and use the energy stored when the price is high.
Electrical heaters are implemented in this paper framework because they are power varying loads that maintain a certain comfort inside the house. Generalizing these types of load, heat pumps, air conditioner, ventilator or electrical water boiler could operate in the house with the same DR strategy. Moreover, electrical heaters or water boilers are still installed in isolated building where it is difficult to access to set up a gas or fuel equipment.

Figure 2. Household features
Finally, with the emergence of clean energy and the demand side management, it is still impossible to predict whether electricity would become more attractive than the other fossil energy in term of heaters. To simplify the development, the building is simulated with a python program. The simulation must work for any kind of building topology. In this report, first the building model is presented followed by the temperature and battery control strategy. Then, the simulation is introduced. Finally, the results and future steps are discussed. The building contains three entities that need to be modeled; thermal model, the battery and the PV panel.

Building Model
The building is characterized by a thermal model according to the conduction and convection equations. All the computations are derived for a single room, considering a homogeneous wall.
The surface S groups every piece of walls surrounding the room. Figure 3 shows the physic constants of the wall, where represents the wall thickness, is the wall density, is the thermal conductivity, and is convection coefficient. Equation 1 represents the heat transfer inside the wall.
Where, is Temperature inside the wall, is the conduction coefficient, and is position perpendicular to the surface of the wall. Equation 2 represents the heat exchange between the air (either the outside or the room) and the surface of the wall. Here, represents the convection flux, is the inside or outside temperature, and is the surface temperate: ( Equations 1 and 2 are used to define a RC circuit describing the whole system. A thermal resistor limits the power flowing inside/outside the wall and a thermal capacitor emulates a delay for the heat to be transferred inside or outside. A parallel between a thermal model and an electrical model could be deduced as in Equations 3, 4, and 5. (3)   (8) air represents the specific heat of the air. The heater is added to the model as in Figure 5, The power is immediately injected inside the room. Equation 6 was a rough approximation, for further steps the wall could be modeled as Figure 6 which leads to more complex equations. In this paper, the model with one wall capacitor is used to remain simple, and the differential equations 9 and 10 are derived based on the RC circuit of Figure 5.
Since a numerical simulation do not work for a continuous model, the system must be discretized. Two different discretization methods are presented. Based on the Euler forward discretization, the derivative is simplified using the value of the next temperature sample as in Equation 11.
Applying from Equation 11 to 9 and 10 gives Equation 12 and 13.
With this derivative approximation, the sample time must be sufficiently small. Otherwise, the differential equation solution diverges. The system is described as a matrix Equation 14 and matrix , , are defined as in Equation 15. ins and are called states variables of the system.
Both of Equation 9 and 10 might be written in the continuous matrix form and in Equations 16 and 17.
This method starts from the state space Equation 18 and the generalized solution Equation 19 [17], and is the state variables and for the inputs. With being the sampling time. By solving Equation 22 and considering to simplify the notation, the discrete state space is obtained as in Equation 23 and the discrete matrices and .
[∫ ] (23) Then Equation 23 is applied to the thermal system as in Equation 24.
This method has the advantage to give the exact solution for any sample time. MATLAB or Python contain libraries which perform the discretization without going through all the computation. In python, control. returns the matrices in discrete time.
However, the computation cost is higher with the exact discretization because a matrix exponential and an integral must be solved. With the system in discrete form as in Equation 24, all the information to simulate the model of the room is available.

Battery Model
The maximum power that could be retrieved from a battery is limited and depends on the state of charge (SOC). The curve representing this maximum is highly nonlinear and is estimated by two straights. To obtain this approximation, the battery power is sampled for different SOC. When the battery is controlled, it is important to make sure that the battery set point is always below the maximum. Moreover, to avoid the battery to lose its capacity prematurely, the state of charge is restricted to an area above a minimum and below a maximum. Figure The energy of the battery and SOC vary according to Equations 25 and 26, is the continuous lost, is the efficiency, is sample time, is battery power, and is energy in the battery when fully charged.

PV Model
The PV panels are modelled according to their characteristics [17] and assuming a MPPT concept. The power production depends on the cell temperature. Cells vary in temperature not only because ambient temperatures change, but also because insolation on the cell changes. With the temperature coefficient of current.
being the MPPT cell output current in standard condition.
The PV generated power could be calculated based on Equation 32 and the available date in Table 1:

Energy Management Strategy
As mentioned before, the goal of this work is to find the best solution to minimize the electricity bill while respecting a certain comfort constraint (Inside temperature restricted between two boundaries). In this section, two common controllers regulating temperatures nowadays are described (Thermostat and PI). Those two regulators are associated with a simple rule base control for the battery. Then, the optimal controller for this study is presented. The performance would be compared with the two first solutions afterwards. For now, a building containing one room and one battery is considered.

Thermostat controller
A Thermostat is the simplest and most common controller in the households nowadays. The heater is turned on using the maximum power once the temperature reached a minimum and is turned off once the temperature is above a maximum. The battery is used to maximize the selfconsumption inside the house. An example of the temperature regulation with a thermostat is shown in Figure 8. The temperature is constrained between two bonds. The battery logic is shown in Figure 9. If the power generated by the solar panel is greater than the power needed to heat the house, the surplus is stored in the battery. Hence, no power is sold to the utility. The heater consumes the battery energy when the power required is above the generation power. The thermostat option is not optimal because the electricity price could not be considered.

PI Controller
A PI is a more advanced controller used for instance in a car to regulate the temperature more precisely. The goal of this controller is to track a reference ( ) as fast as possible and minimize the error in the steady state. Figure 10 shows  If is too small, the temperature converges to the reference slowly. If is too small, the controller would never provide enough power to track the reference. A trade-off must be found for the optimal gains. Figure 11 shows the PI with the optimal values ( = 1.6 and = 0.015). The error is immediately corrected which gives a signal oscillating around the reference. The battery logic is the same as the thermostat. A PI controller is a good solution to obtain the best comfort with a very precise temperature but do not account for the electricity price.

Model Predictive Controller (MPC)
A MPC (Model Predictive Controller) is chosen to be implemented in the system. This is the only controller able to consider the electricity price to plan an optimal schedule for the heaters and the battery set points. A MPC block diagram is shown as in Figure 12. This controller takes as input all the predictions, the comfort constraints defined by the resident and the actual states of the plant (the temperature inside the room and the wall). The wall temperature is not measured and therefore not available, for now, this temperature is considered as known.  To implement a MPC, an optimization problem needs to be solved. The mathematical problem is made of two distinct parts to minimize the electricity price while respecting certain constraints.
The objective function is to minimize the electricity price, while its constraints are the thermal model of the system must be respected, comfort constraints defined by the resident must be respected, and power for the heater and battery must be bounded. The objective function and constraints equations are taken as input. The optimal powers to apply to the system are computed and returned by the solver. Therefore, the way of solving an optimization problem is not detail in this section. For this problem, Equation (33) is the objective function. The objective function allows to modify the resident preferences according to priorities. To increase the comfort, the temperature is contained as close as possible to a reference instead of just being between two constraints. The electricity sold to the utility could be also minimized to encourage self-consumption. To account these criterions, another objective function, Equation 43 is implemented with additional terms:

∑ ( )
Coefficients and are tuned according to the objective. The higher is, the more the reference would be tracked with less consideration to the electricity price. The higher is, the higher the self-consumption is encouraged, and less energy is sold to the grid. Recall that is always negative, hence there is a negative sign before to minimize the power sold.
As mentioned, the maximum power curve for the battery, Figure 7 is non-linear and the MPC only accepts linear constraints. Thus, a new model is developed to approximate the maximum battery power curve for the minimization problem. Figure 16 shows the three different models were tested, where those models were simulated in different scenarios to determine which one  Figure 17 shows the scenario 1 power flow for the three models. In model A (Figure 17a), it is observed that the battery is initially charged very fast because the power allowed for 0.25 SOC is large. Then the power is relatively restricted for the rest of the simulation but is higher than the other models on average. Model B (Figure 17b) and C (Figure 17c) are relatively similar. Table 2 highlights the fictive cost for the different scenarios. It could be concluded that model B is the best model. Indeed, even if model A performs better for the 0.25 initial SOC scenario, it is only because the battery was charged very fast initially. Model A did not perform well for scenario 2 due to the MPC biased computations. Model B is always better than model C. It is not surprising because the MPC with model C would either perform wrong predictions or restrict the power available.  but not exactly the real plant. However, this approximation is good enough since the controller is robust to noise and corrects the mismatch model/reality. Of course, this assume that the states variables are known. It is not the case for this MPC and the wall temperature. Therefore, there are two issues to solve; The initial temperature inside the wall is unknown at the beginning of the simulation and must converge as fast as possible to the building wall temperature. While, the second is The wall temperature in the simulation must be as close as possible to the building wall temperature (which slightly differs to the wall temperature varying according to the thermal model developed in section 2) Thus, a mathematical entity called observer in the control theory is implemented. An observer checks how a physical variable behave by sending an input signal to the plant and watch the change in the output. Then, states variables are guessed. In this paper context, the room temperature is observed according to the power injected by the heater and the wall temperature is guessed. The bloc diagram of the system accounting for the observer is shown in Figure 18.
The wall temperature in the observer ( wall init) could be initialized to a random value.
However, if this value is close to the reality, the wall temperature would converge faster.
Therefore, the wall temperature is initialized as the average of the initial inside and outside To modify the transfer function of the observer system, two complex conjugate poles of must be chosen within the complex unit circle. If the poles are close to 0, the wall temperature converges very fast. However, a fast convergence implies a system more sensitive to temperature variation/noise which is always present in a room. If the norm of the complex poles is close to 1, the wall temperature converges very slowly. However, the system is less sensitive to temperature variations and noise. Thus, a trade-off must be found to adjust the complex poles.
To tune the observer, several simulations are performed with different complex conjugates poles values as in Figure 19. A noise with a constant biased is added to the temperatures given by the model to simulate the real temperatures as in Equation 50. The observer must be able to guess in which direction is the bias to converge to the building wall temperature.
(50) Figure 19a shows the wall temperatures with poles at (0.3 ± 0.1j). The poles are close to zero and the predicted wall temperature is sensible to noise. It is observed that when the power is abruptly changed by the MPC, it is difficult for the observer to adapt and guess the wall temperature correctly. Indeed, as seen in Figure 18, the power is an input of the observer and an abrupt change perturbs the system. Since the MPC base the computations on a noisy wall temperature, the power sent to the heater is also noisy. Figure 19b shows the wall temperatures the poles at (0.9±0.1j). These poles are close to the unit circle, therefore the wall temperature predicted converge slowly to the real temperature. However almost no noise is observed. Figure 19c shows the wall temperatures the poles at (0.6 ± 0.1j). These poles values evidence a fair balance between fast convergence and noise for this special case. The abrupt change in heater power sent by the MPC remains an issue difficult to manage. To find the best poles values, the standard deviation between the real and predicted wall temperatures is computed as in Table 3. Poles at ( ) clearly perform the best results. Without observer, the standard deviation corresponds to the error between the real and model wall temperature. This value is around 7.63 which is much higher than with an observer. The observer is also tested with a mismatch between the model and the reality. Figure 20 show the observer if in reality, the wall thermal resistor is 1.5 times smaller than what the model expects.
This time, because the temperature is less noisy, poles closer to the unit circle are a better choice (0.8 ± 0.1j) In that case, the wall temperature matches almost perfectly to the building wall temperature.

Results and Discussion
Every simulation was performed using test files to develop the MPC or the observer for one room and one battery. The provided program allows to generate a building with multiple rooms and different topologies. A server containing the information of the building is available. This database includes the rooms, the wall properties and if the walls contain doors or windows. The electricity price, temperature, and sun forecast are also obtained from this database. The program is composed of two entities; the simulator that emulates the building by using the database information and the EMS that contains the strategy implemented (MPC, PI, Thermostat). The simulator and the EMS are two process running at the same time. Every time step along the simulation, the desired heaters powers and batteries set points are sent by the EMS to the simulator. Then the simulator communicates the temperature and battery state to the EMS. Figure 21 illustrates the whole operation of the building simulation. While, Figure 22 illustrates the program structure with the main classes and function. All these entities allow to obtain all the data to implement our energy management strategy. In this section, the MPC without temperature tracking is compared with the PI and thermostat. A house with two rooms and one battery is considered. Figure 23 shows the outside temperature which is the same for every simulation. The outside temperature and electricity price are retrieved from a typical day Cairo, Egypt.

Figure 23. Outside temperature
The controllers are compared for a simulation lasting 24 hours with a ten minutes' time step. It was chosen that sending power to the grid do not bring money back. Figure 24 and 25 show the temperature and power plots for the thermostat developed model. The battery is used to maximize the self-consumption. It is observed in Figure 24 that between 12h and 16h, the battery is full. When all heaters are turned off, the energy generate has no other choice than be sold to the grid.   Table 4 shows the grid and thermal analysis for the different controllers. The standard deviation between the reference temperature and the room temperature is evidenced (err and err ) for both rooms and corresponds to a comfort measurement. The thermostat performs better than the PI in term of energy purchased. The MPC saves almost half of the electricity cost compare to the thermostat which is significant. However, this study does not account for the difference in comfort between the controllers.  The MPC with the tracking coefficient is compared to the PI controller. The tracking coefficient allows to tune the balance between the electricity cost minimization and a good reference tracking. The system is compared for , , and . Figure 29 highlights the difference in the inside temperature depending on how much the comfort is fostered with . Table 5 shows the grid and thermal analysis for the different controllers and value of the tracking coefficient q2.  The PI controller is still the best to optimize the comfort but has the highest cost. By setting to a high value, the electricity price and comfort of the MPC approach the PI values. Depending on the tracking error is reduced while the cost increases.
The horizon for which the MPC computes the optimal powers has a relevant impact on the price.
If the horizon is too small, the controller might not see that the price would be higher in the future and preheat the room/charge the battery. If the horizon is too large, the simulation completion time is too long. Moreover, it might be useless to use a very large horizon time.
Indeed, if the MPC detects a peak consumption in 4 hours and preheat the room, it is not useful to know that another peak electricity price would occur 8 hours later. Figures 30 and 31 show the difference in power for a horizon of 1.5h and 9h With a small horizon, it is evidenced that the power is used right before a price increase or right after a price decrease. This is due to a lack of long-term price consideration. With smaller horizon, there is less planning and the energy is stored less in the battery. For higher horizon, even if the prices increase in a short term, no power is used in prevention of more favorable time to preheat the room or charge the battery. Table 6 compare the simulation reports with the different horizons. It is observed that the price is smaller when the horizon grows. Small horizons even sell energy due to a bad planning.
However, the difference in price is small, especially for higher horizon. The simulation time gets significantly higher with larger horizon.
Comparing 6h horizon and 12h horizon, there is only 0.36$ cost difference and a simulation time difference of 2:21 minutes. Between 4.5h and 6h horizon, there is a simulation time gain of 0:31 for a cost loss of 0.92$ which would remain significant for a month (27.6$ in average). Thus, a 6h horizon is a good compromise between simulation duration and minimal cost.

Conclusions
Demand Response plays a major role in smart grids implementation and allows benefits on both system operation and market efficiency. A smart building solution evidenced a way to minimize the electricity bill of one residence while in a large scale supporting the grid to avoid peak energy consumption. An intelligent way to optimize the comfort temperature inside the rooms by using a MPC strategy with a PV panel and a battery was proposed. The building was modelled and simulated in a generic manner for any floor topology. The predictive controller enabled many possibilities to tradeoff between a better comfort or more economy savings. The study comparison evidenced a significant economic benefit of using a MPC instead of basic controllers such as a thermostat or a PI.