An Evaluation and Implementation of Rule-Based Home Energy Management System Using the Rete Algorithm

In recent years, sensors become popular and Home Energy Management System (HEMS) takes an important role in saving energy without decrease in QoL (Quality of Life). Currently, many rule-based HEMSs have been proposed and almost all of them assume “IF-THEN” rules. The Rete algorithm is a typical pattern matching algorithm for IF-THEN rules. Currently, we have proposed a rule-based Home Energy Management System (HEMS) using the Rete algorithm. In the proposed system, rules for managing energy are processed by smart taps in network, and the loads for processing rules and collecting data are distributed to smart taps. In addition, the number of processes and collecting data are reduced by processing rules based on the Rete algorithm. In this paper, we evaluated the proposed system by simulation. In the simulation environment, rules are processed by a smart tap that relates to the action part of each rule. In addition, we implemented the proposed system as HEMS using smart taps.


Introduction
In recent years, sensors become popular and various sensors are placed in each home. These homes are called "Smart House, " and many applications such as healthcare are probable [1]. In the Smart House, Home Energy Management System (HEMS) realizes to save energy without decrease in QoL (Quality of Life) by controlling electrical appliances based on those situations [2]. Although the reduction effect of energy consumption depends on the rules, the rule-based HEMS is effective because sensing environment becomes realized and there are many situations to reduce energy consumption of electrical appliances. Thus, HEMS takes an important role in Smart House.
Currently, many rule-based systems to manage energy have been proposed. Almost all of them assume "IF-THEN" rules, and also our research group proposed related method [3,4]. The IF-THEN rules can be handled in production systems. The Rete algorithm is proposed to speed up the rule processing and is a typical pattern matching algorithm for production systems [5]. Moreover, an approach that distributes the Rete algorithm to some computers has been proposed [6]. Since a large number of electrical appliances, sensors, and rules are expected to exist in each home in the future, this distributed processing model is efficient from the perspective of availability and scalability, for example, building energy management system (BEMS), factory energy management system (FEMS), and community energy management system (CEMS). In addition, the effectiveness of rule-based energy management becomes higher in those large scale and complicated environments. However, the loads for processing rules are probable to concentrate to a specific computer because the existing work aims to distribute a specific part of the processes in the Rete algorithm. Therefore, we have proposed a rule-based HEMS using the Rete algorithm in order to reduce redundant processes and communication loads by the memory of processing results [7]. The proposed system assumes the distributed processing model, and information about electrical appliances and sensors is distributed to "smart taps" [8] in network. The smart tap is a power strip that executes computer programs and controls power feeding for each socket. To manage 2 The Scientific World Journal for electrical appliance in entrance , sensor data in living room If .type = "light" and .status = "OFF" and .type = "human detection" and .value = true Then turn on Algorithm 1: An example of rule. energy to electrical appliances, smart taps reason situations based on rules. The loads for processing rules and collecting data are distributed to smart taps. In addition, the number of processes and collecting data are reduced by processing rules based on the Rete algorithm. Accordingly, the proposed system enables the rule-based HEMS by low-spec and lowpower computing units because the processing loads and the data are distributed.
In this paper, we evaluated the proposed system by simulation. In the simulation environment, rules are processed by a smart tap that relates to the action part of each rule. In addition, we implemented the proposed system as HEMS using smart taps.
In the following, we explain the Rete algorithm and the existing technique in Section 2. The proposed system is described in Section 3. An evaluation of the proposed system is described in Section 4. The implementation of the proposed system is described in Section 5. Finally, we conclude this paper in Section 6.

The Rete Algorithm
The Rete algorithm is a typical condition matching algorithm for production systems [5]. In the Rete algorithm, a graph structure called Rete network is generated from rules. The Rete network has some types of node to filter data for each condition on rules, such as node and node. The node filters data from single input for each condition on a specific rule. On the other hand, the node joins data from multiple inputs for some matched data on a specific rule. All data are firstly processed on root node of the Rete network, and the data matched conditions of each node are repeated to be processed on the lower nodes. Each node memorizes the matched data and their sets as processing results. By the memory of processing results based on the Rete network, processes for matching condition on rules are reduced also when the data are changed. In addition, the TREAT algorithm has been proposed for an environment where the data are frequently updated [9]. The TREAT algorithm does not have the memories on the Rete algorithm. Algorithm 1 shows an example of the rule that represents "turn the lights in the entrance on if someone exists in the living room. " In addition, Figure 1 shows the Rete network generated from the rule of Algorithm 1 on the smart tap placed to the entrance. In the case of Algorithm 1 and Figure 1,  Figure 1: Rete network generated from the rule. data from electrical appliances or sensors are divided to "electrical appliance" or "sensor data" by those object types. After that, the data matched conditions of each node are sent to the lower node. Finally, the data satisfying all conditions on each rule are sent to the node showed as terminal node. The terminal node exists for each rule, and the data matching each rule are retrieved by checking corresponding terminal node. In Figure 1, the data that "someone exists in the living room and the light turned off in the entrance" reaches to the left terminal node. In addition, nodes and nodes memorize the processing results. For example, when the rule which has a condition "no one exists in the living room" is added, new node is added to the lower part of the node shown as " .value = FALSE. " The memory of the existing node is referred and the processes for common condition are reduced.
Currently, an approach that distributes the Rete algorithm to some computers has been proposed [6]. In the existing technique, the load of node on the Rete algorithm is distributed based on Chord [10]. In addition, the related data are shared on publish/subscribe (Pub/Sub) model [11]. However, the existing work aims to distribute the processes of nodes on the Rete algorithm. Thus, the loads for processing rules are probable to concentrate to a specific computer because the processes of nodes and collecting related data such as sensor data are executed by each computer. These redundant processes especially increase communication loads among the computers.

