An Embedded Platform for Testbed Implementation of Multi-Agent System in Building Energy Management System

: This paper presents a hardware testbed for testing the building energy management system (BEMS) based-on the multi agent system (MAS). The objective of BEMS is to maximize user comfort while minimizing the energy extracted from the grid. The proposed system implements a multi-objective optimization technique using a genetic algorithm (GA) and the fuzzy logic controller (FLC) to control the room temperature and illumination setpoints. The agents are implemented on the low cost embedded systems equipped with the WiFi communication for communicating between the agents. The photovoltaic (PV)-battery system, the air conditioning system, the lighting system, and the electrical loads are modeled and simulated on the embedded hardware. The popular communication protocols such as Message Queuing Telemetry Transport (MQTT) and Modbus TCP / IP are adopted for integrating the proposed MAS with the existing infrastructures and devices. The experimental results show that the sampling time of the proposed system is 16.50 s. Therefore it is suitable for implementing the BEMS in a real-time where the data are updated in an hourly or minutely basis. Further, the proposed optimization technique shows better results in optimizing the comfort index and the energy extracted from the grid compared to the existing methods.


Introduction
An energy management system is one of the popular and challenging topics in the electrical power system.In recent modern Smart Grid technology, the research topics in the energy management system field have increased significantly, especially in the areas of home energy management systems (HEMSs) and building energy management systems (BEMSs).The authors in [1] propose a method to reduce the energy consumption by switching on/off the air conditioning (AC) and adjusting the temperature setpoint.The objectives are to reduce the electricity consumption of the AC unit in a way that the users do not feel any changes in temperature comfort.In the experiments, they change the temperature setpoint of the AC during a certain time interval and observe whether the comfort changes are felt or not by the users.The temperature setpoints are changed remotely using a centralized server.
The fuzzy logic controller (FLC) is employed in [2] to adjust the temperature setpoint of the AC units for energy management in residential buildings.The temperature setpoint is adjusted by a fuzzy inference system that considers four parameter inputs, i.e., (a) initial temperature setpoint; (b) outdoor temperature; (c) home occupancy; (d) electricity price.The system consists of two optimization units for handling the hot temperature setpoint and the cold temperature setpoint.An energy management system to control the AC unit and the electrical loads using control logic is proposed in [3].The control logic covers six functions i.e., (a) comfort, (b) economy, (c) emergency, (d) energy, (e) power, (f) thermal storage.The comfort function is used to ensure that the AC units and the electrical loads can be supplied with maximum comfort.The economy function optimizes the configuration of the AC unit and the electrical loads to minimize the cost.The emergency function is used during grid failures and allows the priority loads to be supplied by a battery system.The energy function is used to allocate energy consumption at a predefined time.The power function is used to ensure that the active power consumption does not exceed a fixed threshold.The thermal storage function is used to change the temperature setpoint of AC unit when the generated PV energy is greater than the consumption.
The authors in [4] employed a fuzzy system in their BEMS as the control strategy and prediction tool.In the control strategy, the FLC is used to control the solar thermal air system and the window-related use such as controlling the indoor temperature and light.The fuzzy prediction system is used to predict the energy demand and solar energy.The prediction system improves the energy efficiency due to the ability to predict the behavior of building in advance.A system to predict the energy demand of the building using the Artificial Neural Network (ANN) is proposed in [5].The ANN model is trained using the dataset of monthly historical energy consumption of the building.
Due to the distributed components (sensors, actuators, generators, loads) of the HEMS/BEMS, an intelligent multi-agent system (MAS) is widely adopted [6][7][8][9][10][11][12][13][14][15][16][17][18][19][20][21][22][23].The MAS is a distributed control system where each agent works autonomously and coordinates with each other to achieve the global goal.The implementation of MAS in the HEMS is proposed in [6][7][8].The MAS in [6] consists of the permanent agent, the temporary agent and the coordinator agent.The permanent agent is used to control the permanent loads, i.e., the appliances which run in a whole-time such as the refrigerator the air conditioner, the water heater.The temporary agent controls the temporary loads, which are divided into two categories: (a) the must run loads such as the lighting, the television, the cooking appliances, etc.; (b) the shiftable loads such as the washing machine, the dishwasher, etc.The coordinator agent is used for the message coordination, controlling and the decision making among the agents.The fuzzy logic controller (FLC) is employed by each agent to manage energy consumption.
The agents in [7] are grouped into three main agents, i.e., management agents, electrical supply system agents, and home appliance agents.The management agents consist of a supply side management (SSM) agent, which manages the electrical flow from the generator system, a demand side management (DSM) agent, which manages the electrical flow to the appliances, and the HEMS agent, which manages both SSM and DSM agents.The electrical supply system agents consist of a solar panel and storage system agent, main grid agent, and electric vehicle agent.The electric vehicle agent controls the charging/discharging of the battery of electric vehicle.Under normal conditions, the battery of electric vehicles will be charged.However under power shortage conditions, the battery may be discharged to supply the energy.The home appliance agents consist of the standing fan agent, rice cooker agent, air condition agent, television agent, etc.
A different MAS architecture of the HEMS is proposed in [8], where the agents are divided into four categories: (a) control and monitoring agents (CMAs), which are used to control and monitor the actuators and sensors; (b) information agents (IAs), which is used to handle the data related to the home devices; (c) application agents (AAs), which are used for prediction, scheduling and feedback functions; (d) management and optimization agents (MOAs), which are used for the optimization tasks.To manage the energy, the HEMS adopts four optimization strategies consisting of the comfort for user satisfaction, the reduction costs, the green energy efficiency, and the smart demand response.
The agents of the MAS employed in the BEMS [9][10][11][12][13][14][15][16][17][18][19][20][21][22][23] can be classified into four main agents, i.e., load agents, generator agents, central agents, and other agents as given in Table 1.The load agent handles the electrical loads in the buildings.The generator agent controls the generation system which supplies the electrical energy to the building.The central agent controls or coordinates the load and the generator agents.The MASs in [9,10,20] do not have a control agent, thus in [9], the load agent and the storage agent coordinate with the generator agent directly.Similarly, the heating agent and the cooling agent are connected to the electricity agent directly [10], while in [20], each local agent such as the local temperature agent is controlled by a load agent, then the load agents were connected to an intelligent coordinator.

