IoT-enabled Microgrid for Intelligent Energy-aware Buildings: A Novel Hierarchical Self-consumption Scheme with Renewables

: This paper presents a novel hierarchical Internet of Things (IoT)-based scheme for Microgrid-Enabled Intelligent Buildings to achieve energy digitalization and automation with a renewable energy self-consumption strategy. Firstly, a hierarchical structure of Microgrid-Enabled Intelligent Buildings is designed to establish a two-dimensional fusion layered architecture for the microgrid to interact with the composite loads of buildings. The building blocks and functions of each layer are deﬁned speciﬁcally. Secondly, to achieve transparent information fusion and interactive cooperation between the supply-side and demand-side, a state transition mechanism driven by a combination of time and events is proposed to activate the real-time and mutual response of generation and loads dynamically. Thirdly, based on the above hierarchical fusion structure and data-driven state transition mechanism, a power balance control algorithm driven by a self-consumption strategy is further proposed to achieve the autonomous balance of supply and demand. Finally, the IoT Microgrid Laboratory at Aalborg University is introduced to show how to implement this novel hierarchical IoT-based scheme in a Microgrid-Enabled Intelligent Building, and the power consensus control method based on the state transition mechanism is veriﬁed to achieve a renewable energy self-consumption strategy.


Introduction
The use of electricity is an integral need in human society to meet the rising living quality in different countries. With growing concerns for environmental issues and fossil energy depletion around the world, increasing attention is being paid to technologies for renewable energy utilization and energy efficiency improvement. In recent decades, many renewable energy technologies have achieved great development, especially solar energy and wind energy. How to provide these renewable energies with high quality to users or the grid becomes a very important issue.
Microgrid is one of the key technologies for solving energy and environmental problems, to increase the penetration of renewable energy and to provide high quality electrical energy, which will play an important role in the edge layer of the Energy Internet [1][2][3][4]. The development of microgrid technology is of great significance to adjust the energy structure, protect the environment, solve the problem of energy consumption in rural areas and remote areas, and the transition from the traditional power grid to a smart grid and even to the Energy Internet.
Microgrid is a controllable small power generation system that consists of a combination of different renewable distributed generations (DGs), storage, controllers and loads with efficient architecture and management strategies. Microgrid is gaining importance in smart societies, giving consideration to cost reductions, self-sustenance, grid resilience, climate change, carbon emissions, etc. [5][6][7][8][9]. Microgrid has two operation modes: grid-tie mode and islanded mode. In grid-tie mode, microgrid is connected to the main power grid at the point of common coupling (PCC), so the loads are supplied by both DGs and the main power grid. In islanded mode, the power and energy balance are maintained by microgrid itself.
In terms of energy consumption, a large proportion of total energy is consumed by commercial and residential buildings, most of which is electricity. According to the U.S. Department of Energy, about 40% of total energy is consumed in buildings in industrialized countries, among which 66% is electricity [10,11]. Figure 1 shows the energy consumption structure of the U.S. Another example is China, as the largest country in the world by population, with the rapid development of the economy, the scale of China's construction industry ranks first in the world. In China, 27.6% of the total energy is used by the building sector currently and the percentage is estimated to reach 35% by 2025. However, coal still accounts for more than 60% of the total energy consumption in the current Chinese energy structure [12][13][14], which puts great pressure on the environment, and creates a difficult task in controlling the emission of CO2, polysulfide, nitrogen oxide, etc.
Therefore, increasing renewable energy supply in buildings can be a remarkable opportunity to reduce the traditional fossil energy consumption and greenhouse gas emissions. A number of countries have taken specific initiatives to encourage higher penetration of renewables and low energy consumption in their building sectors, which is of great significance to the realization of energy saving and emission reduction, and to the optimization of social energy structure.
As an effective way to handle the uncertainties of renewable energies, microgrids provide an economical and reliable energy supply for buildings. Intelligent building is the result of a combination of building technology and control technology, communication technology and computer technology [15,16]. By constructing an integrated intelligent platform covering the whole building, intelligent building realizes the automation and intelligence of subsystems such as equipment, communication, office, air conditioning, security and monitoring. It needs a large number of components to run and produces a great deal of energy consumption, mainly the consumption of electric energy. In this situation, the type of building will change from intelligent building to green intelligent building, which is also called low energy building [17,18]. Another example is China, as the largest country in the world by population, with the rapid development of the economy, the scale of China's construction industry ranks first in the world. In China, 27.6% of the total energy is used by the building sector currently and the percentage is estimated to reach 35% by 2025. However, coal still accounts for more than 60% of the total energy consumption in the current Chinese energy structure [12][13][14], which puts great pressure on the environment, and creates a difficult task in controlling the emission of CO2, polysulfide, nitrogen oxide, etc.
Therefore, increasing renewable energy supply in buildings can be a remarkable opportunity to reduce the traditional fossil energy consumption and greenhouse gas emissions. A number of countries have taken specific initiatives to encourage higher penetration of renewables and low energy consumption in their building sectors, which is of great significance to the realization of energy saving and emission reduction, and to the optimization of social energy structure.
As an effective way to handle the uncertainties of renewable energies, microgrids provide an economical and reliable energy supply for buildings. Intelligent building is the result of a combination of building technology and control technology, communication technology and computer technology [15,16]. By constructing an integrated intelligent platform covering the whole building, intelligent building realizes the automation and intelligence of subsystems such as equipment, communication, office, air conditioning, security and monitoring. It needs a large number of components to run and produces a great deal of energy consumption, mainly the consumption of electric energy. In this situation, the type of building will change from intelligent building to green intelligent building, which is also called low energy building [17,18].
With the combination of microgrid technology and intelligent building, the development of green intelligent building has decided advantages. (1) From a green building point of view, the distributed energy generation system can be connected to the building power supply and distribution system through microgrid technology, and the use of renewable and clean energy can be realized by using photovoltaic, wind, natural gas, energy storage systems, etc. It has great economic and environmental benefits. (2) From an intelligent building perspective, the microgrid control system can be integrated with the existing Building Automation System (BAS), so as to provide a basis for achieving a power generation-consumption balance, intelligent energy management and cooperative optimization scheduling of the whole Microgrid-Enabled Intelligent Building system. (3) From a microgrid point of view, the microgrid based on distributed power generation (DG) systems is normally a low-voltage network, while the building electrical system operates at voltages below 10 kV. Therefore, the power demand of the building can be well satisfied by the nearby microgrid. The cost of power transmission and conversion is reduced or even eliminated. The structure of the Microgrid-Enabled Intelligent Building is shown in Figure 2.
Electronics 2020, 9, x FOR PEER REVIEW 3 of 18 With the combination of microgrid technology and intelligent building, the development of green intelligent building has decided advantages. (1) From a green building point of view, the distributed energy generation system can be connected to the building power supply and distribution system through microgrid technology, and the use of renewable and clean energy can be realized by using photovoltaic, wind, natural gas, energy storage systems, etc. It has great economic and environmental benefits. (2) From an intelligent building perspective, the microgrid control system can be integrated with the existing Building Automation System (BAS), so as to provide a basis for achieving a power generation-consumption balance, intelligent energy management and cooperative optimization scheduling of the whole Microgrid-Enabled Intelligent Building system. (3) From a microgrid point of view, the microgrid based on distributed power generation (DG) systems is normally a low-voltage network, while the building electrical system operates at voltages below 10 kV. Therefore, the power demand of the building can be well satisfied by the nearby microgrid. The cost of power transmission and conversion is reduced or even eliminated. The structure of the Microgrid-Enabled Intelligent Building is shown in Figure 2.

