An Event-triggered Online Energy Management Algorithm of Smart Home: Lyapunov Optimization Approach

As an important component of the smart grid on the user side, a home energy management system is the core of optimal operation for a smart home. In this paper, the energy scheduling problem for a household equipped with photovoltaic devices was investigated. An online energy management algorithm based on event triggering was proposed. The Lyapunov optimization method was adopted to schedule controllable load in the household. Without forecasting related variables, real-time decisions were made based only on the current information. Energy could be rapidly regulated under the fluctuation of distributed generation, electricity demand and market price. The event-triggering mechanism was adopted to trigger the execution of the online algorithm, so as to cut down the execution frequency and unnecessary calculation. A comprehensive result obtained from simulation shows that the proposed algorithm could effectively decrease the electricity bills of users. Moreover, the required computational resource is small, which contributes to the low-cost energy management of a smart home.


Introduction
The smart grid is the vision for enhancing the efficiency of electricity utilization from the production to end-user points, together with enabling consumer participation in the demand-side [1,2].Along with the growing importance of the smart grid, smart households that can monitor the use of electricity in real time have also received more attention in recent years [3].With the widespread deployment of advanced metering infrastructure [4], the two-way flow of electricity and real-time information is a remarkable feature of smart households, which offers numerous technical benefits and flexibilities to both utility providers and consumers.Those advantages include balancing supply and demand in a timely fashion and improving energy efficiency [5].
An important way to improve the operation utility of households is through a Home Energy Management System (HEMS) [6].It is employed to collect data from household appliances using smart meters and sensors [7] and then to optimize power supply and management with this information [8,9].It is expected to guarantee economic efficiency and operation security in households.These functions make HEMS act as the "core" of smart households.However, there are some major challenges for HEMS to play a role.The forecasting error increases due to the highly variable and unpredictable nature of renewable resources [10].Furthermore, it is challenging to manage energy without the future knowledge of time-varying load requirements and electricity prices [11].Fast and effective energy regulation is needed to satisfy the increasing demand of real-time decisions.
HEMS has been receiving significant research attention over the past few years [12].Currently, the research about HEMS falls into two major categories.In the first kind of HEMS, the electricity demand curve of household load needs to be forecasted.A large number of historical data needs to be analyzed statistically; thus, the operational complexity is relatively high.In [13], a non-intrusive load-monitoring technique is adopted to characterize the physical characteristics of household appliances based on historical data.The running time of appliances is further estimated.Additionally, the result is used for the power scheduling of enrolled appliances in order to save on electricity bills.In [14], an autonomous appliance scheduling method is proposed for a single home.Time-of-use probabilities of each device are used to generate optimal operating schedules of appliances.In the calculation of probabilities, weather conditions, day of the week and penetration level of appliances need to be considered.
In the second kind of HEMS, instead of forecasting the operating schedules of appliances, users need to set the running time interval and preferred time interval for scheduling regularly.Therefore, this method is not suitable for situations of random demand.Besides, this kind of HEMS mostly adopts traditional optimization algorithms, which are of high computational complexity.Apart from the consumption demand, other uncertain factors still need to be predicted, such as prices, distributed generation, outdoor temperature, and so on.In [15], a multi-objective mixed integer nonlinear programming model is developed for a single home.Additionally, the energy savings and a comfortable lifestyle are considered.Residents need to provide the running time range, the preferred time range for scheduling, the length of operation time and the estimated energy consumption.In [16], an intelligent home energy management algorithm is proposed for residential consumers.The household appliances are managed according to their preset priority and the comfort demand of users.The homeowner should set the comfort preference, load priority and running time range of appliances.In [17], an efficient scheduling method for household power usage is proposed to reduce electricity expenses and the power peak-to-average ratio.A genetic algorithm is adopted to solve the problem based on the combination of real-time pricing and the inclining block rate.It is necessary for residents to set the time parameters for appliances, such as the length of operation time, the operation time interval and the power consumption per hour.In [18], game theory is adopted for residential load management to minimize the energy cost and the peak-to-average ratio.The electricity price adopts the forecasted value.Residents need to select the beginning and the end of a time interval in which appliances can be scheduled.In [19], a home energy management controller is presented to reduce the electricity bill of consumers.The controller receives the forecasted outdoor temperatures and price signals as inputs.Users need to update the settings of appliances several times during a day, such as the preferred operation time interval of deferrable appliances, the power profile of non-flexible deferrable appliances, the required energy for flexible deferrable appliances, the preferred indoor temperature, and so on.
It can be seen that the existing research about HEMS is mostly based on the forecasting model and user intervention.As for the forecasting model, due to the strong randomness of the household load, the forecasting error of the load is relatively large [20], which makes the optimal schedule difficult to carry out.As for the user intervention, HEMS with too many preset parameters cannot perform well under the random demand of occupants.Meanwhile, the manual intervention of occupants breaks the intelligence of HEMS and affects the comfort level of occupants.Therefore, an online [21,22] scheduling algorithm that does not rely on any future information and user intervention is highly desirable [23].
In order to solve the above problems, an online [24][25][26] energy management algorithm based on event triggering is proposed.In this algorithm, we tackle the home energy management problem with the Lyapunov optimization approach, which is a useful technique for solving stochastic network optimization, particularly in queueing systems [27].Our main contributions are summarized as follows:

