*4.4. Rule Engine*

The rule engine has a specific function and it may be labeled as the most important piece of the system regarding the application objectives, due to its capability to analyze information and ease decision-making. A rule engine may be viewed as a sophisticated "if/then" statement interpreter. In addition, the rules engine can handle a large number of rules with minimum impact on the normal execution flow of the process [38].

The main task of the rules engine is to ensure that the light values measured by the application are within the proper range. To perform this evaluation, the rules engine has several inputs, such as the measured illuminance, maintained illuminance, or the location characteristics, as well as the XML with the rules to perform the evaluation. Once the inputs have been analyzed, the results will show the recommended actions to guarantee the proper illuminance (Figure 2). Among the actions recommended by the application are: reducing or increasing the power of the lamp to adapt the lighting to the requirements of the regulation, reducing or increasing the distance from the light source, moving closer to or farther from the windows, or using light dimmers.

**Figure 2.** Rules engine working chart.

The selected rule engine was JRuleEngine, due to its open license, availability of source code, and practicality in the development of rules which may be described through an XML file. The Algorithm 1 shows an example of a rule extracted from the XML file. In this case, the rule checks if the level of measured light is correct. To perform this evaluation, the value measured is compared with maximum and average levels of illuminance required by the space regarding its specifications. As a result, if the measured level is between those two levels, the rule will call to a method that will inform the user that the level is correct.