Two-dimensional Fusion Model for Microgrid with Composite Loads
Wind and solar energy sources can be exploited in many cases for electricity production in buildings or in the close vicinity of the buildings. These energy sources are clean and almost universally available. Another particularly attractive aspect is that these sources of energy are cost-free and independent from fluctuations in energy market prices that may increase the cost of building energy. These renewable energy sources are diversified for the supply of building energy systems. It is of great significance to improve the energy utilization efficiency of buildings by realizing reliable access to renewable energy sources on the premise of ensuring the balance between supply and demand [19].
Generally, energy in buildings is consumed by space heating or cooling, water heating, lighting and feeding of domestic electric appliances, where electric vehicles can be included. The power consumption of traditional buildings is mainly supplied by the utility grid, but taking climate change and the maturity of renewable energy technologies into consideration, building integrated photovoltaic (BIPV), wind power generation and power storage systems are widely used in building systems that can be named Microgrid-Enabled Intelligent Buildings (MGIBs).
The MGIB includes DGs, energy storage systems (ESS), and typical loads in buildings such as heating, ventilating and air conditioning systems (HVAC) and lighting systems, etc. [6,20,21]. Although the requirements of HVAC and lighting are time-varying, the energy profile of these systems can be measured by BAS in real-time.
The goal of the MGIB system is to maximize the utilization of renewable energy and to provide high quality power for intelligent buildings. The MGIB control strategy is a 'self-consumption

