# Building XAI-Based Agents for IoT Systems
## 3 Results--An Explainable Agent-Based Smart Home System
### The Steps for Developing an Explainable Smart Home Control System  
The proposed method has been adapted to implement a smart home control system. The experiment was carried out according to the steps outlined in Figure 2. _Matlab's Fuzzy Toolkit_ was used to define the control rules for **step 1** of the proposed method. For this purpose, the model was divided into 3 parts to represent the different controllers used in home automation: heating, ventilation, and lighting. The heating model with input data [temperature] and [presence] is shown in Figure 4. The heating model utilizes two inputs, temperature and presence, and one output, heating level. The [temperature] input is described by a membership function with verbal values of {very cold, cold, warm, hot}. The membership function is represented by Gaussian functions with temperature values ranging from 0 to 25 degrees Celsius. The [presence] input is described by a membership function with verbal values of {not present, present}. The output, heating level, ranges from 0, indicating heating is off, to 3, indicating high-level heating. The lighting model also utilizes two inputs, lighting and presence, and one output, lighting level. The [lighting] input is described by a membership function with verbal values of {very dark, dark, light, very light}. The membership function is represented  
Figure 4: Fuzzy heating model. Figure 3: Communication of hardware agents. by Gaussian functions with light values in lumens ranging from 0 to 3000. The [presence] input is described by a membership function with verbal values of [not present, present]. The output, lighting level, ranges from 0, indicating lighting is off, to 3, indicating high-level lighting. Finally, the ventilation model utilizes two inputs, temperature and presence, and one output, ventilation level. The [temperature] input is described by a membership function with verbal values of {cold, warm, hot, very hot}. The membership function is represented by Gaussian functions with temperature values ranging from 0 to 45 degrees Celsius. The [presence] input is described by a membership function with verbal values of [not present, present]. The output, ventilation level, ranges from 0, indicating ventilation is off, to 5, indicating high-level ventilation. To verify if the heating control rules covered all cases of control scenarios, the graph relationship between the heating level with temperature and presence is demonstrated in Figure 5. It was determined that when a person is present, the heating will gradually increase as the temperature inside decreases, with low heating activated when the room is warm, medium heating when it is cold, and high heating when the room temperature is very cold. When the person is absent, the system will maintain minimal heating to prevent damage to the room from cold and humidity. It was established that all scenarios had been accounted for, ensuring proper operation of the heating agent. The correlation between lighting level and luminosity within the room as well as presence is depicted in Figure 6. Through verification, it was determined that when an individual is present, the lighting level will gradually increase as the luminosity decreases, with 20% brightness activated when the light is low, 50% brightness activated when it is dark, and 100% brightness activated when the room is extremely dark. Conversely, when the individual is absent, the system will shut off the lighting to minimize energy consumption. It has been confirmed that all possible scenarios have been taken into consideration, thus ensuring the optimal functionality of the lighting agent. The relationship between ventilation level and temperature, as well as presence, is illustrated in Figure 7. Through examination, it was established that when an individual is present, the ventilation level will be adjusted proportionally to the increase in temperature within the room.