•
An online energy management algorithm based on the Lyapunov optimization method is developed.It does not rely on any future information and could quickly regulate energy flow under the fluctuation of distributed generation, demand and price.The decision at each slot can be made by only using the current observations.

•
Occupants do not need to manually preset the operation time interval of appliances.The energy management is implemented without user intervention, which can deal with the random demand.

•
The event-triggering mechanism is adopted to decide when to execute the online energy management algorithm, which reduces the computational cost significantly.The time complexity of the algorithm is O(1), which enables the algorithm to be applied in an embedded system and realizes the cost-effective management of smart households.
The rest of this paper is organized as follows.Section 2 describes the research object and basic models.Some basic concepts of online energy management algorithms are introduced in Section 3. In Section 4, the online energy management algorithm is proposed.Case studies and the analysis of the results are presented in Section 5. Finally, conclusions are given in Section 6.

Research Object
An overview of HEMS is shown in Figure 1.It consists of a photovoltaic (PV) power unit, local load, a monitor and a power controller.The monitor collects information about household demands, PV generation, market price, and so on.Meanwhile, the monitor performs the function of event triggering.Based on the information provided by the monitor, the power controller executes the energy management algorithm and controls the consumption of controllable appliances to lower the cost.

Event-Triggered Control System
Power Controller

PV Model
The PV power unit consists of PV arrays, inverters and other necessary components.The output of PV arrays is related to the illumination intensity, environmental temperature and the output voltage [28].The electricity produced by PV arrays is outputted through inverters and relevant filters.The unit is controlled by maximum power point tracking, which could guarantee the maximum output of PV arrays.
The information about PV generation is acquired by the monitor in real time.The instant PV generation can be denoted as T is the number of time slots in the operation cycle.In consideration of the high cost of energy storage devices, the smart home in this paper would operate without energy storage equipment.The main function of PV generation PV(t) is to supply household load instantly.

Load Model
Generally, a certain percentage of the power load of household users is elastic and controllable.The controllable load could help households realize demand response through adjusting the power level and operation time.According to the operation properties of appliances, household load is classified into two groups in this paper: 1. Baseline load: The appliances that must be served immediately at any time or need to be maintained on standby.This type of appliance includes illumination, computers, televisions and entertainment.The baseline load is assumed to be fixed and is not involved in the scheduling of HEMS. 2. Controllable load: The appliances that are interruptible and deferrable.After the starting time is set by users, this type of appliance does not need to run immediately, and the starting time can be deferred within the permitted time range.During the operation period, the operation status can also be adjusted, until its task is completed.This types of appliances include Plug-in Electric Vehicles (PEV), Electric Water Heaters (EWH) and Heating, Ventilation and Air Conditioning (HVAC).This paper mainly focuses on how to regulate the controllable load to decrease the cost with a guarantee on the comfort level of users.
In the controllable load, EWH and HVAC are special, as they have the function of storing heat.As a function of time, their energy consumption could be accurately estimated by an Equivalent Thermal Parameter (ETP) approach.This approach models the heating loads in a residence or small commercial building as a function of a few lumped parameters, weather and thermostat setpoints.Due to its accuracy of modeling residential loads, this modeling approach has been adopted for the current work.The heat transfer properties are represented by equivalent electrical components with associated parameters for modeling the thermostatically-controlled system of EWH and HVAC [29].
The modeling of EWH operation involves the heat exchange with the environment and inlet water.The thermal dynamic behavior of EWH can be described by differential equations [30].When EWH is on over the period [t k , t k+1 ], the water temperature at time t k+1 increases to θ k+1 , which is given by: Otherwise, when EWH is off over the period [t k , t k+1 ], the water temperature at time t k+1 drops to θ k+1 , which is given by: When the hot water has been used for multiple times and the water volume reaches the lowest bound, cold water is needed to refill the tank.The water temperature after adding inlet water is given by: where θ k is the water temperature at time t k .θ en is the temperature of the surroundings, i.e., the temperature of cold water.Q e , R e and C e are the related thermodynamic parameters of EWH.M is the capacity of the water tank.d k is the amount of inlet water added at time t k .Different residences have different preferable temperature settings for hot water θ set and acceptable variation ranges θ b .The comfort constraint for EWH can be described as: The modeling of HVAC operation needs to consider the heat exchange with surrounding air.The simplified modeling is well-suited for simulating residential and small commercial buildings.However, it may be unsuitable for large commercial buildings with multi-zone central heating and cooling systems.The thermal dynamic behavior of household HVAC can be described by differential equations [31].When HVAC is on over the period [t k , t k+1 ], the indoor temperature at time t k+1 increases to T k+1 , which is given by: When HVAC is off over the period [t k , t k+1 ], the indoor temperature at time t k+1 drops to T k+1 , which is given by: where T k is the indoor temperature at time t k .T 0 is the temperature of surrounding air.Q h , R h and C h are the related thermodynamic parameters of HVAC.Different residences have different preferable settings for indoor temperature T set and acceptable variation ranges T b .The comfort constraint for HVAC can be described as: The comfort level of consumers is reflected by the difference between the resultant temperature and the corresponding standard temperature.Equations ( 1)-( 3) and ( 5)-( 6) respectively describe the thermal dynamics of EWH and HVAC, which can be interpreted as a function of thermal parameters, ambient temperature and on/off statuses.Their thermal models are characterized by several lumped parameters.C e and C h are the equivalent heat capacities (J/ • C).R e and R h are the equivalent thermal resistances ( • C/W).Q e and Q h are the equivalent operational heat rates (W) [32,33].These thermal coefficients can be estimated with statistical and regression techniques by fitting the observed performance data to the equations [34].