Two-dimensional Fusion Model for Microgrid with Composite Loads
Wind and solar energy sources can be exploited in many cases for electricity production in buildings or in the close vicinity of the buildings. These energy sources are clean and almost universally available. Another particularly attractive aspect is that these sources of energy are cost-free and independent from fluctuations in energy market prices that may increase the cost of building energy. These renewable energy sources are diversified for the supply of building energy systems. It is of great significance to improve the energy utilization efficiency of buildings by realizing reliable access to renewable energy sources on the premise of ensuring the balance between supply and demand [19].
Generally, energy in buildings is consumed by space heating or cooling, water heating, lighting and feeding of domestic electric appliances, where electric vehicles can be included. The power consumption of traditional buildings is mainly supplied by the utility grid, but taking climate change and the maturity of renewable energy technologies into consideration, building integrated photovoltaic (BIPV), wind power generation and power storage systems are widely used in building systems that can be named Microgrid-Enabled Intelligent Buildings (MGIBs).
The MGIB includes DGs, energy storage systems (ESS), and typical loads in buildings such as heating, ventilating and air conditioning systems (HVAC) and lighting systems, etc. [6,20,21]. Although the requirements of HVAC and lighting are time-varying, the energy profile of these systems can be measured by BAS in real-time.
The goal of the MGIB system is to maximize the utilization of renewable energy and to provide high quality power for intelligent buildings. The MGIB control strategy is a 'self-consumption priority Electronics 2020, 9, 550 4 of 18 model', which means when self-production by DGs is sufficient, total load demand is supplied by DGs, otherwise, self-storage is used as a priority instead of importing from the grid.
On the load side of the system, BAS is able to monitor the operation and energy consumption of individual load. The load demand for total power is time-varying during the day. At a moment, the total power demand of load side P load (t) can be calculated by BAS and will be notified to the supply side quickly. The power demand will be assigned to DGs, storage systems and distribution networks according to the capabilities of these power sources at that moment and renewable energy will be utilized as much as possible.
In this paper, the microgrid is assumed to operate in grid-connected mode. The load profile is time-varying 24 hours a day. When the power generation and energy storage within the microgrid cannot follow the peak of the load profile, extra power will be exchanged from the distribution networks to MGIB via PCC. The load demands need to be met from the microgrid's own generation, energy storage and the utility grid moment-to-moment in order to avoid voltage drop and unreliable power supply.
The MGIB control strategy aims to ensure the stability of voltage and frequency, the real-time power balance between the load-side and the supply-side, and the maximum utilization of renewable energy. Meanwhile, in order to realize the energy balance in MGIB, the consumption power should be distributed between the DGs, energy storage system and distribution network on the premise that the energy target is satisfied. To achieve these goals, three pieces of information are needed-the real-time power requirements of the load side, real-time power capability of the DGs and ESS, and the power exchanged with the utility network. Therefore, a hierarchical control framework based on efficient information fusion between the load side and DG side is the key to implementing an overall control strategy.
The framework of two-dimensional fusion for an MGIB with composite loads is shown in Figure 3. In the framework, both the load side and the DG side have four logical layers: the physical layer, information layer, control layer and dispatch layer. Each upper layer is served by each lower layer. For example, the control layer needs to aggregate information from the information layer to make control decisions based on control algorithms. Meanwhile, it needs to send the control decisions and the aggregated information to the dispatch layer to obtain optimized scheduling for longer time granularity.
Electronics 2020, 9, x FOR PEER REVIEW 4 of 18 priority model', which means when self-production by DGs is sufficient, total load demand is supplied by DGs, otherwise, self-storage is used as a priority instead of importing from the grid. On the load side of the system, BAS is able to monitor the operation and energy consumption of individual load. The load demand for total power is time-varying during the day. At a moment, the total power demand of load side ( ) load P t can be calculated by BAS and will be notified to the supply side quickly. The power demand will be assigned to DGs, storage systems and distribution networks according to the capabilities of these power sources at that moment and renewable energy will be utilized as much as possible.
In this paper, the microgrid is assumed to operate in grid-connected mode. The load profile is time-varying 24 hours a day. When the power generation and energy storage within the microgrid cannot follow the peak of the load profile, extra power will be exchanged from the distribution networks to MGIB via PCC. The load demands need to be met from the microgrid's own generation, energy storage and the utility grid moment-to-moment in order to avoid voltage drop and unreliable power supply.
The MGIB control strategy aims to ensure the stability of voltage and frequency, the real-time power balance between the load-side and the supply-side, and the maximum utilization of renewable energy. Meanwhile, in order to realize the energy balance in MGIB, the consumption power should be distributed between the DGs, energy storage system and distribution network on the premise that the energy target is satisfied. To achieve these goals, three pieces of information are needed-the real-time power requirements of the load side, real-time power capability of the DGs and ESS, and the power exchanged with the utility network. Therefore, a hierarchical control framework based on efficient information fusion between the load side and DG side is the key to implementing an overall control strategy.
The framework of two-dimensional fusion for an MGIB with composite loads is shown in Figure 3. In the framework, both the load side and the DG side have four logical layers: the physical layer, information layer, control layer and dispatch layer. Each upper layer is served by each lower layer. For example, the control layer needs to aggregate information from the information layer to make control decisions based on control algorithms. Meanwhile, it needs to send the control decisions and the aggregated information to the dispatch layer to obtain optimized scheduling for longer time granularity. In the framework of two-dimensional fusion for microgrid with composite loads, the real communication connections and energy transaction are established at the physical layer between the DG side and the load side. Based on the mechanism that each lower layer serves its neighboring upper layer, the two-sided peer upper layers can communicate with each other, but in an indirect In the framework of two-dimensional fusion for microgrid with composite loads, the real communication connections and energy transaction are established at the physical layer between Electronics 2020, 9, 550 5 of 18 the DG side and the load side. Based on the mechanism that each lower layer serves its neighboring upper layer, the two-sided peer upper layers can communicate with each other, but in an indirect way. Because the real connection occurs in the physical layer, the communication between upper layers totally depends on the physical layer. In this way, the two-sided peer layers, such as the information layer, control layer and dispatch layer can establish logical communication connections with the peer. Thus, the information of each layer can be sent to and synchronized with the peer in real-time. In Figure 3, the horizontal dotted lines indicate the logical communication relationship between two sides. The functions of each layer are defined in detail below.
(1) Physical layer: The physical layer is responsible for detecting the raw data of loads and DGs. From an information perspective, the Internet of Things (IoT) terminal sensors in the buildings which are used to detect raw data loads, including building equipment operating sensors, household appliance operating sensors, lighting sensors, temperature sensors, humidity sensors, smart meters, smart plugs, smart cables, etc. For the generation side, the raw data should be detected, including the state of charge (SoC) of the ESS, the instantaneous output power of the DGs and the exchanged power on the PCC, etc. In addition, inner loop controllers without communication support, like current and voltage regulation and droop control, should be included in this layer. (2) Information layer: The information layer is above the physical layer and provides end-to-end data preprocessing and transmitting. MGIB is often heterogeneous, and different communication technologies are used at the information access layer. All raw data detected by the physical layer are aggregated to this level by multiple communication technologies. Some consistency information and autonomous information can be processed at this layer and serve higher layers. (3) Control layer: For efficient and high-quality use of power, some information fusion based control methods that were served by the information layer with different time granularity need to be implemented in this layer, including: (a) power quality compensation control for voltage, frequency regulation and harmonic compensation, etc., (b) dynamic consensus control based on the power generation capabilities of DGs to achieve current and power sharing among different DGs, (c) demand-side response control based on load profile to achieve energy balancing between the load side and generation side. (4) Dispatch layer: The dispatch layer is responsible for energy management and optimization at a relatively large time granularity. The function of economic load dispatch, unit commitment and demand-side management are embedded in this layer based on the loads and available states of the DGs. The strategy of the dispatch layer can be modeled as an optimization process with the objective of maximizing economic benefits or environmental benefits with the constraints of the distributed system.