Proposed System
Currently, we have proposed a rule-based HEMS using the Rete algorithm [7].

3.1.
Overview. In the proposed system, rules for managing energy are processed by smart taps in network. The loads for processing rules and collecting data are distributed to smart taps. In addition, the number of processes and collecting data are reduced by processing rules based on the Rete algorithm.   Figure 2 shows an overview of the proposed system. In the proposed system, smart taps showed as 1 , 2 , and 3 are put all over the home and connected to LAN to communicate with each other. Electrical appliances are plugged in the smart taps placed near to or in the same room. Each smart tap feeds power to and controls the plugged-in electrical appliances. Sensors are plugged in the smart taps and connected to the LAN or publish observed data via resource networks such as wireless sensor network (WSN) [12][13][14] and semantic link network (SLN) [15,16]. The observed data such as user's location [17] are referred from other devices. Smart taps collect related information from electrical appliances and sensors to process IF-THEN rules based on the Rete algorithm. The smart taps memorize the processing results per each condition matching on rules and share the processing results with each other on Pub/Sub model. By sharing the processing results based on the Rete algorithm, the number of processes and collecting data for other rules are reduced. The rules are managed intensively by a specific computer on the LAN. The computer is called home gateway (HG). The HG delivers rules to smart taps when the rules are updated, and all smart taps understand the same rules.

Rule Processing.
We describe the flow of rule processing in the case of Algorithm 1 and Figure 1.
In the case of Algorithm 1 and Figure 1, the smart tap 1 in the entrance processes the rule of Algorithm 1 because action part of the rule is related to electrical appliances in the entrance. Firstly, the smart tap 1 checks the pluggedin electrical appliances. After that, 1 collects related data from other smart taps in the living room if 1 has pluggedin electrical appliances whose "type" is "light" and "status" is "OFF. " In the case of Algorithm 1 and Figure 1, the smart tap 3 is placed in the living room, and 1 requests to subscribe related data showed as " .type = TRUE" in Figure 1. 3 checks the requested data in processing results and publishes matched data to 1 . If 3 does not have the requested data, 3 collects the requested data from related sensors and memorizes the processing results. 1 joins the results of data about " .status = OFF" and " .value = TRUE" from 3 and turns the lights on if all conditions are satisfied. 1 memorizes these processing results and keeps them updated with reflecting changes of the data and reprocessing affected parts on rules.

Evaluation
In this paper, we evaluated the proposed system by simulation.

Simulation Environment.
In this simulation, rules are processed by a smart tap that relates to the action part of each rule. As an evaluation value, we measured the number of sending/receiving messages by each node as a load for collecting sensor and processing rules. The load of ( = 0, . . . , ) is . We used the load of each node to represent total loads of nodes and the maximum load of a node. In addition, the following fairness index (FI) is used as an index for load distribution: where 0 ≤ FI ≤ 1, and when FI = 1, 0 = ⋅ ⋅ ⋅ = . It is indicated that the closer FI is to 1, the more the load is distributed. Table 1 shows the number of each value in simulation environment. As default values of each parameter, the number of nodes is 2 5 , the number of sensors and rules is 100, and the number of the required sensors per 1 rule is 5. In this simulation, comparison methods to the proposed system "Rete" are "Server" and "Not-Rete. " In the "Server" method, a specific smart tap collects all sensor data and processes rules. In the "Not-Rete" method, each smart tap processes rules and collects related sensor data. Figure 3 shows the total load of all nodes and Figure 4 shows the fairness index of nodes by the number of sensors. The longitudinal axis is the total load of nodes or fairness index, and the lateral axis is the number of sensors.

Results by the Number of Sensors.
In these results, although the number of total sensor data is changed, the amount of sensor data required to process 1 rule is not changed. Therefore, in Not-Rete method, the load of each is always high in this simulation environment that has many rules. On the other hand, in server-based method and Rete-based method in Figure 3, the total load of all nodes is increased by the number of nodes because all sensor data are processed. However, as shown in Figure 4, the Rete-based method distributes the load to nodes widely. Therefore, the average load of node can be controlled by enhancing of nodes based on the system scale. Figure 5 shows the maximum load of node. The longitudinal axis is the maximum load of node, and the lateral axis is the number of sensors.
In the Figure 5, the maximum load of node in serverbased method is extremely increased by the number of sensors because a specific smart tap collects all sensor data. On the other hand, in Not-Rete method and Rete method, the maximum load of node is not increased largely. Figure 6 shows the total load of all nodes and Figure 7 shows the fairness index of nodes by the number of rules. The longitudinal axis is the total load of nodes or fairness index, and the lateral axis is the number of rules.   In Figure 6, the total load of nodes in Not-Rete method is increased because each node processes rules and collects related sensor data individually. On the other hand, in serverbased method and Rete-based method, the total load of nodes is not increased largely because the amount of processed sensor data is not increased largely even if the number of rules is increased. Figure 8 shows the maximum load of node. The longitudinal axis is the maximum load of node, and the lateral axis is the number of rules.