Queues of Controllable Load
Controllable load is the regulation object in HEMS.The number of controllable appliances in the household is assumed to be N.The set of electricity demand for controllable load at time slot t can be described as: The electricity demand of the i-th controllable load L i (t) needs to satisfy: where L max,i is the maximum demand of the i-th controllable load.L(t) is generated randomly by consumers and does not need to be satisfied immediately.It can be deferred with a guarantee of comfort level for users.The set of actual electricity consumption for controllable load at time slot t can be described as: The actual electricity consumption of the i-th controllable load X i (t) needs to satisfy: where W i is the electricity consumption of the i-th controllable load per time slot.W i can adopt the fixed rated value and can also change at every slot according to the different working modes of the i-th controllable load.It can be represented as W i = ηE i , where E i is the rated value.η represents the adjustable interval of energy consumption and changes from zero to one.If the controllable load works under a fixed mode, W i adopts the fixed value, and the value of η is one.If the controllable load works under different modes, W i can turn into a different value through adjusting the value of η according to the current working mode.
The uncompleted electricity demands of the i-th controllable load are accumulated and thus form the queue of the i-th controllable load Q i (t).The queue represents the amount of electricity demand that needs to be completed.The set of controllable load queues at time slot t can be described as: Controllable load queues have the following properties: • Nonnegativity: The initial state Q(0) is assumed to be a nonnegative real valued variable.According to the definition of queues, it can be inferred that Q(t) ≥ 0 for all slots t. • Time-variability: The states of controllable load queues change with the random demands of consumers and the execution results of HEMS.Specifically, the future state of Q(t) is driven by stochastic arrival L(t) and execution process X(t) according to the following dynamic equation:

Information Vector
The household load is supplied by the PV power unit and the power grid jointly.PV power is preferred to improve the utilization of renewable energy.As the baseline load is fixed and cannot be scheduled, PV power supplies the baseline load first.After meeting the demands of baseline load, the extra PV power would be allocated among controllable loads according to priorities.The set of PV power that every controllable appliance gets at time slot t can be described as: The PV power obtained by the i-th controllable load S i (t) needs to satisfy: When PV power is not sufficient to satisfy all load demands, consumers need to purchase electricity from the power grid.The electricity price of the power grid at t can be denoted as R(t).
From the above, as for the i-th controllable load, the information vector Y i (t) could be formed by electricity demand from consumers L i (t), PV power S i (t) and electricity price R(t).
According to [5,[35][36][37][38][39][40][41][42][43], for the same type of problems, the harvested renewable energy, the load demand and electricity price are considered to be independent and identically distributed (i.i.d.) over time slots, such as the energy management problem of a single smart home in [35], the bidirectional transaction and load scheduling problem of multiple users in [5,[36][37][38], the demand response control problem of HVAC loads in [39], the PEV charging and vehicle-to-grid control problem in [40,41], the energy management of storage units in [42,43], etc.Therefore, in this paper, we assume that the information vector is i.i.d.over time slots.The set of information vectors for all controllable loads can be represented as:

Problem Formulation
As energy consumption of the baseline load is fixed, the corresponding electricity cost is constant.Therefore, the main focus of this paper is the cost generated by controllable load.Based on the above analysis, the amount of electricity that needs to be purchased from the power grid is: The value of X i (t) is either zero or W i .If X i (t) = 0, the allocated PV power S i (t) cannot be consumed, which is unreasonable.Therefore, the amount of electricity purchased from the power grid at time slot t in Equation ( 18) is further converted to The cost of the i-th controllable load can be denoted as c i (t), and the total electricity cost generated by all controllable loads at time slot t is: The energy management algorithm in HEMS is supposed to lower the cost as much as possible, so as to reduce the household expenses.Based on the above concepts, the online energy management problem in this paper can be described as: at time slot t, the power controller receives information vector Y(t).With a guarantee of comfort level and the stability of controllable load queues Q(t), the power controller aims at minimizing the electricity cost.Based on information vector Y(t), X(t) is determined to control the operation statuses of controllable appliances.As time goes on, the controllable load queues evolve based on Equation (13).The problem can be expressed as: 4), (7) and (11), controllable load queues are mean rate stable ∀i, t. (20)

Queue Stability
The queue Q i (t) is mean rate stable if: The energy management algorithm in HEMS is supposed to guarantee the stability of controllable load queues apart from minimizing the electricity bills of consumers.It should be ensured that consumers could accept the degree of load accumulation in queues, which means that the demands of controllable load will not be put off indefinitely.The stability of controllable load queues can be interpreted as the principle of HEMS that the load demand would not be unlimitedly accumulated and should be responded to as efficiently as possible.
Denote c * as the optimal objective value of Equation ( 20) and c * i as the optimal cost of the i-th controllable load.It can be shown that there exists a policy that can achieve the optimal solution as stated in the following lemma.Lemma 1.For Equation (20), there exists a stationary randomized policy that makes decisions X s (t) depending only on the system state and at the same time satisfies the following conditions: where X s (t), c s i (t), L s i (t) and X s i (t) are respectively the corresponding values of X(t), c i (t), L i (t) and X i (t) under the existing stationary policy.The expectations above are with respect to the stationary distributions of system state and the randomized control decisions.
Proof.The claims above can be derived from Theorem 4.5 in [44].In particular, the theorem implies that the sufficient conditions for the existence of a stationary and randomized policy as described in Lemma 1 are: first, the system state is stationary; second, the system variables satisfy the boundedness assumptions and the law of large numbers; finally, the problem is feasible.
The existence of such a policy can be used to design our online algorithm and to derive a performance guarantee for our algorithm, as shown later in Theorem 3. Accordingly, an Online Event-triggered Algorithm with Lyapunov optimization (OEAL) is proposed to stabilize the demand queues and thus to solve Equation (20).

Allocation Strategy of PV Power
PV power at every slot is set to first satisfy the demand of baseline load L b (t).Define N(t) = PV(t) − L b (t) as the excess PV power after meeting demand of L b (t).The excess PV power would be allocated to controllable load according to principles of priorities and the maximum delay limit.The order of precedence for PV power allocation is EWH, HVAC and PEV.The maximum delay limit of each appliance D max,i is set on the basis of their operation properties.The allocation strategy of excess PV power is described as follows.
(1) At every slot t, the delay condition of controllable load is checked in the order of priority.The length of controllable load queues represents the uncompleted demand.The value of X i (t) is either zero or W i .According to Equation ( 13), Q i (t) is composed of demand blocks W i , which means that Q i (t) is multiples of W i .Thus, Q i (t)/W i can represent the delay time of the i-th controllable load.If the delay time of the i-th controllable load exceeds the limit, i.e., Q i (t)/W i > D max,i , the appliance would get its corresponding PV energy S i (t) subject to the constraint Equation (15).The process continues until all of the controllable appliances are checked or PV power has worn out.
(2) If PV power is still left after the first step, the excess energy would be used to satisfy all of the accumulated demand in queue backlog Q i (t) in order of priority.Note that the maximum delay limit D max,i and priorities are only used in the allocation strategy of PV power and are irrelevant to the following strategy of scheduling controllable load.

Event-Triggering Mechanism
The event-triggering mechanism is implemented in the monitor and power controller.The monitor collects the information vector at a fixed rate and decides whether the triggering signal is generated to send to the power controller.Once the signal is received, the power controller will refresh its control actions, and the value of decision variables will be redetermined according to the current system state.Otherwise, decision variables will remain at the last value.
In terms of the event detection logic, the load scheduling process is affected by baseline load, controllable load, PV generation and electricity price.The monitor will generate a new signal to trigger the power controller if the following events occur.
• The variation of baseline load exceeds a certain range.
• At least one of the controllable load queues accumulates to a certain degree.
where W i is the electricity consumption of the i-th controllable load per time slot.Equation ( 25) means that the demand of the i-th controllable load has been piled up at least three times, and the power controller should be triggered to refresh its control actions.• The variation of PV output exceeds the accepted range.
• The time-of-use electricity price changes.
Note that the above thresholds are chosen empirically through simulation tests.Large thresholds in the above events could decrease the triggering times and thus reduce the computational cost effectively.However, the performance of the algorithm would be affected, as the decision variables will remain at last value.If the last value is zero, the appliances would keep the "off" state, and thus, consumers would suffer from the excessive delay of controllable load.If the last value is W i , the appliances would keep the "on" state, which may incur a large penalty on the electricity cost.On the contrary, small thresholds could guarantee the timely execution of the algorithm, but increase the triggering times and make the event-triggering mechanism invalid.In practical applications, the thresholds in the events can be set as adjustable parameters, which are set according to consumer preferences and weather conditions.
A state machine is well designed to realize the event-triggering mechanism.Three states, "event monitoring", "load scheduling" and "execution", are involved.The "event monitoring" state is at the beginning of the loop and is the most normal state of the state machine.Once one or more events are detected, the "load scheduling" state will be triggered to redetermine the operation status of controllable load.The "execution" state will then be triggered, and the instructions conveyed by the "load scheduling" state will be executed.After the execution is completed, it will go back to the "event monitoring" state and enter into the next time slot.The process is shown in Figure 2.

Lyapunov Optimization
2 is defined as a scalar measure of the congestion of all of the controllable load queues.Define the Lyapunov drift for slot t: where ∆(Q(t)) is the expected variation of the Lyapunov function over a time slot, which represents the stability of queues.The expectation depends on the control actions of HEMS and is related to the random arrival of load demands from consumers.
Based on the drift-plus-penalty method in Lyapunov optimization [44], an online energy management algorithm is designed in this paper.At every time slot, the current information vector Y(t) is observed.Based on the information acquired, the value of X(t) is determined to minimize the drift-plus-penalty expression: where the first item is Lyapunov drift, representing the queue stability.In the second item, V i represents the importance weight, illustrating how much we emphasize the cost minimization of the i-th controllable load.The rest of the second item is the cost incurred by the i-th controllable load.V i represents the tradeoff between stabilizing queues and minimizing the electricity cost.The physical meaning of V i (kWh 2 /RMB) is the increment on the variation of the Lyapunov function when the electricity cost decreases by 1 RMB.It unifies the measurement of the two different physical quantities and scales the conversion from the cost to the drift.V i is determined based on the power level of the i-th controllable load and the user preference between cost and delay.If V i = 0, it corresponds to the pure system stability problem by minimizing the Lyapunov drift.Minimizing ∆(Q(t)) alone would push all demand queues towards lower backlog, but would incur a large penalty on the cost.Therefore, the algorithm proposed in this paper minimizes the weighted sum of drift and penalty.
Lemma 2. (Drift bound) For any control policy that satisfies the constraints in Equation ( 20), the drift-plus-penalty expression satisfies: where the constant B i is defined as: Proof.A bound can be computed on the Lyapunov drift through its definition: and thus, B i can be defined as Equation (31).Using Equations ( 9) and ( 11), we have: Adding the utility function to both sides, we thus have Equation (30).The proof is concluded.
The original problem Equation ( 20) is transformed into the following problem by minimizing the right-hand side of Equation (30).4), (7) and (11), ∀i, t.
The above problem can be further reduced to the following simple threshold rule: It can be seen from Equation ( 35) that Lyapunov optimization is relatively simple to implement compared to the traditional optimization method.It does not need a priori statistical knowledge and only relies on the instant information about the system state at this moment.The complex energy management problem is transformed into a linear programming problem, which largely reduces the computational complexity.Furthermore, it has no curse of dimensionality and, hence, can be easily applied in extended formulations with multiple queues and multiple households.The overall flowchart of the proposed online energy management algorithm is shown in Figure 3.