State Transition Mechanism Driven by Interaction of Supply and Demand
On one hand, the generation capability of the DGs that integrate renewable energy is time-varying due to many factors. For example, as the most prominent sources of renewable energy, solar and wind energy are volatile due to the stochastic nature of weather-dependent solar and wind resources. Factors like temperature, wind speed, air pressure, clouds, precipitation and sunlight radiation intensity can affect the power generation capacity of renewable energy. In the best case with the right weather conditions, the share of renewable energy can rise to 80 percent or more [22]. Conversely, renewable energy generation may also drop to zero on a windless night.
On the other hand, the consumption of power by building loads also changes quickly according to the consumption profile. Thus, a finite state machine (FSM) can be used to describe and maintain the state transition of the DG side and load side. In other words, both the DG side and load side have a finite state set and their states can be transitioned within the set with event triggering or time triggering. In this way, the occurrence of physical events and the result of information fusion can be used as triggers for FSM transitions, so that both DGs and loads can obtain information in real-time and adopt appropriate control strategies to make optimal control decisions.
The two-sided state transition mechanism of MGIB is illustrated in Figure 4. The DG side and load side periodically exchange information in a small time slot along the time axis and update their status based on this information. In addition, non-periodic external events can also trigger transitions in the current state. External events not only include physical events, such as DG start/stop, operating state change, load online/offline, but also include logical events such as information fusion results, consistency control information, demand response information, etc.
Electronics 2020, 9, x FOR PEER REVIEW 6 of 18 The two-sided state transition mechanism of MGIB is illustrated in Figure 4. The DG side and load side periodically exchange information in a small time slot along the time axis and update their status based on this information. In addition, non-periodic external events can also trigger transitions in the current state. External events not only include physical events, such as DG start/stop, operating state change, load online/offline, but also include logical events such as information fusion results, consistency control information, demand response information, etc. From a holistic point of view, the MGIB is a distributed controllable system with different operating modes. In each operating mode, the DGs and loads have different states, and the running state is both time and event driven. Due to the diversity of triggering factors, the operating state of MGIB is complex and varied. Therefore, it is important to study the real-time state transition relationship model of the system with an accurate response to external events. The state transition model of MGIB is shown in Figure 5. Firstly, let us discuss the structure of the state transition model. Both sides of the system are modeled as a double-layer FSMs from the outside to the inside. On the load side, the outer FSM maintains the load side state variables and state transition according to the load side events and information fusion results. The inner FSM maintains the state variables and state transitions of each load according to the specific load event and information. On the DG sides, the double-layer FSMs are similar to the load side. In the middle of two sides shown in Figure 5, the two-dimensional fusion model mentioned in Section 2 provides a transparent service for the physical layer, information layer, control layer and dispatch layer to enable the interaction between the load side and DG side. From a holistic point of view, the MGIB is a distributed controllable system with different operating modes. In each operating mode, the DGs and loads have different states, and the running state is both time and event driven. Due to the diversity of triggering factors, the operating state of MGIB is complex and varied. Therefore, it is important to study the real-time state transition relationship model of the system with an accurate response to external events. The state transition model of MGIB is shown in Figure 5. The two-sided state transition mechanism of MGIB is illustrated in Figure 4. The DG side and load side periodically exchange information in a small time slot along the time axis and update their status based on this information. In addition, non-periodic external events can also trigger transitions in the current state. External events not only include physical events, such as DG start/stop, operating state change, load online/offline, but also include logical events such as information fusion results, consistency control information, demand response information, etc. From a holistic point of view, the MGIB is a distributed controllable system with different operating modes. In each operating mode, the DGs and loads have different states, and the running state is both time and event driven. Due to the diversity of triggering factors, the operating state of MGIB is complex and varied. Therefore, it is important to study the real-time state transition relationship model of the system with an accurate response to external events. The state transition model of MGIB is shown in Figure 5. Firstly, let us discuss the structure of the state transition model. Both sides of the system are modeled as a double-layer FSMs from the outside to the inside. On the load side, the outer FSM maintains the load side state variables and state transition according to the load side events and information fusion results. The inner FSM maintains the state variables and state transitions of each load according to the specific load event and information. On the DG sides, the double-layer FSMs are similar to the load side. In the middle of two sides shown in Figure 5, the two-dimensional fusion model mentioned in Section 2 provides a transparent service for the physical layer, information layer, control layer and dispatch layer to enable the interaction between the load side and DG side. load according to the specific load event and information. On the DG sides, the double-layer FSMs are similar to the load side. In the middle of two sides shown in Figure 5, the two-dimensional fusion model mentioned in Section 2 provides a transparent service for the physical layer, information layer, control layer and dispatch layer to enable the interaction between the load side and DG side.
Secondly, the mechanism of the state transition model is analyzed based on the structure described above. In order to achieve power bilateral balance and improve energy efficiency, both the DG side and load side should not only process the information at the local end in real time, but also realize the efficient and transparent transmission of the information to the opposite end. In this way, the status can be updated quickly to drive the state transition and, finally, to realize an accurate and efficient response. Based on time-driven and event-driven triggers, FSM implements two-side information exchange and state transition. As shown by the polylines with endpoints in Figure 5, the solid lines represent bottom-up information flow and dotted lines represent top-down control flow. The information flow is detected by the physical layer and spirals up on the local side to drive the FSM transition in the upper layer, meanwhile the peer layer is notified at each layer and the higher level information interacts between the upper layers of both sides.
In this way, the information flow and the reverse control flow are formed vertically between the physical layer, information layer, control layer and dispatch layer. The bidirectional multi-layer information flows between the load side and DG side and is formed horizontally. Thus, two-dimensional information fusion is achieved as shown in the middle part of Figure 5.

