# Context-Aware Wireless Sensor Networks for Smart Building Energy Management System
## 4 Proposed EMS for SEEB
### Appliance Control Using Finite State Machine (FSM)  
In this deployment, we tested the ON/OFF control method which was implemented using FSM (Figure 12) [20]. In this implementation, FSMs control heaters where the context change drives transitions between states. Such implementation effectively minimized the processing load, especially when adopting multithreading in data acquisition and control.  
The proposed EMS, which adopts the classical control method (ON/OFF), was based on a set of predefined rules in the draft energy policy document. To apply these rules, the EMS represents each rule by a state in the FSM that is generated automatically by the system. For example, when the EMS is about to apply a control upon the heater(s) in a given room, it checks current conditions (season, building type, room type, day/night), then it constructs an FSM and links it to the heaters of that room. A given room's conditions include temperature, humidity, occupancy, and the door and window situation (open or closed). These conditions were transmitted to the server running the application via a WSN. The database server contains declared knowledge. For instance, the building type, source of energy (biomass/electricity), room type (bedroom, classroom, laboratory, office, meeting room, auditorium, number of heaters, number of windows). The room volume is an essential piece of information alongside the outside temperature that helps the heating system calculate the needed time to heat the room. The database also contains scheduled events, schedule of classes, etc. EMS considers the previous input parameters and the energy policy rules to control the heater(s). This control is implemented as an FSM. Figure 12 illustrates the state diagram of the FSM that controls a laboratory room called Linux Laboratory. This FSM has three different states. In State0, all the heaters are OFF. This state runs when the heating process is disabled, for example, during the holidays.  
A transition occurs from State0 to State1 when heating is enabled, for instance, during the working days. This transition is conditioned by having the temperature value less than min_value. When State1 is running, all the heaters are ON. The transition from State0 to State2 will occur when heating is enabled, and the temperature value is more than max_value. In State2, only two heaters are ON, while the other two heaters are OFF. Moving from State1 to State2 is the fluctuation process, which is possible only if heating is enabled. When the temperature value is above min_value and less than max_value, State2 runs. At the same time, State1 runs only if the temperature value goes below the min value. Finally, as long as conditions do not change, the current status remains the one running.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Knowledge** & **Data** & **Data Type** & **Sensor Module** & **Sampling Time Interval** \\ \hline \multirow{4}{*}{Occupancy} & Motion & Digital & PIR & Low \\  & Pressure & Analog & MPX4115A & High \\  & Sound & Analog & 2 PCS & High \\  & Gas & Analog & MQ-4 & Medium \\  & Camera & Analog & OV2640 & High \\ \hline Air & Temperature & Digital & DHT11 & High \\ quality & Humidity & Digital & DHT22 & High \\ \hline \multirow{4}{*}{Appliance status} & Light & Digital & MSE004 LSM & High \\  & Relay & Digital & SRD-05 VDC-SL-C SV & High \\ \cline{1-1}  & Power consumption & Analog & YHDC 30A & High \\ \hline \hline \end{tabular}
\end{table}
Table 9: Knowledge based on different sensor modules.