Optimality Analysis
The performance of the online energy management algorithm is analyzed in this section.Some conclusions of the optimality are given in the following theorem.Theorem 3. Suppose that the system state Y i (t) is i.i.d.over time.If we use the proposed algorithm every slot t, then: (1) The proposed algorithm stabilizes the system, which means that the controllable load queues Q i (t) are mean rate stable and the constraints of original problem Equation ( 20) are satisfied.
(2) The time average expected cost under the proposed online algorithm is within B i /V i of the optimal value.lim sup (3) Suppose there are constants i > 0 and Ψ i ( i ) for which the Slater condition of Assumption 1 holds.Then: where min and c i,min , c i,max are defined as c i,min ≤ E{c i (t)} ≤ c i,max .
Proof.Since the system state Y i (t) is assumed to be i.i.d.over time and the related variables L i (t), X i (t), S i (t) and R(t) are all bounded, the conclusion in Lemma 1 holds.At every slot t, our implementation comes by minimizing the upper bound of the drift-plus-penalty expression.Plugging the conclusions of Lemma 1 into the right-hand-side of Equation ( 30) yields: Fix any slot τ.Take expectations of both sides, and use the law of iterated expectations to yield: Summing over τ ∈ {0, 1, • • • t − 1} for some t > 0 and using the law of telescoping sums yields: Rearranging terms and neglecting nonnegative terms when appropriate, the following inequality is obtained for all t > 0: Taking a limit as t → ∞ proves the conclusion in (2).
To prove the conclusion in (1), the following inequality is derived from Equation (40).
where E{c i (t)} ≥ c i,min .Using the definition of the Lyapunov function yields: Therefore, for all i ∈ {1, 2, • • • , N}, we have: Since the variance of |Q i (t)| cannot be negative, we have E{Q i (t) 2 } ≥ E{|Q i (t)|} 2 .Thus, for all slots, t > 0.
Dividing both sides by tand taking a limit as t → ∞ yields: Thus, all controllable load queues Q i (t) are mean rate stable, proving the result in (1).To verify the conclusion in (3), Assumption 1 is presented as follows.
Assumption 1 (Slater Condition): There exist values i > 0 and Ψ i ( i ) (where c i,min ≤ Ψ i ( i ) ≤ c i,max ) and a policy that only depends on the system state that satisfies: Plugging the above condition into the right-hand side of the drift bound Equation (33) yields: Taking iterated expectations, summing the telescoping series and rearranging terms yields: However, the limiting time average expectation for c i (t) cannot be better than c * i : Taking a limit of Equation (49) as t → ∞ and using Equation (50) could yield Equation (37).The proof is concluded.This theorem demonstrates the [O(1/V), O(V)] performance-delay tradeoff, which proves that the optimal time average cost of Equation ( 34) is within O(1/V) of the optimal value of the original problem Equation ( 20), with a corresponding O(V) tradeoff in the average queue length.By choosing a larger V i , the time average cost of the i-th controllable load can get closer to the optimal value, with the penalty on the congestion of demand queues.