Power Consensus Control Strategy Driven by Self-consumption
The widespread use of IoT technologies in the energy domain has made it possible to bridge the gap between generation and consumption by automatically regulating the bidirectional flows in real-time. Self-generators have, therefore, become self-consumers by using and storing as much electricity generated locally as possible. The efficient information fusion and data-driven control models are established in Sections 2 and 3 as the fundamentals for achieving a balance of supply and demand. Then, in this section, a power consensus control algorithm driven by self-consumption strategy will be discussed to further introduce the operation details.
The following assumptions will be discussed in this section: (1) When ESS supplies energy for the loads, its power is positive (P Batt (t)>0) and when charged, its power is negative (P Batt (t)<0). (2) When the utility grid transfers energy to MGIB, the exchanged power on the PCC between the distribution network and the microgrid is positive (P TL >0) and when the opposite occurs, it is negative.

System Operation Target
The goal of the system is to maximize the utilization of renewable energy and to provide high quality power for Microgrid-Enabled Intelligent Building. On one hand, it is necessary to reduce the current circulation on the supply side as much as possible in order to reduce the loss of energy. It means that the load side demand needs to be allocated to the various power sources according to the generation capacity. On the other hand, the building loads need to minimize the use of electricity from distribution networks and to use renewable energy from DGs and storage systems as much as possible [23][24][25][26][27]. The MGIB system control strategy is a 'self-consumption priority model', which means that when self-production by DGs is sufficient, total load demand is supplied by DGs; otherwise, self-storage is used as a priority instead of importing from the grid.
During the system operation, renewable energy generation is free of any additional costs. Therefore, the operating cost of the system mainly come from the electric charge of the distribution network [28][29][30]. When the utility grid delivers electricity to the microgrid, which means that the renewable energy generation cannot meet the demand from buildings, the cost is positive. On the contrary, when the microgrid injects electricity to the utility grid, which means the renewable energy generation can meet the demand of buildings and storage systems, the cost is negative. Thus, the economic target of the MGIB over 24 hours can be modeled as where P TL i is the exchanged power on the PCC between the utility grid and microgrid, S is the price of electricity for the moment i. From the energy balance conditions on the load side and the supply side of the system, the exchanged power on the PCC can be described as where P TL (t) is the exchanged power on the PCC at the moment t, P load (t) is total load requirement of the intelligent building at the moment t, P Batt (t) is the output power of the storage system, P DG (t) is the renewable energy power provided by DGs at the moment t.

Consensus Control Strategy with Self-consumption
To ensure the high reliability of the power supply to intelligent buildings, the MGIB operates in grid-connected mode. Thus, surpluses of electricity can be sold and injected into the grid or be used for charging batteries. Connection to the grid enhances the flexibility and reliability of the power supply to electricity users in the building. In addition, the capacity of the battery can be significantly reduced in grid-connected mode. The power consensus control strategy of the Microgrid-Enabled Intelligent Building is shown in Figure 6.
Operational Condition 1: The sum of the DGs is greater than the sum of the power demand of the loads.