Results by the Number of Rules.
In Figure 8, the maximum load of node in Not-Rete method is increased because each node processes rules and collects related sensor data individually. On the other hand, in Rete method, the maximum load of node is not increased largely. Figure 9 shows the total load of all nodes and Figure 10 shows the fairness index of  nodes by the number of nodes. The longitudinal axis is the total load of nodes or fairness index, and the lateral axis is the number of nodes.

Results by the Number of Nodes.
In these results, the number of total loads of nodes is not changed in server-based method and Not-Rete method. Although the number of total loads is increased in Retebased method, the difference is not large in this simulation environment. On the other hand, as shown in Figure 10, the fairness indexes of Not-Rete method and Rete-based method are high, and the total load is distributed to the nodes even if the number of nodes is increased. Figure 11 shows the maximum load of node. The longitudinal axis is the maximum load of node, and the lateral axis is the number of nodes.
In the Figure 11, the maximum load of node in serverbased method is not changed because only one node collects 6 The Scientific World Journal sensor data and processes rules. On the other hand, in Not-Rete method and Rete method, the maximum load of node is decreased by the number of nodes. Figure 12 shows the total load of all nodes and Figure 13 shows the fairness index of nodes by the number of sensors per 1 rule. The longitudinal axis is the total load of nodes or fairness index, and the lateral axis is the number of sensors per 1 rule. In Figure 12, similar to Figure 6, the total load of nodes in Not-Rete method is increased because each node processes rules and collects related sensor data individually. On the other hand, in server-based method and Rete-based method, the total load of nodes is not increased largely by the amount of sensor data per 1 rule. Figure 14 shows the maximum load of node. The longitudinal axis is the maximum load of node, and the lateral axis is the number of sensors per 1 rule. In the Figure 14, similar to Figure 8, the maximum load of node in Not-Rete method is increased because each node processes rules and collects related sensor data individually. On the other hand, in Rete method, the maximum load of node is not increased largely.

Implementation
In this paper, we describe the implemented system of the proposed system as HEMS.

Smart Tap.
We implemented the proposed system as rule-based HEMS using the Rete algorithm and smart tap which has been developed in Enegate Co., Ltd., Japan (Enegate Co., Ltd., available at http://www.enegate.co.jp/ (in Japanese)). The smart tap is developed based on the Raspberry Pi Model-B (Raspberry Pi, available at http://www. raspberrypi.org/). The smart tap has a function of softwarebased breaker and can switch the power feeding of each socket ON/OFF based on various policies. The smart tap mainly consists of application layer and sensing/control layer. In the implemented system, the smart taps use data about electric power consumption of plugged-in appliances to manage home energy based on rules. The data are current [A], voltage [V], power [W], and energy [Wh]. The smart tap measures the data per 1 second for each socket. Algorithm 2 shows an example of the data about electric power consumption described in XML. The function of software-based breaker described above is executed by sending control commands to smart taps also described in XML. Algorithm 3 shows an example of the command that stops power feeding to socket 1.

Rule
Engine. In the proposed system, the decentralized smart taps collect necessary data and process rules autonomously. We have developed the rule engine executed on the smart tap based on Ruleby (Ruleby, available at  the proposed system, we have installed Ruby 1.9.3 and Ruleby to the smart taps. Table 2 shows the data registered to the rule engine. The data are about plugged-in electrical appliance and sensor data including the data about electric power consumption. In addition, we have defined each data as a class in Ruby. Algorithm 4 shows an example of the rule described in Ruby. The rule in Algorithm 4 is "if the electric power of TV in the living room is larger than 1 W, the system recognizes that someone exists in the living room and turns on the light. " The proposed system registers the rules such as Algorithm 4 and controls electric appliances based on the rules showed in Algorithm 3.

Conclusion
In this paper, we evaluated a rule-based Home Energy Management System (HEMS) using the Rete algorithm by simulation. In the simulation results, the proposed system distributes the load for rule processing to nodes and has achieved to reduce the maximum load of node compared with server-based method and Not-Rete method. In addition, we implemented the proposed system as HEMS using smart taps.
In the future, we plan to study the structure of nodes and other assignment methods of rule processing to nodes. For instance, categorization and hierarchization of nodes are probable in more large scale environments. For the other assignment methods, approaches based on frequency of referred rules and performances of node are probable. In addition, we plan to evaluate the proposed system in various environments that have many electrical appliances, rules, and nodes. Eventually, we apply the proposed system to large scale and complicated systems such as BEMS, FEMS, and CEMS.