## 3 The Proposed Solution
### Fuzzy-Based Algorithm for Home Energy Management  
The proposed fuzzy-based algorithm monitors and controls the electrical appliances in the smart home, planning a convenient start time for them. In order to realize a cost-effective operation, the management algorithm deals with guaranteeing the supply-demand balance by taking into account the present electricity price and the state of energy storage system. The flowchart of the proposed HEM algorithm is shown in Figure 3.  
The starting point is represented by the time instant in which the consumer turns on an appliance (\(T_{start}\)). At this time, a proper signal is sent to the EMU in order to notify about this operation. Subsequently, the EMU interacts both with the smart meter and with the storage system in order to know about the TOU prices. As a consequence, the EMU is able to known the corresponding energy consumption prices at that particular moment and then can easily check whether the current time falls within peak hours. In the next step, the EMU verifies if the starting time of the appliance (\(T_{start}\)) falls outside the peak hours. If so, the EMU allows the appliance to start immediately; otherwise, the algorithm moves to the next step, because \(T_{start}\) is in peak hours. Considering that even standby appliances play a reasonable role in energy wastage [29], in the next step, the EMU checks for all of the standby appliances in home and turns them all off, regardless of their requests to be turned on. Subsequently, the EMU communicates with the local energy storage system in order to inquire about the locally-generated or stored energy. As a consequence, if there is enough energy in the storage system for the appliance, it is started immediately, without any delay. On the contrary, the algorithm goes ahead to the next step where a comparison between the power ratings is carried out. In fact, considering that in the proposed scheme, a threshold value of power (\(P_{thr}\)) is set, the EMU evaluates the power rating of the i-th appliance (\(P_{app}\)), and for every appliance request, its power rating is compared to the threshold value (\(P_{thr}\)). If \(P_{app}\leq P_{thr}\), then the appliance can start immediately; otherwise, the algorithm moves to the next step. In this case, the appliance operation is shifted from peak hours to off-peak ones. As a result, a delay (\(D_{app}\)), equal to the difference of the scheduled time suggested by the EMU and the request start time, is introduced in the operation of the appliance cycle due to the load shifting technique. It is necessary to note that this delay can be inversely proportional to the comfort level desired by the consumers. In fact, large delays can significantly lower their satisfaction. For this reason, in the proposed scheme, a threshold value of delay (\(D_{thr}\)) has been taken into account. Each device has its threshold value of delay. Figure 3: Home energy management (HEM) algorithm flowchart. In fact, in the next step of the algorithm, a comparison between the delays is carried out. If \(D_{app}>D_{thr}\), then the appliance can start immediately. The algorithm moves ahead in the next step if the previous condition is not satisfied. As a consequence, the appliance cycle is shifted to hours where electricity prices are comparatively low. Then, the EMU calculates the delay in the appliance cycle and sends it to the appliance in order to make it known what will be its start time. The scheduled time (delay) is calculated from the difference between the starting time of the appliance scheduled by the EMU and the request start time by the appliance. Subsequently, the scheduled time and the feedback previously provided by the consumer represent the input values of an FLC, described in detail in Section 3.3, that outputs the updated value of the scheduled time. Then, this value is both returned to the appliance, and the customer is notified. In the next step, the consumer may deny or accept the schedule proposed by the EMU.