Operational Condition 2:
The sum of the DGs is less than the sum of the power demand of the loads. However, the power provided by the battery can meet the gap between load demand and DGs.
Operational State 1: The sum of the DGs is greater than the sum of the power demand of the loads, and the energy storage system is already fully charged. In this situation, the microgrid transfers excess power to the distribution network. The storage system works in the 'pass-by' mode, neither charging nor discharging.

Operational State 2:
The sum of the DGs is greater than the sum of the power demand of the loads, and the energy storage system is not fully charged. In this situation, the battery can accept the remaining renewable energy, and the exchanged power between the microgrid and the distribution networks is zero.
To ensure the high reliability of the power supply to intelligent buildings, the MGIB operates in grid-connected mode. Thus, surpluses of electricity can be sold and injected into the grid or be used for charging batteries. Connection to the grid enhances the flexibility and reliability of the power supply to electricity users in the building. In addition, the capacity of the battery can be significantly reduced in grid-connected mode. The power consensus control strategy of the Microgrid-Enabled Intelligent Building is shown in Figure 6.  From the above analysis, we can find that DGs can meet all the power needs of the intelligent building in both Operational State 1 and Operational State 2. Here, the total power demand can be represented as P Batt < 0, the storage system worked as a load (7) and the power allocation strategy is Operational State 3: The sum of the DGs is less than the sum of the power demand of the loads, and the battery is too low to supply power. In this case, the distribution system needs to transfer power to the microgrid. At the same time, in order to prevent the storage system from working in the over-discharge state, it is necessary to charge the storage system.
Electronics 2020, 9, 550 10 of 18 In this operational state, the total power demand is supplied by both DGs and the distribution system. This situation requires a consensus control algorithm to allocate the power demand between DGs and the distribution system. The total power demand can be represented as P Total = P Load (t) + P Batt (t) SOC < SOC Min , P Batt (t) < 0, the storage system worked as a load (10) and the power allocation strategy is Operational State 4: The power supplied by DGs and storage systems can meet all the power needs of the loads in an intelligent building. In this situation, the exchanged power on the PCC between utility grid and microgrid is zero.
In this operational state, the total power demand is supplied by both DGs and storage systems. The consensus control algorithm is needed to allocate the power demand between DGs and the storage system. The total power demand is the sum of all loads in intelligent building and can be represented as P Total = P Load (t), the power allocation strategy is Operational State 5: The power supplied by DGs and storage systems cannot meet all the power needs of the loads in an intelligent building. The distribution system needs to transfer additional power to microgrid. The exchanged power on the PCC between the utility grid and microgrid is greater than zero.
In this operational state, the total power demand is supplied by DGs, the storage system and the distribution system. The consensus control algorithm is needed to allocate the power demand between the three power sources. The total power demand is the sum of all loads in the intelligent building P Total = P Load (t), and the power allocation strategy is where P Batt (t) is the output power of the storage system.