Reference
Load Agent Generator Agent Central Agent Other Agent [9] Load agent Generator agent -Storage agent [10] Heating agent, Cooling agent Electricity agent -- The energy management system proposed by [26] allows the users (Smarthome or Smartbuilding) to exchange the local jointly renewable energy resources.This approach is based on the decentralized algorithm to optimize the energy from the renewable resource, i.e., to be exchanged with the neighbors, and to optimize the energy of the distribution network, i.e., to be delivered to the network or extracted from the network.The similar approach is proposed by [27], in which renewable energy is shared among the users.The users may lend/borrow the renewable energy to/from the neighbors.
As discussed previously, the BEMS, especially MAS-based BEMSs, are still rarely implemented on a hardware platform (more specifically an embedded platform), especially when AI techniques are adopted for solving the optimization problems.In this paper, we propose a hardware testbed implementation of the MAS-based BEMS.The novelty of our proposed system is the implementation of a GA-based optimization technique on an embedded platform to optimize the energy cost and user comfort in the building using only a few optimized parameters.Our proposed hardware testbed is focused on the electronics and communication parts for the real-time implementation of the algorithm.Our proposed MAS consists of the central control agent which is implemented on a Raspberry Pi module [37], the generator agent and the load agents which are implemented on Wemos modules [38].The main contributions of our hardware testbed system are fivefold: (a) It implements the genetic algorithm (GA) technique on the embedded hardware for real-time optimization of the BEMS; (b) It emulates the generator system and the loads on the embedded hardware; (c) It adjusts the room temperature and illumination setpoints according to the optimized power; (d) It implements the popular industrial communication protocol, i.e., Modbus protocol [39] for interfacing between the agents and the devices; (e) It implements the state of the art communication protocol in the Internet of Things (IoT) technology, i.e., the Message Queuing Telemetry Transport (MQTT) protocol [40] for communicating between the agents.
To the best of our knowledge, there are no prior works related to the first and second contributions or they are very rare.Furthermore, our proposed optimization technique, which is used to minimize the energy cost while maximizing the user comfort, utilizes a few parameters for calculating the objective function.Instead of using both the energy cost and the comfort parameters in the objective function explicitly [18][19][20][21][22][23]28,29], our method uses the energy cost parameter only, since the comfort parameters could be represented in the term of energy cost parameter as described in the following.The power consumption in each room, which is calculated by the load agent, reflects the user comfort (the thermal comfort and the illumination comfort) of the room, in the sense that high power consumption represents high comfort, and low power consumption represents low comfort.Then the total power consumptions of all rooms are considered as the energy cost that should be minimized.The advantage of using this approach is that only the power consumption data should be sent to the central control agent for the optimization calculation.The comfort data are handled by each load agent.
Related to the third contribution, compared to [2] where the method to adjust temperature setpoint is used to minimize the energy cost only, our method considers both the energy cost and user comfort.While the adoption of Modbus protocol provides a wide range implementation without replacing the existing sensor and actuator devices.
The selection of the MQTT protocol rather than the Lightweight Machine to Machine (LWM2M) protocol [41] is discussed as follows.Both the MQTT and the LWM2M protocols are lightweight protocols, which are suitable for the IoT applications.While the LWM2M protocol has a well-defined data and device management model, the communication data of the MQTT protocol must be developed from scratch.However, in the case of our testbed, we may have more flexibility to define the structure of communication data to fulfill the requirement of our proposed BEMS, when the MQTT protocol is employed.
The rest of the paper is organized as follows: Section 2 describes our proposed system.Section 3 presents the experimental results and discussion.Conclusions are covered in Section 4.

System Overview
The architecture of the proposed system is depicted in Figure 1.The proposed BEMS adopts the MAS to manage the energy and user comfort in a building, more specifically a university building.The testbed consists of the central control agent, the generator agent, and the load agents.In this work, the load agents consist of three load agents which are located in the classroom, the laboratory room, and the office room.Each load agent controls three kinds of loads, namely the lighting, the air conditioning (AC), and the electrical load such as the computer and the printer.The generator agent controls the utility grid, the photovoltaic (PV) and the battery systems.Meanwhile, the central control agent is used to control all the agents.
As described in [8], the MAS-based BEMS can participate in a demand response program, i.e., the user can change the power consumption to response the changes in the electrical price or the incentive tariff introduced by the utility grid, due to the availability of the smart metering and intelligent control system of the BEMS.As illustrated in Figure 1, the load agent, the generator agent, and the central control agent provide the functionality of smart metering and intelligent control.Further, the MAS-based BEMS could be extended to interact with the larger Smart Grid system [13].In the case of our proposed system, the integration with the Smart Grid could be done easily by extended the functionality of the central control agent to exchange information with the Smart Grid system such as the environment and the weather data, the generator, the storage, the loads, and the electrical networks.
In a more complex system such as the smart city [42,43], there are five energy-related activities, i.e., the generation, the storage, the infrastructure, the facilities and the transport [42].In this context, our proposed BEMS takes part in the facility activity that consumes the energy.The energy management of smart city as proposed in [43] employs the hierarchical decision control where each subsystem may have different control decision scheme.Due to the decentralized scheme of our proposed BEMS, it is suitable to be adopted in such hierarchical decision control architecture.

System Overview
The architecture of the proposed system is depicted in Figure 1.The proposed BEMS adopts the MAS to manage the energy and user comfort in a building, more specifically a university building.The testbed consists of the central control agent, the generator agent, and the load agents.In this work, the load agents consist of three load agents which are located in the classroom, the laboratory room, and the office room.Each load agent controls three kinds of loads, namely the lighting, the air conditioning (AC), and the electrical load such as the computer and the printer.The generator agent controls the utility grid, the photovoltaic (PV) and the battery systems.Meanwhile, the central control agent is used to control all the agents.
As described in [8], the MAS-based BEMS can participate in a demand response program, i.e., the user can change the power consumption to response the changes in the electrical price or the incentive tariff introduced by the utility grid, due to the availability of the smart metering and intelligent control system of the BEMS.As illustrated in Figure 1, the load agent, the generator agent, and the central control agent provide the functionality of smart metering and intelligent control.Further, the MAS-based BEMS could be extended to interact with the larger Smart Grid system [13].
In the case of our proposed system, the integration with the Smart Grid could be done easily by extended the functionality of the central control agent to exchange information with the Smart Grid system such as the environment and the weather data, the generator, the storage, the loads, and the electrical networks.
In a more complex system such as the smart city [42,43], there are five energy-related activities, i.e., the generation, the storage, the infrastructure, the facilities and the transport [42].In this context, our proposed BEMS takes part in the facility activity that consumes the energy.The energy management of smart city as proposed in [43] employs the hierarchical decision control where each subsystem may have different control decision scheme.Due to the decentralized scheme of our proposed BEMS, it is suitable to be adopted in such hierarchical decision control architecture.Since our proposed system divides a whole system into agents, it provides the flexibility to add the new agents to fit the requirements, for instance, to be extended to multi-commodity smart energy systems [44], where the hybrid energy systems (the heat and the electricity) are controlled.It Since our proposed system divides a whole system into agents, it provides the flexibility to add the new agents to fit the requirements, for instance, to be extended to multi-commodity smart energy systems [44], where the hybrid energy systems (the heat and the electricity) are controlled.It is also possible to extend the agents to form the group of interconnected users/buildings with the shared Energies 2019, 12, 3655 7 of 29 generator agents as proposed in [45].It is worthy to note that several MAS-based BEMS as illustrated in Figure 1 could be interconnected and coordinated in the energy district system as proposed in [46], where the several central control agents appoint a coalition coordinator to manage the energy in the district.
As shown in Figure 1, agents are implemented on the embedded systems in which the load agents and the generator agent are implemented on Wemos modules, while the central control agent is implemented on a Raspberry Pi module.A lighting simulator, AC simulator, and electrical load simulator are used to simulate the lighting, the AC, and the electrical load in the classroom, respectively.To provide a flexible implementation, a popular Modbus TCP/IP protocol is employed to communicate between the load agent and the devices.Fortunately, the Wemos is equipped with a built-in WiFi module, thus the Modbus TCP/IP protocol could be implemented easily via WiFi communication.A PV-battery simulator is developed to simulate the PV-battery system.Similar to the classroom, the simulator is implemented on Wemos modules and communicates with the generator agent using the Modbus TCP/IP protocol.The simulators in the laboratory room and the office room are developed in a rather different way.Instead of implementing the simulators on the separate modules, they are implemented in the same Wemos module with the load agent.
The objective of our proposed BEMS is to minimize the energy extracted from the grid while maximizing the user comforts.It deals with the multi-objective optimization problem.Instead of using the scheduling techniques [47,48], that manages the operation time of the controllable loads, our method controls the amount of power required by the loads.Thus it offers better control, in the sense that rather than switching-on/off the loads in a specific time interval (one-hour [47,48]), our method can adjust the power consumption of the loads in real-time, i.e., in one-minute intervals.
In this work, we propose a GA technique to solve the optimization problem and implement it on the control central agent.To provide a real-time implementation of the BEMS, the control central agent is implemented on a Raspberry Pi module.The Raspberry Pi communicates with the other agents (Wemos) via WiFi communication.Further, the MQTT protocol, a lightweight IoT protocol, is employed as the communication protocol.Compared to the method in [49] that combining the SCADA system and the Matlab software for implementing the optimization technique, our proposed method offers a simple and flexible approach due to the embedded hardware implementation.Thanks to the Raspberry Pi module that provides a small and powerful embedded computer.Further, our proposed testbed implements the Modbus protocol which is commonly used in the SCADA system.