Basic Data and Simulation Setting
In order to evaluate the performance of the proposed algorithm, the HEMS is developed in the MATLAB simulation environment.The time resolution of basic data is 10 min.The basic data of PV generation and baseline load are all collected from the real-time measurements from real households, which are shown in Figure 4.All data are gathered in winter, and HVAC is mainly for heating.The time-of-use price adopted in HEMS is shown in Table 1.
Table 1.Time-of-use price.

Time
Price (RMB/kWh) 10:00-15:00, 18:00-21:00 1.37 7:00-10:00, 15:00-18:00, 21:00-23:00 0.8 23:00-7:00 0.37 Electricity consumption of EWH, HVAC and PEV at each time slot is the decision variable.W i adopts the fixed rated value in the simulation.The related parameters of controllable load in the simulation are shown in Table 2.According to Equation ( 35), the setting of V i is related to the power level and deferrable degree of the i-th controllable load.On the one hand, as Q i (t) is composed of demand blocks W i , the length of Q i (t) increases with the rising of the corresponding power level.The appliance with a higher power level requires larger V i to achieve the same degree of delay, i.e., the same duration of X i (t) = 0. On the other hand, the appliance with the same power level needs larger V i to achieve a higher degree of delay, which means the longer duration of X i (t) = 0.As the power level and delay-tolerant degree of PEV are the highest among controllable appliances, the corresponding V i is the largest.The demand of EWH is given in real time based on the variation of water temperature.Additionally, the water temperature is simulated through the operation model of EWH.The standard temperature of EWH is set as 45 • C, and the acceptable variation range is 3 • C. When the water temperature is lower than the standard temperature, EWH is supposed to start running to raise the water temperature, which dynamically generates the demand of EWH.Similarly, the demand of HVAC is randomly given in real time based on indoor temperature variation.The standard temperature of HVAC is set as 21 • C, and the acceptable variation range is 2 • C. When the indoor temperature is lower than the standard temperature, HVAC is supposed to start running to raise the indoor temperature, which dynamically generates the demand of HVAC.