Case Study-IoT Microgrid Laboratory at Aalborg University
The IoT Microgrid Laboratory (IoT-MGLab) at Aalborg University is a living laboratory that intends to research the framework of the Energy Internet and various smart energy applications by integrating IoT technologies into microgrids [31]. The main idea of this laboratory is to simulate an intelligent building environment with renewable energy access, intelligent energy management, measurement and control automation, things-based convergence, energy-based interoperability and energy digitalization, etc. The IoT-MGLab also serves as a demonstrator to show the viability of low voltage DC and AC systems for future households, which will enhance the energy efficiency, flexibility and reliability following the Danish smart grid strategy [32][33][34][35].
The IoT-MGLab is located in the building Pontoppidanstraede 109-A of the Department of Energy Technology in Aalborg University, Denmark. The laboratory is equipped with several means of distributed generations, such as PV panels, a wind turbine and an underfloor heating-cooling system, and is expected to be equipped in the near future with a controllable micro-combined heat and power (mCHP) generator and EV charging infrastructure to form a fully featured autonomous and IoT-enabled residential MGIB. Figure 7 shows photographs of the IoT-MGLab.  Figure 8. shows the infrastructure of the IoT-MGLab for the digitalization and control of the MGIB system. The IoT-MGLab is designed to emulate a residential building which consists of four areas: a control room, a kitchen, a living room and an office. The energy resources, such as the utility grid, PV system, wind turbine, battery, EV charger and fuel cell are connected to the common buses in the control room. Finally, three power buses are provided for the household supply ring, which are AC 230V, DC 48V and DC 400V.
To get full automation of measurement and control, two groups of sensors and a group of actuators were deployed in the IoT-MGLab. One group of sensors is responsible for collecting the energy generation data of DGs, the energy consumption data of each load, indoor environmental data like temperature, humidity, air quality, lighting and occupants, etc. Another group of sensors is used to detect outdoor environmental data, which are related to renewable energy generation such as wind speed, solar radiation, rain, etc. These actuators, including smart plugs and smart relays, are responsible for the connection or disconnection of loads and distributed generators.  Figure 8. shows the infrastructure of the IoT-MGLab for the digitalization and control of the MGIB system. The IoT-MGLab is designed to emulate a residential building which consists of four areas: a control room, a kitchen, a living room and an office. The energy resources, such as the utility grid, PV system, wind turbine, battery, EV charger and fuel cell are connected to the common buses in the control room. Finally, three power buses are provided for the household supply ring, which are AC 230V, DC 48V and DC 400V.
To get full automation of measurement and control, two groups of sensors and a group of actuators were deployed in the IoT-MGLab. One group of sensors is responsible for collecting the energy generation data of DGs, the energy consumption data of each load, indoor environmental data like temperature, humidity, air quality, lighting and occupants, etc. Another group of sensors is used to detect outdoor environmental data, which are related to renewable energy generation such as wind speed, solar radiation, rain, etc. These actuators, including smart plugs and smart relays, are responsible for the connection or disconnection of loads and distributed generators. All real-time monitoring data will be aggregated on the IoT platform, which is implemented based on the FIWARE framework [36][37][38]. Different IoT devices may use different wireless communication protocols and IoT protocols. In order to ensure good scalability and compatibility of the IoT platform, Next Generation Service Interfaces (NGSI) are used to store and exchange data in the core domain of the IoT architecture. NGSI is a protocol developed by Open Mobile Alliance (OMA) to manage contextual information about context entities, such as the lifetime and quality of information, and access the context information with queries and subscription/notification mechanisms [39][40][41]. Different IoT devices can be aggregated on the different gateways according to the adopted wireless communication protocol and IoT protocol, and the IoT agent can be an adapter to translate their data into the NGSI domain for unified data storage and exchange. There are two key components in the IoT platform, one is the Context Broker, and the other one is the Bigdata Center. The Context Broker is the real-time data center which allows users to manage the entire lifecycle of context information including updates, queries, registrations and subscriptions [42,43]. It is a NGSI server implementation used to manage context information and its availability. The Bigdata Center is the historical data center; the data of load consumption profile, DG generation profile, indoor/outdoor environmental profile are all recorded and stored in the Bigdata Center. Based on the mechanisms described above, functions like data synchronization, subscription/notification, data persistence and integration and inter-operations are achieved in the IoT platform. The detailed FIWARE-based IoT Architecture of IoT-MGLab can be found in Figure 9. In this figure, it can be seen that the four-layer hierarchical control framework proposed in Section 2 efficiently supports achieving information fusion between the load side and DG side. All real-time monitoring data will be aggregated on the IoT platform, which is implemented based on the FIWARE framework [36][37][38]. Different IoT devices may use different wireless communication protocols and IoT protocols. In order to ensure good scalability and compatibility of the IoT platform, Next Generation Service Interfaces (NGSI) are used to store and exchange data in the core domain of the IoT architecture. NGSI is a protocol developed by Open Mobile Alliance (OMA) to manage contextual information about context entities, such as the lifetime and quality of information, and access the context information with queries and subscription/notification mechanisms [39][40][41]. Different IoT devices can be aggregated on the different gateways according to the adopted wireless communication protocol and IoT protocol, and the IoT agent can be an adapter to translate their data into the NGSI domain for unified data storage and exchange. There are two key components in the IoT platform, one is the Context Broker, and the other one is the Bigdata Center. The Context Broker is the real-time data center which allows users to manage the entire lifecycle of context information including updates, queries, registrations and subscriptions [42,43]. It is a NGSI server implementation used to manage context information and its availability. The Bigdata Center is the historical data center; the data of load consumption profile, DG generation profile, indoor/outdoor environmental profile are all recorded and stored in the Bigdata Center. Based on the mechanisms described above, functions like data synchronization, subscription/notification, data persistence and integration and inter-operations are achieved in the IoT platform. The detailed FIWARE-based IoT Architecture of IoT-MGLab can be found in Figure 9. In this figure, it can be seen that the four-layer hierarchical control framework proposed in Section 2 efficiently supports achieving information fusion between the load side and DG side. The core components of the FIWARE-based framework are the Context Broker and the Bigdata Center, which enable real-time data and historical data processing to drive the upper level services and applications [44,45]. These data-driven service-based applications are developed in the dispatch layer to make decisions and send the power dispatching commands to the lower layer to achieve the goals of intelligent energy management, demand response, intelligent load recognition and generation/consumption prediction. FIWARE, acting as the resource integrator and coordinator, covers the control layer and information layer to bridge the device-based physical layer and business-based dispatch layer. In this way, the consumption and supply can be adjusted automatically to achieve higher energy efficiency, quality and cost reduction.
Furthermore, based on the state transition mechanism in Section 3, users can get the real-time operations and obtain access to the resources of the IoT-MGLab on the web interaction interface of the IoT-MGLab system, which is shown in Figure 10. The interaction between the upper level applications and lower-level DG resources and loads can be performed through this interface, such as the power-limit setting, DG and load scheduling, the demand response based on load priority and real-time generation and consumption profiles. Of course, these operations and API can also be called by data-driven upper level applications. The core components of the FIWARE-based framework are the Context Broker and the Bigdata Center, which enable real-time data and historical data processing to drive the upper level services and applications [44,45]. These data-driven service-based applications are developed in the dispatch layer to make decisions and send the power dispatching commands to the lower layer to achieve the goals of intelligent energy management, demand response, intelligent load recognition and generation/consumption prediction. FIWARE, acting as the resource integrator and coordinator, covers the control layer and information layer to bridge the device-based physical layer and business-based dispatch layer. In this way, the consumption and supply can be adjusted automatically to achieve higher energy efficiency, quality and cost reduction.
Furthermore, based on the state transition mechanism in Section 3, users can get the real-time operations and obtain access to the resources of the IoT-MGLab on the web interaction interface of the IoT-MGLab system, which is shown in Figure 10. The interaction between the upper level applications and lower-level DG resources and loads can be performed through this interface, such as the power-limit setting, DG and load scheduling, the demand response based on load priority and real-time generation and consumption profiles. Of course, these operations and API can also be called by data-driven upper level applications. As described in Section 4, the control strategy of IoT-MGLab is a 'self-consumption priority model', which helps to maximize the utilization of renewable energy and bridge the gap between generation and consumption via regulating power flows between the grid, DGs and batteries automatically. Based on the consensus control method driven by the self-consumption strategy proposed in this paper, the data of the power distribution between the grid, DGs and batteries can be presented on the data visualization portal in real-time. In addition, all real-time and historical data, such as the energy profile of each area, load consumption, smart meter data, indoor/outdoor environmental parameters and occupants' behavior data can be presented on the portal in a vivid way. The data visualization portal of the IoT-MGLab system and the results of the self-consumption priority model are shown in Figure 11. Based on priority settings, the active power and reactive power from the DG side and the load side will cooperate with each other to achieve self-consumption. As described in Section 4, the control strategy of IoT-MGLab is a 'self-consumption priority model', which helps to maximize the utilization of renewable energy and bridge the gap between generation and consumption via regulating power flows between the grid, DGs and batteries automatically. Based on the consensus control method driven by the self-consumption strategy proposed in this paper, the data of the power distribution between the grid, DGs and batteries can be presented on the data visualization portal in real-time. In addition, all real-time and historical data, such as the energy profile of each area, load consumption, smart meter data, indoor/outdoor environmental parameters and occupants' behavior data can be presented on the portal in a vivid way. The data visualization portal of the IoT-MGLab system and the results of the self-consumption priority model are shown in Figure 11. Based on priority settings, the active power and reactive power from the DG side and the load side will cooperate with each other to achieve self-consumption.