Multi Agent Systen
To provide an easy explanation, the variables used in the proposed MAS-based BEMS are listed in Table 3.

Central Control Agent
The central control agent is the main agent that is responsible to manage the energy in the building by solving the multi-objective optimization problem as described in the following.The objective is to minimize power consumption, while maximizing the user comforts (temperature and lighting).Our multi-objective optimization problem is formulated using four objective functions and four constraints.The objective functions are expressed below Energies 2019, 12, 3655 9 of 29 Maximize (p 2 ) (3) Equation ( 1) represents the objective for minimizing the total power consumed by the classroom, the office room and the laboratory room, while Equations ( 2)-( 4) represents the objective for maximizing the user comfort in each room.It is noted here that instead of using the comfort index directly, we use the power consumption to represent user comfort.Therefore maximizing the user comfort could be defined by maximizing the power consumption of each room (Equations ( 2)-( 4)).This approach could be realized due to the fact that when the temperature and the illumination comforts to be increased, the power consumption will increase.The lower user comfort requires lower power consumption.This approach will reduce the number of parameters to be optimized.The objective functions in Equations ( 1)-( 4) only require three variables, i.e., p 1 , p 2 , p 3 that should be provided in the central control agent.Thus it offers an efficient data exchange between the agents.
The constraints are formulated using the inequalities as expressed by Equations ( 5)-( 8).The constraints in Equations ( 5)-( 7) are the lower and upper bounds of the power consumptions which are used to ensure that the optimized parameters p 1 , p 2 , p 3 fall in the allowable range of the user comfort.While the constraint in Equation ( 8) ensures that the power consumption of the building could be supplied by the generator systems (the renewable energy resources and/or the utility grid).
To solve the above multi-objectives optimization problem, we adopt the Multi-Objective Genetic Algorithm (MOGA), more specifically the NSGA-II as proposed by [50].The MOGA is implemented on the central control agent to find the optimal power required by the building based on the current power consumptions and the generated power as illustrated in Figure 2. As shown in the figure, the inputs of the central control agent are the minimum and maximum power consumptions of the classroom, the office room, and the laboratory room, the power produced by the battery and the PV.Then these values are used by the MOGA to solve the multi-objective optimization as expressed in Equations ( 1)- (8).The outputs of the central control agent are the optimal values of power required by the classroom, the office room, and the laboratory room which are sent to the respective agents.
The power required by the classroom, the office room, and the laboratory room are the optimal values that should be consumed by the respective loads.Then the respective load agent control its loads to satisfy the power requirement using the strategy as described in the following section.
Energies 2019, 12, x FOR PEER REVIEW 9 of 29 directly, we use the power consumption to represent user comfort.Therefore maximizing the user comfort could be defined by maximizing the power consumption of each room (Equations ( 2)-( 4)).This approach could be realized due to the fact that when the temperature and the illumination comforts to be increased, the power consumption will increase.The lower user comfort requires lower power consumption.This approach will reduce the number of parameters to be optimized.The objective functions in Equations ( 1)-( 4) only require three variables, i.e., p1, p2, p3 that should be provided in the central control agent.Thus it offers an efficient data exchange between the agents.The constraints are formulated using the inequalities as expressed by Equations ( 5)-( 8).The constraints in Equations ( 5)-( 7) are the lower and upper bounds of the power consumptions which are used to ensure that the optimized parameters p1, p2, p3 fall in the allowable range of the user comfort.While the constraint in Equation ( 8) ensures that the power consumption of the building could be supplied by the generator systems (the renewable energy resources and/or the utility grid).
To solve the above multi-objectives optimization problem, we adopt the Multi-Objective Genetic Algorithm (MOGA), more specifically the NSGA-II as proposed by [50].The MOGA is implemented on the central control agent to find the optimal power required by the building based on the current power consumptions and the generated power as illustrated in Figure 2. As shown in the figure, the inputs of the central control agent are the minimum and maximum power consumptions of the classroom, the office room, and the laboratory room, the power produced by the battery and the PV.Then these values are used by the MOGA to solve the multi-objective optimization as expressed in Equations ( 1)- (8).The outputs of the central control agent are the optimal values of power required by the classroom, the office room, and the laboratory room which are sent to the respective agents.
The power required by the classroom, the office room, and the laboratory room are the optimal values that should be consumed by the respective loads.Then the respective load agent control its loads to satisfy the power requirement using the strategy as described in the following section.

Load Agent
The load agents in the classroom, the office room and the laboratory room are similar, in the sense of the control function.However in our testbed they have the different device protocols, where the load agent in the classroom communicates with the load devices using the Modbus TCP/IP