Appliance Operation Time Rated Power
In order to verify the effectiveness of the proposed OEAL, an Online Algorithm with only Current Information (OACI) and an Online Algorithm Without Event-triggering (OAWE) are taken as a comparison.Both OEAL and OACI only require the information of the current time slot.With only the current information, OACI does not consider the future variation of related variables.It only aims to obtain the minimum cost of the current time slot and does not take advantage of the deferrable properties of controllable load.Based on the same information demand and time complexity with the proposed algorithm, OACI is taken for comparison to better analyze the performance of OEAL.As another contrast, OAWE adopts a time-triggering mechanism to execute the Lyapunov optimization algorithm, where the control actions of HEMS will be refreshed at every time slot.OAWE is taken for comparison to analyze the effect of the event-triggering mechanism in OEAL.The comparison of the features for the three algorithms is shown in Table 3.

Comparative Analysis of the Results
The proposed algorithm only requires the current information vector Y(t).Neither the historical nor the future information is needed.Based on the same information requirement, OEAL is compared to OACI in the simulation.The time complexities of the two algorithms are both O(1).The comparison result is shown in Table 4.The comparison result of the operation time for PEV is shown in Figure 5. Compared to OACI, the proposed algorithm OEAL transfers the load from the peak period of price to the off-peak period after 21:00, which contributes to reducing the electricity cost for consumers.The comparison of the operation time for EWH is shown in Figure 6.Compared to OACI, the operation of EWH in OEAL avoids the peak period of price, which helps to realize the economic operation of households.
As shown in Figure 7, inlet water and the comparison of water temperature are illustrated through the simulation of the ETP model.The decline of water temperature at 17:40 and 23:20 is due to the cold water being added into the tank.It can be seen that the water temperature variation of OACI is smaller than the proposed OEAL.However, the switching frequency of EWH in OACI is much higher than the one in OEAL, which is harmful to the service life of EWH.Besides, the water temperature in OEAL varies from 42-47.5The comparison of the operation time and indoor temperature for HVAC is respectively shown in Figures 8 and 9. Compared to OACI, the operation of HVAC in OEAL avoids the peak period of price.For instance, during 11:50-15:00, when the electricity price is at its peak, HVAC stops running, and the indoor temperature decreases.At 15:00, as the demand queue of HVAC has accumulated to a certain degree and the price drops into the flat period, the HVAC starts running to guarantee the comfort level and economic efficiency of consumers.It can be seen from Figure 9 that the indoor temperature variation of OACI is smaller than the proposed OEAL.Nevertheless, the switching frequency of HVAC in OACI is much higher than the one in OEAL, which is harmful to the service life of HVAC.Besides, the lowest indoor temperature in OEAL is 19

Performance Analysis
According to the analysis of Theorem 3, the performance of OEAL is associated with the setting of weight parameters V i .In order to study the related performance of OEAL, the simulation analyzes the impact of weight parameters on the energy management result from two aspects: delay condition of controllable load and electricity cost.
It can be inferred from the theoretical analysis in Theorem 3 that when V i gradually increases, the average length of queues would increase, and the utility function would decrease.Based on the weight parameters set in Table 2, when V i of each controllable appliance varies individually, variation curves of average length for the corresponding queue and the electricity bills of controllable load are shown in Figures 10-12.Particularly, the load of EWH and HVAC is given in real time based on the variation of temperature.When the water temperature or the indoor temperature is lower than the standard temperature, EWH or HVAC is supposed to start running, i.e., L i (t) = W i , which generates their dynamic load demand.When the corresponding weight parameter V i changes, the deferrable degree and operation temperature all change, along with the variation of load demand.By contrast, the load demand of PEV is fixed.It can be seen from Figure 12 that the simulation result of PEV coincides with the theoretical law.In Figures 10 and 11, the simulation results of EWH and HVAC conform with the theoretical law on the whole, but fluctuate to a certain extent due to the influence of temperature and random load fluctuation.With the increase of V i , the weight of ∆(Q i (t)) in the minimizing object decreases, and the average queue backlog increases, which leads to the rise of delay time for the controllable load.Meanwhile, the weight of the utility function is raised, which leads to the decrease of the electricity cost for the controllable load.It can be seen from Figures 10-12 that the simulation results of the controllable load coincide with the theoretical analysis.With large V i , consumers can achieve a lower electricity bill, but will suffer from the excessive delay of controllable load.With small V i , the comfort level of consumers is guaranteed, and the demand of the controllable load will be completed quickly and efficiently.However, the electricity cost would be higher.In practical applications, consumers can set the weight parameters according to their own preferences.

Effect of the Event-Triggering Mechanism
In order to verify the effect of the event-triggering mechanism, OEAL is compared to OAWE, which adopts a time-triggering mechanism.In OAWE, the Lyapunov optimization algorithm is executed at every time slot, which means 144 times in total.However, in OEAL, the execution times reduce to 95, which largely decreases the computational cost of the power controller.The comparison result of the two algorithms is shown in Table 5.