Conclusions
Energy consumption, especially power consumption in countries, will continue rise as the world's population, urbanization and global warming continue to escalate. This trend not only requires a significant increase in the use of renewable energy, but also places higher demands on the energy management system. IoT technology, communication technology and control technology enable energy management systems with more powerful capabilities and can provide more transparent information acquisition, transmission and processing capabilities for microgrid systems. In this article, first we designed the hierarchical structure of Microgrid-Enabled Intelligent Buildings with composite loads. The building blocks and functions of each layer, including physical layer, information layer, control layer and dispatch layer, were respectively discussed in detail. Secondly, to achieve transparent information fusion and interactive cooperation between the supply side and demand side, a state transition mechanism driven by a combination of time and events was proposed to active the real-time and mutual response of generation and loads dynamically. Thirdly, based on the above hierarchical fusion structure and data-driven state transition mechanism, a power consensus control algorithm driven by a self-consumption strategy was further proposed to achieve the autonomous balance of supply and demand. Finally, the IoT Microgrid Laboratory at Aalborg University was introduced to show how to implement this novel hierarchical IoT-based scheme in a Microgrid-Enabled Intelligent Building, and the power consensus control method based on the state transition mechanism was verified to achieve a renewable energy self-consumption strategy.

Conclusions
Energy consumption, especially power consumption in countries, will continue rise as the world's population, urbanization and global warming continue to escalate. This trend not only requires a significant increase in the use of renewable energy, but also places higher demands on the energy management system. IoT technology, communication technology and control technology enable energy management systems with more powerful capabilities and can provide more transparent information acquisition, transmission and processing capabilities for microgrid systems. In this article, first we designed the hierarchical structure of Microgrid-Enabled Intelligent Buildings with composite loads. The building blocks and functions of each layer, including physical layer, information layer, control layer and dispatch layer, were respectively discussed in detail. Secondly, to achieve transparent information fusion and interactive cooperation between the supply side and demand side, a state transition mechanism driven by a combination of time and events was proposed to active the real-time and mutual response of generation and loads dynamically. Thirdly, based on the above hierarchical fusion structure and data-driven state transition mechanism, a power consensus control algorithm driven by a self-consumption strategy was further proposed to achieve the autonomous balance of supply and demand. Finally, the IoT Microgrid Laboratory at Aalborg University was introduced to show how to implement this novel hierarchical IoT-based scheme in a Microgrid-Enabled Intelligent Building, and the power consensus control method based on the state transition mechanism was verified to achieve a renewable energy self-consumption strategy.