Load Agent
The load agents in the classroom, the office room and the laboratory room are similar, in the sense of the control function.However in our testbed they have the different device protocols, where the load agent in the classroom communicates with the load devices using the Modbus TCP/IP protocol via the WiFi communication, while the data exchange between the load agents and the devices in the office room and the laboratory room are performed directly in the Wemos module.
Figure 3 illustrates the input and output data of the load agent.As shown in the figure, the inputs are the required power, the outdoor temperature, and the outdoor illumination.These data are used by the fuzzy logic controllers (FLCs) to determine the optimal room temperature and illumination setpoints.There are two FLCs, one for controlling the room temperature setpoint (called as FLC-T), and another one for controlling the room illumination setpoint (called as FLC-I).The inputs of FLC-T are the required power and the outdoor temperature, while the output is the room temperature setpoint.The membership functions of the required power, the outdoor temperature, and the room temperature setpoint are shown in Figure 4, where each variable has three linguistic values, i.e., Low (LOW), Medium (MED), and High (HIGH).The values of the required power (658 W-1137 W), the outdoor temperature ( 26   The fuzzy rules of FLC-T are given in Table 4, where the rules are determined by considering the objectives as follows.It is worthy to note that the AC system discussed here is applicable for the hot season where the AC system is controlled to decrease the outdoor temperature (i.e., the cooling    The fuzzy rules of FLC-T are given in Table 4, where the rules are determined by considering the objectives as follows.It is worthy to note that the AC system discussed here is applicable for the hot season where the AC system is controlled to decrease the outdoor temperature (i.e., the cooling system) to the desired comfortable room temperature.Therefore the consumed power of the AC system will increase when the room temperature setpoint is decreased and vice versa.The fuzzy rules of FLC-T are given in Table 4, where the rules are determined by considering the objectives as follows.It is worthy to note that the AC system discussed here is applicable for the hot season where the AC system is controlled to decrease the outdoor temperature (i.e., the cooling system) to the desired comfortable room temperature.Therefore the consumed power of the AC system will increase when the room temperature setpoint is decreased and vice versa.

FLC
-When the required power is low (LOW), then it is better to set the room temperature setpoint follows to the level of the outdoor temperature to minimize the consumed power of the AC.
Thus the fuzzy rules given in Table 4 show that when the required power is LOW, the room temperature setpoint is set to LOW when the outdoor temperature is LOW, it is set to MED when the outdoor temperature is MED, and it is set to HIGH when the outdoor temperature is HIGH.-When the required power is high (HIGH), it allows the AC to consume high power.Thus the room temperature setpoint could be set to LOW for all outdoor temperature conditions.-When the required power is medium (MED), it is better to set the room temperature setpoint to the medium (MED) regardless of the outdoor temperature conditions.The inputs of FLC-I is the required power and the outdoor illumination, while the output is the room illumination setpoint.The membership functions of the required power, the outdoor illumination, and the room illumination setpoint are shown in Figure 5, where each variable has three linguistic values, i.e., Low (LOW), Medium (MED), and High (HIGH).The values of the required power (658 W-1137 W), the outdoor illumination (1000 lx-10,000 lx), and the room illumination setpoint (300 lx-500 lx) are normalized to 0-1.
The fuzzy rules of FLC-I are given in Table 5, where the rules are determined by considering the objectives as follows.It is noted that the property of the comfort value of the illumination is the opposite from the one of the temperature, in the sense that the temperature comfort increases when the room temperature setpoint is decreased, while the illumination comfort increases when the room illumination setpoint is increased.Therefore the fuzzy rules of the FLC-I are defined below: -When the required power is low (LOW), then it is better to set the room illumination setpoint follows to the level of the outdoor illumination to minimize the consumed power of the lighting.
Thus the fuzzy rules given in Table 5 show that when the required power is LOW, the room illumination setpoint is set to LOW when the outdoor illumination is LOW, it is set to MED when the outdoor illumination is MED, and it is set to HIGH when the outdoor illumination is HIGH.-When the required power is high (HIGH), it allows the lighting to consume high power.It means that the room illumination setpoint could be set to the HIGH for all outdoor temperature conditions.-When the required power is medium (MED), it is better to set the room illumination setpoint to the medium (MED) regardless of the outdoor illumination condition.

Required Power
The inputs of FLC-I is the required power and the outdoor illumination, while the output is the room illumination setpoint.The membership functions of the required power, the outdoor illumination, and the room illumination setpoint are shown in Figure 5, where each variable has three linguistic values, i.e., Low (LOW), Medium (MED), and High (HIGH).The values of the required power (658 W-1137 W), the outdoor illumination (1000 lx-10,000 lx), and the room illumination setpoint (300 lx-500 lx) are normalized to 0-1.The fuzzy rules of FLC-I are given in Table 5, where the rules are determined by considering the objectives as follows.It is noted that the property of the comfort value of the illumination is the opposite from the one of the temperature, in the sense that the temperature comfort increases when the room temperature setpoint is decreased, while the illumination comfort increases when the room

Generator Agent
The generator agent is used to manage the battery charging/discharging according to the state of charge (SOC) of the battery as illustrated in Figure 6.Besides controlling the battery, the generator agent receives the generated power from the PV-battery system and sends the data to the central control agent as shown in Figure 1.The battery charging/discharging is controlled using the simple strategy as expressed by Equations ( 9)- (11).Using these rules, the battery could be effectively operated to supply the load (discharging) and/or saving the PV power based-on the SOC of the battery.Equation ( 9) is used to prevent the over-discharge, while Equation ( 11) is used to prevent the over-charge.Equation ( 10

AC Simulator
The model of an air conditioning (AC) system is a modified version of the model in [51].Since the model in [51] is the heater system, we modify it to become the cooling system to fulfill with our proposed system.The important contribution of our work is that the model is simulated in the embedded system (Wemos module) for real-time implementation, especially for the electronic/communication aspects.The AC simulator consists of two models: the AC (cooling system) and the thermodynamic model of a room.The AC system is expressed by Equation (12), while the thermodynamic model of a room is expressed by Equation (13).The electrical power consumed by the room is simplified by a linear function of the difference between the outdoor temperature and the room temperature as expressed by Equation ( 14): The block diagram of AC simulator is illustrated in Figure 7, where it has two inputs, i.e., the outdoor temperature which is predefined data stored in the Wemos module, and the room temperature setpoint which is received from the load agent (see Figure 1).The AC simulator sends the power consumption, the room temperature and the outdoor temperature to the load agent.

AC Simulator
The model of an air conditioning (AC) system is a modified version of the model in [51].Since the model in [51] is the heater system, we modify it to become the cooling system to fulfill with our proposed system.The important contribution of our work is that the model is simulated in the embedded system (Wemos module) for real-time implementation, especially for the electronic/communication aspects.The AC simulator consists of two models: the AC (cooling system) and the thermodynamic model of a room.The AC system is expressed by Equation (12), while the thermodynamic model of a room is expressed by Equation (13).The electrical power consumed by the room is simplified by a linear function of the difference between the outdoor temperature and the room temperature as expressed by Equation ( 14): The block diagram of AC simulator is illustrated in Figure 7, where it has two inputs, i.e., the outdoor temperature which is predefined data stored in the Wemos module, and the room temperature setpoint which is received from the load agent (see Figure 1).The AC simulator sends the power consumption, the room temperature and the outdoor temperature to the load agent.

AC Simulator
The model of an air conditioning (AC) system is a modified version of the model in [51].Since the model in [51] is the heater system, we modify it to become the cooling system to fulfill with our proposed system.The important contribution of our work is that the model is simulated in the embedded system (Wemos module) for real-time implementation, especially for the electronic/communication aspects.The AC simulator consists of two models: the AC (cooling system) and the thermodynamic model of a room.The AC system is expressed by Equation ( 12), while the thermodynamic model of a room is expressed by Equation (13).The electrical power consumed by the room is simplified by a linear function of the difference between the outdoor temperature and the room temperature as expressed by Equation ( 14): The block diagram of AC simulator is illustrated in Figure 7, where it has two inputs, i.e., the outdoor temperature which is predefined data stored in the Wemos module, and the room temperature setpoint which is received from the load agent (see Figure 1).The AC simulator sends the power consumption, the room temperature and the outdoor temperature to the load agent.To provide real-time implementation, we adopt the Modbus TCP/IP protocol for interfacing between the AC simulator and the load agent, where the load agent acts as the master device and the AC simulator is the slave device.The Modbus data such as the register address and the command type are listed in Table 6.To show that the adopted devices are available commercially, the name of the manufacturer is given in the table.As shown in the table, the Modbus data for the AC power To provide real-time implementation, we adopt the Modbus TCP/IP protocol for interfacing between the AC simulator and the load agent, where the load agent acts as the master device and the AC simulator is the slave device.The Modbus data such as the register address and the command type are listed in Table 6.To show that the adopted devices are available commercially, the name of the manufacturer is given in the table.As shown in the table, the Modbus data for the AC power consumption is provided by the power meter [52], while Modbus data for the room temperature, the temperature setpoint and the outdoor temperature are provided by the Modbus thermostat device [53].

Lighting Simulator
The power consumption of the lighting in the room is calculated by dividing the luminous flux to the luminous efficacy as given in Equation ( 15): In the experiment, the LED lamp is used, where the luminous efficacy is 100 lm/W, while the daylight factor (DF) of the room is 2%, which means that the room illumination is 2% of the outdoor illumination.
The block diagram of lighting simulator is illustrated in Figure 8.It has two inputs: the outdoor illumination which is a predefined data stored in the Wemos module, and the room illumination setpoint which is received from the load agent.The lighting simulator sends the data of the power consumption, the room and the outdoor illumination to the load agent.

Lighting Simulator
The power consumption of the lighting in the room is calculated by dividing the luminous flux to the luminous efficacy as given in Equation ( 15): In the experiment, the LED lamp is used, where the luminous efficacy is 100 lm/W, while the daylight factor (DF) of the room is 2%, which means that the room illumination is 2% of the outdoor illumination.
The block diagram of lighting simulator is illustrated in Figure 8.It has two inputs: the outdoor illumination which is a predefined data stored in the Wemos module, and the room illumination setpoint which is received from the load agent.The lighting simulator sends the data of the power consumption, the room illumination and the outdoor illumination to the load agent.The Modbus data of the simulator is given in Table 7. Similar to the AC simulator, the Modbus data for the lighting power consumption is provided by the power meter [52].The Modbus data for the room illumination is provided by the daylight sensor [54].The LED dimmer [55] provides the Modbus data for the room illumination setpoint.The outdoor light sensor [56] provides the Modbus data for outdoor illumination.The Modbus data of the simulator is given in Table 7. Similar to the AC simulator, the Modbus data for the lighting power consumption is provided by the power meter [52].The Modbus data for the room illumination is provided by the daylight sensor [54].The LED dimmer [55] provides the Modbus data for the room illumination setpoint.The outdoor light sensor [56] provides the Modbus data for outdoor illumination.

Electrical Load Simulator
The block diagram of electrical load simulator is in Figure 9.The electrical load is modeled with the load profile stored in the Wemos module.The simulator sends the data of power consumption to the load agent using the Modbus data as given in Table 8, where it only contains the power consumption data provided by the power meter [52].

Electrical Load Simulator
The block diagram of electrical load simulator is illustrated in Figure 9.The electrical load is modeled with the load profile stored in the Wemos module.The simulator sends the data of power consumption to the load agent using the Modbus data as given in Table 8, where it only contains the power consumption data provided by the power meter [52].

PV-Battery Simulator
The relationship between current and voltage (I-V) of the PV is expressed by Equations ( 16)-( 18) [57], where NS = 4, NP = 65 and VPV = 48 V.The battery is modeled by its SOC as expressed by Equation ( 19) [58]: ) )) 432 /( 1 ( SOC( ) SOC( 1) The block diagram of the PV-battery simulator is illustrated in Figure 10.The PV-battery simulator receives the battery charging/discharging control signal from the generator agent.The predefined data of the solar irradiation is stored in the Wemos module which used to produce the

PV-Battery Simulator
The relationship between current and voltage (I-V) of the PV is expressed by Equations ( 16)-( 18) [57], where N S = 4, N P = 65 and V PV = 48 V.The battery is modeled by its SOC as expressed by Equation ( 19) [58]: i d = N P e −9 (e ((v PV /(36N S )+0.05i out /N P )/26e −3 )−1) ) ( 17) Energies 2019, 12, 3655 16 of 29 The block diagram of the PV-battery simulator is illustrated in Figure 10.The PV-battery simulator receives the battery charging/discharging control signal from the generator agent.The predefined data of the solar irradiation is stored in the Wemos module which used to produce the PV power as defined by Equations ( 16)- (18).Then the PV power, the battery power, and the battery SOC are sent to the generator agent using the Modbus data as given in Table 9.The Modbus data of the PV power is provided by the Gridtie inverter device [59].The battery power, the battery SOC and the battery charging/discharging control are provided by the battery charger controller [60].

Communication Protocol
As described in the previous section, the MQTT protocol is adopted as the communication protocol between the central control agent and the other agents (the load agents and the generator agent).MQTT is lightweight messaging protocol that runs on the Transmission Control Protocol/Internet Protocol (TCP/IP).It works based on the publish-subscribe mechanism, where the MQTT broker is required to establish a connection between the publisher and the subscriber.
The configuration of MQTT protocol is illustrated in Figure 11.In the system, the MQTT broker and the central control agent are installed on same Raspberry Pi module.Thus the central control agent communicates with the broker via a localhost connection.As shown in the figure, each agent publishes and subscribes the specific topics as described in the following.
In Figure 11, an arrow with "Publish-C2CC" means that the load agent in the classroom publishes the "C2CC" topics, while an arrow with "Subscribe-CC2C" means the load agent subscribes the "CC2C" topics.The list of the topics is given in Table 10.As shown in the table, all topics that are published by the load agents and the generator agent are subscribed by the central control agent, thus all data sent by the load agents and the generator agent will be received by the central control agent.Meanwhile, the topics that are subscribed by load agents and the generator agent are published by the central control agent, thus the data that is required by the load agents and the generator agent will be provided by the central control agent.

Communication Protocol
As described in the previous section, the MQTT protocol is adopted as the communication protocol between the central control agent and the other agents (the load agents and the generator agent).MQTT is lightweight messaging protocol that runs on the Transmission Control Protocol/Internet Protocol (TCP/IP).It works based on the publish-subscribe mechanism, where the MQTT broker is required to establish a connection between the publisher and the subscriber.
The configuration of MQTT protocol is illustrated in Figure 11.In the system, the MQTT broker and the central control agent are installed on same Raspberry Pi module.Thus the central control agent communicates with the broker via a localhost connection.As shown in the figure, each agent publishes and subscribes the specific topics as described in the following.
In Figure 11, an arrow with "Publish-C2CC" means that the load agent in the classroom publishes the "C2CC" topics, while an arrow with "Subscribe-CC2C" means the load agent subscribes the "CC2C" topics.The list of the topics is given in Table 10.As shown in the table, all topics that are published by the load agents and the generator agent are subscribed by the central control agent, thus all data sent by the load agents and the generator agent will be received by the central control agent.Meanwhile, the topics that are subscribed by load agents and the generator agent are published by the central illumination setpoint, except at the time during the previous periods.Further, the power consumption shows the proper behavior, i.e., it increases when the difference between the illumination setpoint and the natural illumination is increased.temperature, and the power consumption during the simulation into the Wemos memory.The recorded data is illustrated in Figure 12.The time sampling of the simulator is one second, and the hourly data is simulated in one-minute interval.It is noted here that from 0 to 59 seconds and from 300 to 359 seconds, the classroom is not occupied and the AC is switched off.Therefore during these time intervals, the power consumptions are zero and the room temperature is the same as the outdoor temperature.As shown in the figure, the AC simulator works properly, in the sense that the room temperature follows the temperature setpoint, and the power consumption changes proportionally to the difference between the outdoor temperature and the temperature setpoint.The power consumption increases when the difference between the outdoor temperature and the temperature is increased.The profile of illumination and power consumption of the lighting simulator is illustrated in Figure 13.Similarly to the AC simulator, the lighting system is switched-off during 0 to 59 seconds and 300 to 359 seconds.In the figure, the natural illumination is the room illumination which is caused by the outdoor lighting (sunshine).As shown in the figure, the room illumination is able to follow the illumination setpoint, except at the time during the previous periods.Further, the power consumption shows the proper behavior, i.e., it increases when the difference between the illumination setpoint and the natural illumination is increased.To assess the sensitivity of the parameters of our proposed FLC, we conduct the sensitivity analysis as described in the following.Two sensitivity analysis methods, i.e., the elementary effect (EE) method [61], and the Fourier Amplitude Sensitivity Testing (FAST) method [62] are employed.The EE method is used to find the influential parameters of the model, while the FAST method is used to find the sensitivity indices of the parameters.The EE and FAST methods are calculated using the SAFE, a Matlab Toolbox for global sensitivity analysis provided by [63].
The mean and standard deviation of EEs of the FLC inputs of the FLC-T and the FLC-I are illustrated in Figure 14a,b respectively.In Figure 14a, the red dot and the blue dot represent the normalized required power and the normalized outdoor temperature respectively.As shown in the figure, the mean and the standard deviation of the required power are higher than the outdoor temperature.Thus it could be concluded that the required power input is more influential than the outdoor temperature input.This result could be understood from the observation of the fuzzy rules of FLC-T shown in Table 4, where the changes of linguistic values (LOW, MED, HIGH) of the outdoor temperature do not change the output when the linguistic values of required power is MED or HIGH.The changes of the outdoor temperature affect the output, only when the value of required power is LOW.Therefore it is clearly shown that the influential effect of the required power is higher than the outdoor illumination.In Figure 14b, the red dot and the blue dot represent the normalized required power and the normalized outdoor illumination respectively.As shown in the figure, the mean and the To assess the sensitivity of the parameters of our proposed FLC, we conduct the sensitivity analysis as described in the following.Two sensitivity analysis methods, i.e., the elementary effect (EE) method [61], and the Fourier Amplitude Sensitivity Testing (FAST) method [62] are employed.The EE method is used to find the influential parameters of the model, while the FAST method is used to find the sensitivity indices of the parameters.The EE and FAST methods are calculated using the SAFE, a Matlab Toolbox for global sensitivity analysis provided by [63].
The mean and standard deviation of EEs of the FLC inputs of the FLC-T and the FLC-I are illustrated in Figure 14a,b respectively.In Figure 14a, the red dot and the blue dot represent the normalized required power and the normalized outdoor temperature respectively.As shown in the figure, the mean and the standard deviation of the required power are higher than the outdoor temperature.Thus it could be concluded that the required power input is more influential than the outdoor temperature input.This result could be understood from the observation of the fuzzy rules of FLC-T shown in Table 4, where the changes of linguistic values (LOW, MED, HIGH) of the outdoor temperature do not change the output when the linguistic values of required power is MED or HIGH.The changes of the outdoor temperature affect the output, only when the value of required power is LOW.Therefore it is clearly shown that the influential effect of the required power is higher than the outdoor illumination.In Figure 14b, the red dot and the blue dot represent the normalized required power and the normalized outdoor illumination respectively.As shown in the figure, the mean and the standard deviation of the required power are higher than the illumination.Thus the required power input is more influential than the outdoor illumination input.Similar to the FLC-T discussed previously, the result could understood from the examination of fuzzy rules of FLC-I shown in Table 5.
illustrated in Figure 14a,b respectively.In Figure 14a, the red dot and the blue dot represent the normalized required power and the normalized outdoor temperature respectively.As shown in the figure, the mean and the standard deviation of the required power are higher than the outdoor temperature.Thus it could be concluded that the required power input is more influential than the outdoor temperature input.This result could be understood from the observation of the fuzzy rules of FLC-T shown in Table 4, where the changes of linguistic values (LOW, MED, HIGH) of the outdoor temperature do not change the output when the linguistic values of required power is MED or HIGH.The changes of the outdoor temperature affect the output, only when the value of required power is LOW.Therefore it is clearly shown that the influential effect of the required power is higher than the outdoor illumination.In Figure 14b, the red dot and the blue dot represent the normalized required power and the normalized outdoor illumination respectively.As shown in the figure, the mean and the standard deviation of the required power are higher than the illumination.Thus the required power input is more influential than the outdoor illumination input.Similar to the FLC-T discussed previously, the result could understood from the examination of fuzzy rules of FLC-I shown in Table 5.The sensitivity indices calculated using the FAST method are shown in Figure 15, where Figure 15a shows the sensitivity indices of the FLC-T inputs, i.e., the normalized required power and the normalized outdoor temperature, while Figure 15b shows the sensitivity indices of the FLC-I inputs, i.e., the normalized required power and the normalized outdoor illumination.The sensitivity indices calculated using the FAST method are shown in Figure 15, where Figure 15a shows the sensitivity indices of the FLC-T inputs, i.e., the normalized required power and the normalized outdoor temperature, while Figure 15b shows the sensitivity indices of the FLC-I inputs, i.e., the normalized required power and the normalized outdoor illumination.Both figures show that the sensitivity index of the required power input is higher than the outdoor temperature input and the outdoor illumination input.These results conform to the previous EE analysis.The sensitivity analysis results show that it is reasonable to select the required power, the outdoor temperature, and the outdoor illumination as the inputs of the proposed FLCs, even though the last two inputs have a less influential effect compared to the required power input.

Performance of Real-Time Implementation
Since the objective of the proposed testbed is for testing the real-time implementation of the building energy management system, we conduct several experiments to verify our method in the term of the real-time implementation such as the execution time of the algorithm, the sampling time of the agents, and the efficiency of the optimization technique.
The execution times of FLCs which are implemented on the Wemos modules are given in Table 11.As shown in the table, the execution time of FLC is about 10 to 12 ms.Thus to execute both FLC-T Both figures show that the sensitivity index of the required power input is higher than the outdoor temperature input and the outdoor illumination input.These results conform to the previous EE analysis.The sensitivity analysis results show that it is reasonable to select the required power, the outdoor temperature, and the outdoor illumination as the inputs of the proposed FLCs, even though the last two inputs have a less influential effect compared to the required power input.

Performance of Real-Time Implementation
Since the objective of the proposed testbed is for testing the real-time implementation of the building energy management system, we conduct several experiments to verify our method in the term of the real-time implementation such as the execution time of the algorithm, the sampling time of the agents, and the efficiency of the optimization technique.
The execution times of FLCs which are implemented on the Wemos modules are given in Table 11.As shown in the table, the execution time of FLC is about 10 to 12 ms.Thus to execute both FLC-T and FLC-I on a Wemos module, it requires about 22 ms.The results verify that the proposed embedded agent using Wemos is suitable for a real-time implementation of the FLC algorithm.Since the sampling time of an agent is determined by the execution time of the algorithm and the transmission time of the communication protocol employed, we examine the sampling time of each agent as given in Table 11.Since the data communication between the load agents in the office room and the laboratory room with the simulators are performed directly, the sampling times of these load agents are quite fast, i.e., about 1.25 ms.Meanwhile, the sampling times of the agents with the Modbus protocol, i.e., the load agent in the classroom and the generator agent are 6.59 s and 2.63 s respectively.These results indicate that the sampling time is very affected by the transmission time of the Modbus protocol.Further, since the number of the Modbus slave devices in the classroom is higher than the generator agent, the sampling time is longer due to the fact that the master must poll the slaves.
The sampling times of the load agent in the classroom and the load agent in the office room are illustrated in Figures 16 and 17, respectively.In the figures, the profiles of room temperature setpoints against time are shown, where the updated data are indicated with the marks on the graphs.Figure 16 shows that the room temperature setpoints in the classroom are updated in an average time of 6 s, while Figure 17 shows that the room temperature setpoints in the office room are updated in an average time of 1 s.The main contribution of our proposed system in the real-time implementation of the optimization technique using GA is shown in Table 11, where the execution time of GA on the Raspberry Pi module is 14.25 s (the number of population is 100 and the number of iteration is 30).While the sampling time of the central control agent is 16.60 s.The result implies that the communication task performed by the MQTT protocol only contributes a small portion of the time.Most of the time is consumed by the GA.It also suggests that the lightweight protocols such as the MQTT and the LWM2M protocols are the effective communication protocols between the agents in the MAS.Relying on the sampling time of the central control agent which is lower than one minute, we may conclude that our proposed testbed is suitable for implementing the BEMS, where the updating process is done in hourly basis even every minute.
The main contribution of our proposed system in the real-time implementation of the optimization technique using GA is shown in Table 11, where the execution time of GA on the Raspberry Pi module is 14.25 s (the number of population is 100 and the number of iteration is 30).While the sampling time of the central control agent is 16.60 s.The result implies that the communication task performed by the MQTT protocol only contributes a small portion of the time.Most of the time is consumed by the GA.It also suggests that the lightweight protocols such as the MQTT and the LWM2M protocols are the effective communication protocols between the agents in the MAS.Relying on the sampling time of the central control agent which is lower than one minute, we may conclude that our proposed testbed is suitable for implementing the BEMS, where the updating process is done in hourly basis even every minute.The main contribution of our proposed system in the real-time implementation of the optimization technique using GA is shown in Table 11, where the execution time of GA on the Raspberry Pi module is 14.25 s (the number of population is 100 and the number of iteration is 30).While the sampling time of the central control agent is 16.60 s.The result implies that the communication task performed by the MQTT protocol only contributes a small portion of the time.Most of the time is consumed by the GA.It also suggests that the lightweight protocols such as the MQTT and the LWM2M protocols are the effective communication protocols between the agents in the MAS.Relying on the sampling time of the central control agent which is lower than one minute, we may conclude that our proposed testbed is suitable for implementing the BEMS, where the updating process is done in hourly basis even every minute.

Effectiveness of Optimization Technique
To verify the effectiveness of the proposed optimization technique, we evaluate the comfort index and the energy extracted from the grid.The objective is to maximize the comfort index while minimizing the energy extracted from the grid.The temperature comfort index (CIT) and the illumination comfort index (CII) are defined based on [64]  where Temp opt , Temp min , Temp max is the optimized room temperature, the allowed minimum and maximum room temperatures respectively, Illum opt , Illum min , Illum max is the optimized room illumination, the allowed minimum and maximum room illuminations respectively.From Equations ( 20) and ( 21), the maximum comfort is achieved when the value of CIT or CII is 1, and the minimum comfort is achieved when the value is 0.
In the experiments, we compare our proposed method that adjusts the temperature and the illumination setpoints to the existing method proposed by [2] (called as EXT), the fixed setpoint methods, i.e., the setpoint is set to the minimum comfort (called as Min-comfort), the setpoint is set to the middle comfort (called as Mid-comfort), and the setpoint is set to the maximum comfort (called as Max-comfort).The EXT [2] employs the FLC to adjust the temperature.The difference with our approach is described briefly in the following.Instead of using the required power and the outdoor temperature as the fuzzy inputs, the EXT uses the electricity price and the outdoor temperature.In this case, the electricity price has two linguistic values (PEAK, MD), whose membership functions are shown in Figure 18.As shown in the figure, the electricity price is expressed in respect to the time of use, which is adopted from [2].While the membership function of the outdoor temperature and the temperature setpoint are the same with our proposed method.The fuzzy rules are given in Table 12.
illumination, the allowed minimum and maximum room illuminations respectively.From Equations ( 20) and ( 21), the maximum comfort is achieved when the value of CIT or CII is 1, and the minimum comfort is achieved when the value is 0.
In the experiments, we compare our proposed method that adjusts the temperature and the illumination setpoints to the existing method proposed by [2] (called as EXT), the fixed setpoint methods, i.e., the setpoint is set to the minimum comfort (called as Min-comfort), the setpoint is set to the middle comfort (called as Mid-comfort), and the setpoint is set to the maximum comfort (called as Max-comfort).The EXT [2] employs the FLC to adjust the temperature.The difference with our approach is described briefly in the following.Instead of using the required power and the outdoor temperature as the fuzzy inputs, the EXT uses the electricity price and the outdoor temperature.In this case, the electricity price has two linguistic values (PEAK, MD), whose membership functions are shown in Figure 18.As shown in the figure, the electricity price is expressed in respect to the time of use, which is adopted from [2].While the membership function of the outdoor temperature and the temperature setpoint are the same with our proposed method.The fuzzy rules are given in Table 12.The room temperature setpoints for Min-comfort, Mid-comfort, and Max-comfort are set to 25 °C, 22.5 °C, and 20 °C respectively.The room illumination setpoints for Min-comfort, Mid-comfort, and Max-comfort are set to 300, 400 and 500 lx, respectively.The data of solar irradiation, the outdoor  The room temperature setpoints for Min-comfort, Mid-comfort, and Max-comfort are set to 25 • C, 22.5 • C, and 20 • C respectively.The room illumination setpoints for Min-comfort, Mid-comfort, and Max-comfort are set to 300, 400 and 500 lx, respectively.The data of solar irradiation, the outdoor temperature, the outdoor illumination, and the electrical load from 7 h to 17 h given in Table 13 are used during comparisons.(FLC-T and FLC-I) have similar membership functions and the fuzzy rules.
Figure 21 shows that the energy extracted from the grid of Min-comfort is always the lowest one, however since its comfort indices as shown in Figures 19 and 20 are also the lowest ones, we could not adopt this method.The same results are also achieved by the EXT, where as shown in the Figure 21, the energy extracted from the grid is lower than our proposed method, however the comfort index is also lower.index of or proposed method.This result could be understood from the fact that both FLC controller (FLC-T and FLC-I) have similar membership functions and the fuzzy rules.
Figure 21 shows that the energy extracted from the grid of Min-comfort is always the lowest one, however since its comfort indices as shown in Figures 19 and 20 are also the lowest ones, we could not adopt this method.The same results are also achieved by the EXT, where as shown in the Figure 21, the energy extracted from the grid is lower than our proposed method, however the comfort index is also lower.It is worth noting that compared to Max-comfort and Mid-comfort, the energy profile extracted from the grid of our proposed method is lower than both methods.Therefore the effectiveness of our proposed in optimizing the comfort index and energy extracted from the grid is verified.Figure 21 shows that the energy extracted from the grid of Min-comfort is always the lowest one, however since its comfort indices as shown in Figures 19 and 20 are also the lowest ones, we could not adopt this method.The same results are also achieved by the EXT, where as shown in the Figure 21, the energy extracted from the grid is lower than our proposed method, however the comfort index is also lower.
It is worth noting that compared to Max-comfort and Mid-comfort, the energy profile extracted from the grid of our proposed method is lower than both methods.Therefore the effectiveness of our proposed in optimizing the comfort index and energy extracted from the grid is verified.

Conclusions
An embedded platform for implementing the multi agent system (MAS) in the building energy management is proposed.The proposed MAS consists of the load agent, the generator agent, and the central control agent.The genetic algorithm (GA) is implemented on the central control agent to find the optimal power required by the load agents based on the availability of the PV-battery power and the requirement of the user comforts.The proposed objective functions require a few parameters, thus the data exchange between the agents could be performed efficiently.To provide a flexible implementation in the existing building infrastructure and to integrate with the state of the art IoT technology, our testbed employs the industrial Modbus protocol and the MQTT protocol, which are implemented on the low cost embedded platform.In the experiments, the execution time, the communication protocols and the sampling time of the embedded testbed are evaluated.The experiments results show that our proposed testbed is able to maximize the temperature and illumination comforts while minimizing the energy in a real-time manner.Further, the effectiveness of the optimization technique to optimize the energy cost and the user comfort of the building is verified.
In future, the testbed system will be extended to cope with the complex building energy management by employing the complex models and advanced optimization algorithms.Further, the electrical system will be considered in the tested.

Figure 1 .
Figure 1.Architecture of the proposed system.

Figure 1 .
Figure 1.Architecture of the proposed system.

Figure 2 .
Figure 2. Input and output data of central control agent.
Min. power consumption of laboratory room, Max.power consumption of laboratory room Central Control Agent (MOGA) Power required by laboratory room Power required by classroom Power required by office room Power supplied by Grid Min.power consumption of classroom, Max.power consumption of classroom Power produced by PV Power produced by Battery Min.power consumption of office room, Max.power consumption of office room

Figure 2 .
Figure 2. Input and output data of central control agent.

Figure 3 .
Figure 3. Input and output data of the load agent.

Figure 3 .
Figure 3. Input and output data of the load agent.

Figure 3 .
Figure 3. Input and output data of the load agent.

Figure 6 .
Figure 6.Input and output data of the generator agent.

Figure 7 .
Figure 7. Block diagram of the AC simulator.

Figure 6 .
Figure 6.Input and output data of the generator agent.

Energies 2019 , 11 )Figure 6 .
Figure 6.Input and output data of the generator agent.