Comparison with Related Work
In order to clarify the benefits and advantages of the proposed algorithm, the results are compared to several related papers mentioned in the Introduction, in terms of computational complexity, performance analysis, time cost, forecasting, data analysis, the need for user intervention and the implementation method.The comparison result is shown in Table 6.With respect to the computational complexity, most contrastive papers need to solve a multi-objective mixed integer nonlinear problem through traditional heuristic algorithms or advanced software, such as Advanced Integrated Multidimensional Modeling Software (AIMMS), while the proposed OEAL transforms the original problem into a linear problem, effectively reducing the computational complexity.In terms of the performance analysis, the cost savings of these papers are compared.As the basic data and scenarios in these papers are different, their simulation results are not comparable.However, it can be roughly concluded from the table that the proposed OEAL has a relatively superior solution among these papers.As for the time cost, some papers do not provide the related data.It can be observed that the proposed OEAL has the best time performance among the available results.In regards to the necessity of forecasting, most contrastive papers need to forecast related system states, such as real-time price, PV production, outdoor temperatures and the demands of non-controllable appliances, while the proposed OEAL does not rely on any future information.With respect to the data requirement, [13,14] respectively need to learn data of 20 days and data of a month, while the proposed OEAL only requires the data of the current time slot.As for the necessity for user intervention, in [15,17,19], consumers need to set the parameters of appliances, such as the length of operation time, the preferred time range, the priority, etc.In terms of the implementation method, most contrastive papers adopt the offline algorithms, where day ahead scheduling is conducted or related information is assumed to be known in advance.The proposed OEAL is implemented online, which only relies on the current information and is more practical in real applications.
Based on the above comparison and simulation results, the online energy management algorithm based on Lyapunov optimization proposed in this paper has strong practicality in smart homes.It is also suitable to be integrated into the embedded system for its advantages of low time complexity, high operation efficiency and small occupancy of computational resources.

Conclusions
In this paper, an online event-triggering algorithm for energy management of smart households is proposed to reduce the electricity cost with a guarantee of comfort level for household members.Household members do not need to manually preset the operation time interval of appliances.The energy management is implemented without user intervention, which can deal with the random demand of consumers.Without a forecasting mechanism, the data of PV generation and load demand are collected in real time.Controllable load EWH, HVAC and PEV are set as regulation objects.The Lyapunov optimization method is adopted to schedule controllable load in the household based only on the current information.The event-triggering mechanism is adopted to trigger the execution of the online algorithm, so as to cut down the execution frequency and unnecessary calculation.The simulation results show that the proposed algorithm could effectively decrease the electricity bill and guarantee the comfort level of users.Moreover, the time complexity is low and the required computational resource is small, which are suitable to be integrated into the embedded system.

Figure 1 .
Figure 1.Overview of a Home Energy Management System (HEMS).

Figure 2 .
Figure 2. Diagram of the event-triggering mechanism.

Figure 3 .
Figure 3. Flowchart of the online energy management algorithm.

Figure 4 .
Figure 4. Power curves of PV generation and baseline load.

Figure 5 .
Figure 5.Comparison of the operation time for PEV.

Figure 6 .Figure 7 .
Figure 6.Comparison of the operation time for EWH.

Figure 8 .Figure 9 .
Figure 8.Comparison of the operation time for HVAC.

Figure 10 .Figure 11 .
Figure 10.Average delay queue backlog of EWH and the electricity bills of controllable load.

Figure 12 .
Figure 12.Average delay queue backlog of PEV and the electricity bills of controllable load.

Table 2 .
Simulation parameters of controllable load.

Table 3 .
Comparison of the three algorithms.

Table 4 .
Comparison of the cost between OEAL and OACI.

of OACI (RMB) Cost of OEAL (RMB) Reduction Ratio (%)
• C, which does not influence the comfort level of household members.
• C, which does not influence the comfort level of household members in winter.

Table 5 .
Comparison of the cost between OEAL and OACI.It can be seen from Table5that the electricity costs in OEAL and OAWE are nearly the same.Their difference is mainly caused by the random load fluctuation of EWH and HVAC.The comparisons of operation time for EWH and HVAC are respectively shown in Figures13 and 14.It can be observed that the switching frequencies of EWH and HVAC in OAWE are much higher than the ones in OEAL, which does not bring extra profit, but only harms their service life.
Figure 13.Comparison of the operation time for EWH between OAWE and OEAL.Figure 14.Comparison of the operation time for HVAC between OAWE and OEAL.

Table 6 .
Comparison with several related papers.