Figure 7 .
Figure 7. Block diagram of the AC simulator.

Figure 7 .
Figure 7. Block diagram of the AC simulator.

Figure 9 .
Figure 9. Block diagram of the electrical load simulator.

Figure 9 .
Figure 9. Block diagram of the electrical load simulator.

Figure 10 .
Figure 10.Block diagram of the PV-battery simulator.

Figure 12 .
Figure 12.Profile of temperatures and power consumption of the AC simulator.

Figure 12 . 29 Figure 13 .
Figure 12.Profile of temperatures and power consumption of the AC simulator.Energies 2019, 12, x FOR PEER REVIEW 19 of 29

Figure 13 .
Figure 13.Profile of illumination and power consumption of the lighting simulator.

Figure 14 .Figure 14 .
Figure 14.Mean and standard deviation of EEs of FLC inputs: (a) Normalized required power and outdoor temperature of FLC-T; (b) Normalized required power and outdoor illumination of FLC-I.

Figure 15 .
Figure 15.Sensitivity index of FLC inputs: (a) Normalized required power and outdoor temperature of FLC-T; (b) Normalized required power and outdoor illumination of FLC-I.

Figure 15 .
Figure 15.Sensitivity index of FLC inputs: (a) Normalized required power and outdoor temperature of FLC-T; (b) Normalized required power and outdoor illumination of FLC-I.

Figure 16 .
Figure 16.Sampling time of the load agent in the classroom.

Figure 17 .
Figure 17.Sampling time of the load agent in the office room.

Figure 16 .
Figure 16.Sampling time of the load agent in the classroom.

Figure 16 .
Figure 16.Sampling time of the load agent in the classroom.

Figure 17 .
Figure 17.Sampling time of the load agent in the office room.

Figure 17 .
Figure 17.Sampling time of the load agent in the office room.

Figure 18 .
Figure 18.Membership function of electricity price in the EXT.

11 Figure 18 .
Figure 18.Membership function of electricity price in the EXT.

Figure 19 .
Figure 19.Temperature comfort index in the office room.

Figure 20 .Figure 19 .
Figure 20.Illumination comfort index in the office room.

Figure 19 .
Figure 19.Temperature comfort index in the office room.

Figure 21 .
Figure 21.Energy extracted from the grid.

Table 1 .
Typical agents of MAS in BEMS.

Table 2 .
Classification of MAS implementation in BEMS.
* ND = Not defined clearly in the paper.

Table 3 .
Description of variables in the proposed MAS-based BEMS.

Table 4 .
Fuzzy rules of FLC-T.

Table 5 .
Fuzzy rules of FLC-I.

Table 4 .
Fuzzy rules of FLC-T.

Table 5 .
Fuzzy rules of FLC-I.

Table 6 .
Modbus data of the AC simulator.

Table 6 .
Modbus data of the AC simulator.

Table 7 .
Modbus data of lighting simulator.

Table 7 .
Modbus data of lighting simulator.

Table 8 .
Modbus data of the electrical load simulator.

Table 8 .
Modbus data of the electrical load simulator.

Table 9 .
Modbus data of the PV-battery simulator.

Table 9 .
Modbus data of the PV-battery simulator.

Table 11 .
Execution time and sampling time.

Table 12 .
Fuzzy rules of EXT.

Table 12 .
Fuzzy rules of EXT.

Table 13 .
Data inputs used in the experiments.