Design and Simulation of an Energy Homeostaticity System for Electric and Thermal Power Management in a Building with Smart Microgrid

Nowadays, microgrids are gaining importance in electric power generation and distribution environments due to their flexibility, versatility, scalability and the possibility of supplying ancillary services when connected to the grid. They allow for the customization of electric supply for very different types of consumers. Therefore, a new control model for power and energy management based on homeostaticity of electric power systems (EPS) is presented, which has been already analyzed and approved by ENEL Chile in its developmental stage. ENEL, the largest electric utility in the country, is interested in incorporating smart microgrids in the electricity distribution market, as part of a worldwide policy. Such microgrids are to be installed in buildings serviced by ENEL. To demonstrate the model’s utility, a Simulink model of a real microgrid is used, which is comprised of PV generation, energy storage, an air conditioning (AC) equipment and thermal storage of the building upon which the microgrid is installed. The behavior of every element is simulated, including the dynamic thermal model of the building in order to optimize energy management and power supply versus consumption. The behavior of the whole system is analyzed under different environmental profiles and energy consumption patterns using the proposed homeostaticity system.


Introduction
Nowadays, electric utility services are facing a series of legislation changes that totally alters the power environment.This has caused the emergence of problems that make the grid management difficult and are still not solved.Those abrupt changes in the power system could be justified from the point of view of the market policies and from the point of view of the reliability and manageability of the grid.
On the other hand, market policies are currently being influenced by the concept of "unbundling".This principle establishes that the activities of generation, transmission, distribution and the electric supply must be managed by independent organizations, or even by regulated entities, as could be the transmission activities in the case of Europe [1].Of course, the implementation of this idea requires a Energies 2019, 12, 1806 2 of 19 totally new way of operation in terms of information sharing amongst the implied agents of the power system and its management [2].
An example of the role of legislators toward the impulse of a more advanced power system can be seen in the Energy Independence Roadmap for the United States [3], which was done during the term of Obama in 2013.This roadmap established the principles and objectives to promote those changes in the power system.
Notwithstanding, the advances to reach those improvements for the power system have been accelerated by the influence of catastrophic natural disasters suffered by the US in the past [4].For example, extreme weather events like torrential rains out of the blue or heavy snowfall, earthquakes and huge fires in some regions, where normally these types of destructive events did not occur.This is where the second mentioned cause takes importance, due to the need of a more reliable power system that could be flexible enough to minimize the effects of those natural disasters.
Due to this situation, the United States of America considered that it was necessary to take action.As an example, in 2014 the US Senate passed a bill [3] where they showed their support to distributed energy system connected to the power grid (like microgrids) to reduce the effects of the described natural and climate disasters, making the electric power distribution more resilient and proactive towards the unexpected and destructive climatic events [5,6].
This support stimulated the developing of multiple initiatives in the field of microgrids and distributed power system.Some examples are grants, demonstration projects, university research, and multiple studies to estimate the costs involved in the industry transformation and to decide what could be the most adequate federal policy actions to continue and support this developing [7,8].In this sense, another significant decision (from the point of view of legislation) was the Energy Policy Modernization Act of 2015 [9], promoted by the US Senate on September 2015, with the objective of promoting the US Grid improvement.
From a global point of view, this modernization of the grid can also be seen in the same line in the rest of the world, as in Canada [7] and Europe, where the "unbundling" has also been implemented in recent years.
Currently, in the case of Latin America, particularly in Chile and Brazil, changes in the electric legislation are under study by legislators and various federal and local authorities with the collaboration of industry stakeholders to promote various policies and technologies whose application can constitute a more secure and reliable power grid.Those initiatives are being promoted by big players like ENEL, who have spurred on several pieces of legislation not only in North America but also in South America [10].
In this situation, Chile is also moving toward power grid improvements as part of the energy matrix modernization plan of the country, firmly advancing towards a greener, more sustainable and energy efficient state through the use of renewable energies and less dependence on fossil fuels.One of the promoters is The Natural Resources Defence Council (NRDC), a non-profit environmental organization dedicated to research and advocacy activities.In the report titled "From Good To Great: The Next Step in Chilean Energy Efficiency" [11] they encourage the Ministry of Energy to make an Energy Efficiency Law.To accomplish this objective, they propose the implementation of a program cycle to be repeated once every ten years.To make the start easier, a three-year preparatory period (from 2014 to 2016) was suggested.It was in this period that the government identified the relevant actors, established the necessary processes, and passed the regulations and the energy efficiency law.After this preparation, the first ten-year cycle (from 2017 to 2027) began.Pursuant to this goal, and considering the constitution of formal participatory processes, the Ministry of Energy was expected to "set a schedule for the issuance of Minimum Energy Performance Standards (MEPS) for appliances from the year 2017 until 2027, prioritized according to benefit" [11].This recommendation has largely been heeded by the prior and current administrations and is providing its benefits.
In this line, one of the objectives of the present paper is precisely to make this change easier, by means of a control system for microgrids that achieves a better integration between customers and Energies 2019, 12, 1806 3 of 19 utilities in Chile.This is an unavoidable action taking into account the increasing difficulty of a power system management.

Understanding the Electric Utilities' Perspective in Today's Distribution Market
The sum of all these facts has recently caused a radical change in the power environment, and this points to a great increasing complexity of electric power systems (EPS) and the growing penetration of the smart grid concept by electric utilities like ENEL in Chile [12].
In order to improve the flexibility, versatility and reliability of the power grid, the paradigm shifts of smart energy systems and smart grid supply [13,14] are being used more regularly, as the benefits are widespread.A specific hierarchical distributed energy arrangement being used today to apply this paradigm is the microgrid, which is comprised of a group of heterogeneous power supply sources, both renewable and non-renewable, organized in a particular manner and located close to the loads to which it will supply electricity.Microgrids are built with a specific purpose in mind: they are aimed at servicing a particular community of consumers somewhere, and this can happen with the presence of the electricity distribution grid, where it can operate grid-connected or without the grid connection, in which case it operates in island mode.It is able to operate off-grid during a certain time (or even permanently, in the case of microgrids which are not grid-tied) and on-grid or grid-connected most of the time, but preserving its autonomy and independence if need be.
Another important aspect that must be considered in developing countries like Chile is the sustainable development [10].Of course, this development is always connected to renewable energy resources (RER), sources that contain a huge potential in Chile and also in the other countries of South America.In this changing power environment, extending the use of distributed energy resources (DER) must be a priority in the path of improving the electricity distribution sector, and of course, the whole power system.The microgrids seem to be a convenient solution to integrate the distributed generation (DG) into this environment, particularly the grid-tied microgrids, which allow a total integration in it [15,16].
The only way to achieve this great change is a total support of the government and regulatory agencies.In this sense, this support must be expressed by adequate legislation proposals, and incentive application when necessary, following the example of North America, where the advances in the power system have had significant growth in the past years.In this way, as it has been already explained, this type of legislation is also very related to the handling capacity of natural disasters [17,18], which also have a huge impact into the power system infrastructure [5,19].
There are some big barriers in the path to achieve these objectives.The first of them is the electric power system (EPS) feebleness and centralization.The centralization is a consequence of the traditional view of the power system, where it was considered the most convenient solution (at least with the technological levels of past years, and the lack of back-up and emergency systems to recover the whole system after a fault), but now the tendency is changing it to a more decentralized structure [20].The second barrier is the legislation.In Chile, unlike in the US, there is no energy sustainability roadmap nor action plans to face climatic challenges by the utilities (in general, there is only the traditional maintenance models).In the same way, in other countries of South America, the lack of a strong, coherent and more forward-looking environmental policy can be observed [21].
In spite of some advances in this area, there are still weaknesses in the law that are being used by companies to operate with disregard for basic environmental norms and health issues that create grave concerns for society as it is the case with the town of Quintero located in the V Region of Chile [22].While energy efficiency and other means of safeguarding the energy supply, aside from the traditional means of electricity distribution infrastructure modernization used to be the norm in the industry, so long as the power supply was not threatened, that is no longer the case.Chile has had its tough share of disruption of basic public services like electricity and water supply just like other countries in America [17].Another example is Puerto Rico, which was hit hard very recently and is still recovering from the huge damages.Also, New Orleans continues to suffer a lot of problems after hurricane Katrina [19].
When facing these described challenges, microgrids are being signalled as a possible solution.Microgrids usually include local generation, such as solar or wind or both, and at certain times they also resort to other means of power generation which are more conventional in nature-like electric power generators or micro-turbines, which are able to provide rapid power dispatching (especially in those cases when the microgrid works off-grid, on what is called island mode) and an energy storage method (such as batteries), if necessary.Some microgrids choose to operate without energy storage altogether and simply opt for taking the electric supply that is needed from the grid whenever it is needed, in times when the microgrid power supply is not enough to satisfy the full loads demand.The decision of whether to use or not to use batteries to store energy depends on the electricity consumption profiles and specific necessities of the community of users (e.g., electricity-dependent people who have medical equipment at home for specific treatments or health sustenance like kidney dialysis, which must always be connected to electric power supply), and on the particular plant capacity options versus peak load patterns, among other things.The impact of this local generation and its advantages has been broadly studied.For example, reference [23] present a real case showing the impact of solar generation over the consumption of a group of consumers of residential buildings in Santiago, Chile.
These types of energy consumer groupings in residential buildings-a strategy being considered by utilities like ENEL Distribution in Chile-allow for identification of diverse electricity consumption profiles at different hourly schedules and displaying various energy versus power consumption patterns, all of which give the electric utility the possibility of managing more appropriately and efficiently, the energy of the microgrid and its relationship with the consumers.As a matter of fact, this particular strategy allows the electric utility to offer electric supply service customization, something that was non-existent before the advent of the smart grid and the microgrid.However, there is a drawback amongst all the benefits.There is an increase in the complexity when managing the system as a whole, particularly when the number of consumers is large and the peak power consumption periods are prolonged or extensive.Hence, it is necessary to apply methods to simplify this task and make it more manageable, as it will be described in this paper.

Microgrid Control and Its Integration with the Utilities
Having pointed out the worries of power distribution utilities and the importance and advantages of the microgrids into the power system, the next step should be selecting the method for the integration and control of a building (or a customer aggregation) with the utility.
A general scope can be found in [24], where the authors make a complete review of state-of-the-art control strategies and control principles, such as model predictive control, droop control, or multi-agent systems.
To solve the energy exchange problems, in [25] the use of an "energy router" is proposed to simplify the connection of energy flows between different type of devices.Talking about management algorithms, reference [26] propose a method that use parametric programming.
Other authors have proposed similar works showing simulation and energy management system (EMS) design, such as [27].For example, reference [28] present an interesting paper for predicting multi-building energy use at a campus or city district scale in Chine involving 17 buildings.In short, they assert that predicting energy use in a cluster of buildings is possible and can lead to better building management policies and guidelines, by noting some key interactions among them.This imitative has, according to the authors, recently gained much attention; and more researchers are beginning to define reference buildings, as a metric standard against which other similar buildings can be compared and monitored, so as to achieve certain efficiency standards and metrics.The study focuses on inter-impact amongst building groups [28].
In [29], how an energy analysis system operating in a test building can provide valuable information on building energy expenditures so as to establish a way to predict particular consistent behavior in energy expenditure is described.The system discussed in said paper operates by monitoring the energy consumption of users in the building and providing a detailed analysis of when, where and how much energy is being consumed in the building.Associated events and particular circumstances and conditions in the building itself are also part of the input for the analysis being conducted.As examples, it proposes that the analysis taking into account a heating balance point, a cooling balance point and an exception rank analysis (to help with the identification of other type of data, such as energy consumption data).The overall aim lies in determining the steps that could be taken in order to reduce the energy footprint, and also to determine the drivers that play a key role in curving down energy consumption.Finally, the system may show the results of the analysis on a user interface device [29].
In [30], the authors show how the so-called urban building energy modeling (UBEM) is a very useful tool when creating energy efficiency programs for buildings in a city.In the process of applying UBEM, a critical step is making a city-scale dataset of the building, which is under study.With this dataset, it is possible to generate energy models of urban buildings and make a simulation of their performance automatically.The data needs, data standards, and data sources that should be used to develop city building datasets for UBEM are also established.The results of the study over existing public data sources from various studied cities show that most cities have adequate public data to properly apply the UBEM methodology; however, as the authors comment, "the data are represented in different formats without standardization, and there is a lack of common keys to make the data mapping easier".Authors also provide a study case to integrate the different data sources of various city departments of San Francisco, California, where along other issues, the data mapping process is introduced and discussed.A given recommendation to make easier the process of data mapping is to use unique building identifiers as common keys in the data sources (in this way, a certain standardization could be reached).The application of the described integration methods and workflow is also made for the cases of other US cities with the objective of developing the city-scale datasets of their buildings, such as San Jose, Los Angeles, and Boston.However, no mention is made here of the role of the electric utilities servicing these buildings' energy needs, which is a key point taking into account the recent and current evolution of the whole power system and the changes in related legislation, as it was explained before.
The energy management in a power system can also be understood under the perspective of Homeostatic Control (based on Homeostasis), in order to establish the relationship between the variables and actions that must be taken into account by the system.The concept of Homeostasis, which was originally defined for the biological field, describes how living organisms regulate themselves to keep internal conditions stable (and avoid external disturbances) [31].This biological principle can be adapted to create an energy management system (EMS) for a microgrid, whose objective is keeping all the conditions of the system (keep enough energy in batteries, load monitoring to avoid excessive consumption, etc.) stable [16].Specifically, it can be described as keeping continuous feedback between energy supply, generation and consumption (and also all other disaggregated values and variables in the microgrid), so as other action algorithms can be easily implemented to achieve certain objectives.These objectives could be a better use of renewable energy resources and DER [32], a wise management of storage systems and, of course, the use of more complicated information provided by the distribution system operator or the utility (which would correspond to the integration of explicit and implicit demand response (DR) programs) [20].As can be seen, this type of control system has a huge potential to achieve a better integration between a building and the environment (i.e., the power supplier and the renewable energy resources) and also a smarter use of the building (from the point of view of internal conditions as temperature and comfort).
There are multiple published papers in the field of homeostatic control and its applications in EPS and sustainable hybrid energy systems (SHES).[33,34] show the application of these principles over micro-generation systems and over different hybrid energy systems that include energy demand response.Moreover, [35] make a study of energy homeostasis from the point of view of exergy management and show that HC applications in EPS in general, and particularly in SHES, boost the exergy content in the system itself.The exergy is a thermodynamic concept that can be defined as the maximum useful work extracted from a system, as it reversibly comes into equilibrium with its environment.Likewise, exergy is also a measure of energy quality and is defined relative to a system's environment.Therefore, whenever the energy efficiency of the EPS is raised, and there is more energy available in the microgrid to supply electricity to consumers, while at the same time, having the alternative of the grid supply, the higher the exergy in the system as a whole becomes.What this means is that with the grouping of consumers in the residential building, coupled with the microgrid installed in the same building and the grid constitute a single system, that is capable of elevating its exergy content, as it increases its energy efficiency and productivity over certain period of time of its electricity generation and supply versus consumption dynamics.Finally, [36] expose the application of homeostatic control without energy storage.
One of the advantages of this type of control is its scalability.It is also very versatile and flexible due to its hierarchical structure, so it can be applied over a wide range of power systems.
While thermal and electrical energy management and control are modeled, analyzed and simulated based on a set of predefined rules and conditions studied before-they have been done so almost entirely in the context and scope of smart buildings technologies, and in advances in buildings' specific energy efficiency metrics.Hence, the salient and very distinct features and contributions of the present paper lie in the case study being presented, which is in the context and scope of energy homeostaticity for electrical and thermal energy management and intelligent control, allowing for the much needed electric utility-customer integration and coordination described, both of which cooperate in search for an optimal use of electrical and thermal energy in the residential building used in the example, and with the incorporation of Distributed Generation Systems (DGS) tied to the electrical distribution network, deploying a growing presence of renewable/green energies, which is what is of keen interest to electric utilities like ENEL.The aim is to simplify and expedite the energy management and power control of a grid-tied microgrid installed in a building, while at the same time, being able to improve real-time connectivity and communication with the electric utility to ensure optimal service management and efficiency from every angle of the triad: the electric utility, the customer and the building, not just the building alone when providing flexibility and ancillary services to the electric power distribution network.In this sense, the present paper applies this paradigm over a real case study, a microgrid installed in a university laboratory building in Santiago, Chile including a thermal study using temperature sensors.
In Section 2, a study of the microgrid is done in order to determine which are the most interesting monitoring variables, and the control actions that could be applied to optimize system performance along with the rules for managing the system adequately.Using this information, Section 3 describes a control flow diagram for the EMS.In turn, Section 4 shows the results of the simulations applying the proposed homeostatic control algorithm.In Section 5, a brief discussion about the relation and dynamics between electric utilities and the customers are discussed.Finally, the conclusions are described in Section 6.

Microgrid Laboratory
The work presented in this paper is centered on a real laboratory building (Figure 1a) located at the Campus San Joaquin of the Universidad Técnica Federico Santa María (UTFSM) in Santiago (Chile) under the supervision of a team of researchers from the Department of Electrical Engineering, which is used for research and teaching purposes.One of its laboratories is dedicated to a smart microgrid system to be tested prior to its installation in a building chosen by ENEL Distribution which is the main and largest electric utility in the country.The testbed is part of an ongoing research project to incorporate distributed generation systems in the form of smart microgrids to a number of residential and commercial buildings currently being serviced by ENEL.The project's chief objective is the realization of probes about renewable energy generation and distribution by means of grid-tie microgrids installed and fully data-integrated with ENEL Smart Metering/Smart Grid division.Along with this, there are energy storage, automatic metering infrastructure (AMI) and heating ventilating air conditioned (HVAC) systems being operated and monitored by the electric utility.
and energy management systems (EMS), which also considers the thermal behavior of the building to improve the utility-customer cooperation.This control system has been simulated extensively and has been connected to a model of a real microgrid in operation with full data integration capability.Thanks to this, it is possible to make a more accurate control adjustment of parameters applying different use cases.
The smart microgrid to be controlled and managed by ENEL contains multiple systems, such as 640 W solar panels, a wind turbine, an inverter, storage based on batteries and an HVAC.It also includes a smart meter to measure the amount of energy that is consumed from the grid, or injected to them.Some of these elements are shown in Figure 1  The most interesting characteristic of this microgrid is that it is not composed only of power devices, but also includes multiple temperature and humidity sensors deployed into the lab room and on the outside.This allows getting complete datasets that can be used for optimization of HVAC systems, taking into account how wall temperatures affect the comfort of the room.
The availability of batteries will give extra flexibility to the EMS, but it could also be possible to design other types of controls without them, as can be seen in [37].This is why this building constitutes the perfect environment for the application of an energy management system (EMS) and to analyze its thermal behavior depending on the weather.In this first proof of concept the EMS monitories the external, internal and walls (of the microgrid room) temperature, while the whole thermal model of the building has been designed, using the real data of every room and materials that compose it.Using this model, it is possible to observe an approximation of the temperature profile during every day using real weather data (temperature and solar irradiation).

Energy Fluxes
As it was explained before, the proposed EMS need to manage the consumption and generation of the systems connected to the microgrid and also the implied temperatures.This means that the objective is to achieve a complete integration of both types of energy fluxes: electric and thermal.The idea of considering thermal inertia and thermal storage has been previously used by other authors.An example would be [38], who study the impact of this inertia and how could affect demand response operations.
This scheme is shown in Figure 2. On one hand, the elements which exchange electric energy are wind/solar generation, energy storage, utility grid and load.On the other hand, the elements which exchange thermal energy are HVAC, the room and the thermal storage (the mass of the building).These two ambits are supervised by the EMS.
Additionally, in the case of an advanced building-utility integration, must be considered the exchange of information between the utility and the microgrid, focused on DR and energy price information, which allow a better adjustment of the consumption according to the needs of the power In this line, the main contribution of the present work (being carried out with the support and cooperation of ENEL) is the application of homeostatic control strategies for power management (PM) and energy management systems (EMS), which also considers the thermal behavior of the building to improve the utility-customer cooperation.This control system has been simulated extensively and has been connected to a model of a real microgrid in operation with full data integration capability.Thanks to this, it is possible to make a more accurate control adjustment of parameters applying different use cases.
The smart microgrid to be controlled and managed by ENEL contains multiple systems, such as 640 W solar panels, a wind turbine, an inverter, storage based on batteries and an HVAC.It also includes a smart meter to measure the amount of energy that is consumed from the grid, or injected to them.Some of these elements are shown in Figure 1 below.
The most interesting characteristic of this microgrid is that it is not composed only of power devices, but also includes multiple temperature and humidity sensors deployed into the lab room and on the outside.This allows getting complete datasets that can be used for optimization of HVAC systems, taking into account how wall temperatures affect the comfort of the room.
The availability of batteries will give extra flexibility to the EMS, but it could also be possible to design other types of controls without them, as can be seen in [37].This is why this building constitutes the perfect environment for the application of an energy management system (EMS) and to analyze its thermal behavior depending on the weather.In this first proof of concept the EMS monitories the external, internal and walls (of the microgrid room) temperature, while the whole thermal model of the building has been designed, using the real data of every room and materials that compose it.Using this model, it is possible to observe an approximation of the temperature profile during every day using real weather data (temperature and solar irradiation).

Energy Fluxes
As it was explained before, the proposed EMS need to manage the consumption and generation of the systems connected to the microgrid and also the implied temperatures.This means that the objective is to achieve a complete integration of both types of energy fluxes: electric and thermal.The idea of considering thermal inertia and thermal storage has been previously used by other authors.An example would be [38], who study the impact of this inertia and how could affect demand response operations.This scheme is shown in Figure 2. On one hand, the elements which exchange electric energy are wind/solar generation, energy storage, utility grid and load.On the other hand, the elements which exchange thermal energy are HVAC, the room and the thermal storage (the mass of the building).These two ambits are supervised by the EMS.
Energies 2019, 12, x FOR PEER REVIEW 8 of 20 system, making its management by the distribution system operator easier.These functions seem to be an unavoidable part to get a more reliable electricity system.Following the described principles, the scheme of the installation, taking into account all of the devices, can be seen in Figure 3.The core of this installation is the Solar Inverter, which is able to connect the DC energy parts (local generation and batteries) with the AC energy section (utility grid and loads).The next step to complete the integration between these fluxes and the EMS is identifying the relationship between the mentioned fluxes and the reactive/predictive homeostatic functions, i.e., the control system must be developed to assign every control variable to its adequate reactive/predictive ambit.This task will be explained later in the homeostatic control section.Before Additionally, in the case of an advanced building-utility integration, must be considered the exchange of information between the utility and the microgrid, focused on DR and energy price information, which allow a better adjustment of the consumption according to the needs of the power system, making its management by the distribution system operator easier.These functions seem to be an unavoidable part to get a more reliable electricity system.
Following the described principles, the scheme of the installation, taking into account all of the devices, can be seen in Figure 3.The core of this installation is the Solar Inverter, which is able to connect the DC energy parts (local generation and batteries) with the AC energy section (utility grid and loads).system, making its management by the distribution system operator easier.These functions seem to be an unavoidable part to get a more reliable electricity system.Following the described principles, the scheme of the installation, taking into account all of the devices, can be seen in Figure 3.The core of this installation is the Solar Inverter, which is able to connect the DC energy parts (local generation and batteries) with the AC energy section (utility grid and loads).The next step to complete the integration between these fluxes and the EMS is identifying the relationship between the mentioned fluxes and the reactive/predictive homeostatic functions, i.e., the control system must be developed to assign every control variable to its adequate reactive/predictive ambit.This task will be explained later in the homeostatic control section.Before The next step to complete the integration between these fluxes and the EMS is identifying the relationship between the mentioned fluxes and the reactive/predictive homeostatic functions, i.e., the control system must be developed to assign every control variable to its adequate reactive/predictive ambit.This task will be explained later in the homeostatic control section.Before this step, creating the simulation models is necessary in order to get which control variables are implied in the EMS.This is explained in the next section.

Simulation Model
The objective of the work described in this paper is the creation of a simulation model of the microgrid lab and the control system to show how a homeostatic-based EMS can be applied and how it must be adjusted.This simulation must include thermal, power and control modelling.
The selected tool to its implementation was MATLAB Simulink (version R2017a, The MathWorks, Inc, Natick, MA, USA), due to its wide use in research and multiple available possibilities, and TRNSYS (version 17, Thermal Energy System Specialists, LLC, Madison, WI, USA) for the thermal modelling.TRNSYS is also used for research purposes when modelling buildings and HVAC systems, as in [39].

The Power and Energy Management Model by Means of Energy Homeostaticity
The power model can be seen in Figure 4.It simulates how generated energy (solar panels and wind turbine) is injected to the solar inverter, which passes it to batteries, or to feed loads.These fluxes depend on the state of charge of batteries and the orders given by control system (which can decide the percentage of charge that batteries must kept, when possible).
Energies 2019, 12, x FOR PEER REVIEW 9 of 20 this step, creating the simulation models is necessary in order to get which control variables are implied in the EMS.This is explained in the next section.

Simulation Model
The objective of the work described in this paper is the creation of a simulation model of the microgrid lab and the control system to show how a homeostatic-based EMS can be applied and how it must be adjusted.This simulation must include thermal, power and control modelling.
The selected tool to its implementation was MATLAB Simulink (version R2017a, The MathWorks, Inc, Natick, MA, USA), due to its wide use in research and multiple available possibilities, and TRNSYS (version 17, Thermal Energy System Specialists, LLC, Madison, WI, USA) for the thermal modelling.TRNSYS is also used for research purposes when modelling buildings and HVAC systems, as in [39].

The Power and Energy Management Model by Means of Energy Homeostaticity
The power model can be seen in Figure 4.It simulates how generated energy (solar panels and wind turbine) is injected to the solar inverter, which passes it to batteries, or to feed loads.These fluxes depend on the state of charge of batteries and the orders given by control system (which can decide the percentage of charge that batteries must kept, when possible).The block "Solar+MPPT" gives the total power generated by solar panels following the maximum power point tracking (MPPT) of Figure 5 depending on solar irradiance and outside temperature, which are obtained from meteorological data to perform the simulation.
The block "Solar Hybrid System" is the inverter, which connects the solar/wind generation, batteries and utility grid.It must be noted that this inverter is not completely manageable.Therefore, it is not possible to dynamically change the modes of priority (between keeping battery charge, consuming from the utility, etc.).This is a fixed characteristic of the used inverter, so the control system cannot change it easily.Due to this circumstance, the applied solution is to install a more complex battery charge circuit that allows one to select which group of batteries is charged/discharged or disconnected.In this way, the EMS will be able to keep the desired state of charge (SoC).Additionally, this microgrid needs a global switch that permits the connecting and disconnecting of the microgrid from the utility grid.Using these two subsystems, the EMS will be completely capable of achieving the described homeostatic control over the whole system, even with the limitations of the inverter.The block "Solar+MPPT" gives the total power generated by solar panels following the maximum power point tracking (MPPT) of Figure 5 depending on solar irradiance and outside temperature, which are obtained from meteorological data to perform the simulation.
The block "Solar Hybrid System" is the inverter, which connects the solar/wind generation, batteries and utility grid.It must be noted that this inverter is not completely manageable.Therefore, it is not possible to dynamically change the modes of priority (between keeping battery charge, consuming from the utility, etc.).This is a fixed characteristic of the used inverter, so the control system cannot change it easily.Due to this circumstance, the applied solution is to install a more complex battery charge circuit that allows one to select which group of batteries is charged/discharged or disconnected.In this way, the EMS will be able to keep the desired state of charge (SoC).Additionally, this microgrid needs a global switch that permits the connecting and disconnecting of the microgrid from the utility grid.Using these two subsystems, the EMS will be completely capable of achieving the described homeostatic control over the whole system, even with the limitations of the inverter.As previously mentioned, the total battery capacity has to be easily manageable to be charged/discharged when necessary.This task will be accomplished by a DC/DC converter, which allows the use of every connected battery independently from the others.To translate this structure to the EMS, only two logical groups will be considered: back up batteries (BU) and storage batteries (ST).This means that the first group will always be connected to the inverter, to serve as a backup in case a blackout occurs.The ST group has the mission of storing energy, but they can be connected or disconnected by the EMS to keep a certain desired SoC.
The block "Pnet total" calculates the total power consumption/injection.Its output ("pnettotal") will be one of the main control variables because it is directly related with the power consumption limit of the microgrid.
Therefore, three binary control signals can be found in this model.The signal "contactHVAC" means that the HVAC system must be turned on.The signal "contactongrid" means that the microgrid is connected (when its value is 1) or disconnected (when its value is 0) from the utility grid.Finally, the "contactBat" signal orders the connection or disconnection of the ST batteries group to the inverter.

Thermal Model
As previously explained, multiple sensors were deployed to get data about temperature, humidity and others.
The distribution of temperature sensors inside the laboratory can be seen in the Figure 6.There are four sensors for the walls, four in the center of the room, at different heights and a humidity sensor in the center.In the outside, it is possible to measure the air temperature and the solar irradiation, which is useful to estimate the generation of solar panels.As previously mentioned, the total battery capacity has to be easily manageable to be charged/discharged when necessary.This task will be accomplished by a DC/DC converter, which allows the use of every connected battery independently from the others.To translate this structure to the EMS, only two logical groups will be considered: back up batteries (BU) and storage batteries (ST).This means that the first group will always be connected to the inverter, to serve as a backup in case a blackout occurs.The ST group has the mission of storing energy, but they can be connected or disconnected by the EMS to keep a certain desired SoC.
The block "Pnet total" calculates the total power consumption/injection.Its output ("pnettotal") will be one of the main control variables because it is directly related with the power consumption limit of the microgrid.
Therefore, three binary control signals can be found in this model.The signal "contactHVAC" means that the HVAC system must be turned on.The signal "contactongrid" means that the microgrid is connected (when its value is 1) or disconnected (when its value is 0) from the utility grid.Finally, the "contactBat" signal orders the connection or disconnection of the ST batteries group to the inverter.

Thermal Model
As previously explained, multiple sensors were deployed to get data about temperature, humidity and others.
The distribution of temperature sensors inside the laboratory can be seen in the Figure 6.There are four sensors for the walls, four in the center of the room, at different heights and a humidity sensor in the center.In the outside, it is possible to measure the air temperature and the solar irradiation, which is useful to estimate the generation of solar panels.As previously mentioned, the total battery capacity has to be easily manageable to be charged/discharged when necessary.This task will be accomplished by a DC/DC converter, which allows the use of every connected battery independently from the others.To translate this structure to the EMS, only two logical groups will be considered: back up batteries (BU) and storage batteries (ST).This means that the first group will always be connected to the inverter, to serve as a backup in case a blackout occurs.The ST group has the mission of storing energy, but they can be connected or disconnected by the EMS to keep a certain desired SoC.
The block "Pnet total" calculates the total power consumption/injection.Its output ("pnettotal") will be one of the main control variables because it is directly related with the power consumption limit of the microgrid.
Therefore, three binary control signals can be found in this model.The signal "contactHVAC" means that the HVAC system must be turned on.The signal "contactongrid" means that the microgrid is connected (when its value is 1) or disconnected (when its value is 0) from the utility grid.Finally, the "contactBat" signal orders the connection or disconnection of the ST batteries group to the inverter.

Thermal Model
As previously explained, multiple sensors were deployed to get data about temperature, humidity and others.
The distribution of temperature sensors inside the laboratory can be seen in the Figure 6.There are four sensors for the walls, four in the center of the room, at different heights and a humidity sensor in the center.In the outside, it is possible to measure the air temperature and the solar irradiation, which is useful to estimate the generation of solar panels.Thanks to these sensors, a set of real data was obtained, which are used to train the thermal model and estimate the solar generation.Specifically, as an example, the period from February 17th 2018 to February 25th 2018 can be observed in Figure 7 (temperatures of outside/inside air and two of the walls) and Figure 8 (solar irradiance).Thanks to these sensors, a set of real data was obtained, which are used to train the thermal model and estimate the solar generation.Specifically, as an example, the period from February 17th 2018 to February 25th 2018 can be observed in Figure 7 (temperatures of outside/inside air and two of the walls) and Figure 8 (solar irradiance).These datasets have been used to make a complete thermal model of the laboratory building, obtaining an approximated model of how temperatures change.
This task was completed using the software TRNSYS, which creates the model using multiple variables.As seen in Figure 9, real datasets of inside/outside temperatures (block Type9c-2) feed the building block in order to adjust its internal parameters.Thanks to these sensors, a set of real data was obtained, which are used to train the thermal model and estimate the solar generation.Specifically, as an example, the period from February 17th 2018 to February 25th 2018 can be observed in Figure 7 (temperatures of outside/inside air and two of the walls) and Figure 8 (solar irradiance).These datasets have been used to make a complete thermal model of the laboratory building, obtaining an approximated model of how temperatures change.
This task was completed using the software TRNSYS, which creates the model using multiple variables.As seen in Figure 9, real datasets of inside/outside temperatures (block Type9c-2) feed the building block in order to adjust its internal parameters.These datasets have been used to make a complete thermal model of the laboratory building, obtaining an approximated model of how temperatures change.
This task was completed using the software TRNSYS, which creates the model using multiple variables.As seen in Figure 9, real datasets of inside/outside temperatures (block Type9c-2) feed the building block in order to adjust its internal parameters.This model considers not only the microgrid room, but also the other parts of the building (geometry, topology and material characteristics), using TRNBuild.
An example of temperature evolution using the obtained model using real outside temperatures (as inputs) can be seen in Figure 10.Wall temperatures are obtained as simulation outputs.
This model shows the concept of thermal inertia, which accounts for the change in wall temperatures exhibiting a time fluctuation when compared with the outside temperature and also a reduction in the total amplitude.This effect depends on the geometry and material of the building.In this case, is has a notable effect, therefore it should be taken into account.This behavior can be exploited in order to maintain adequate internal conditions in the rooms (accumulating thermal energy, hot or cold), which raises thermal efficiency and thus exergy.

Control Block
The control block has a series of interfaces.Inputs correspond to measured variables and signals from the system, while outputs correspond to "orders", that the system can accept.These inputs and outputs are listed in Table 1.This model considers not only the microgrid room, but also the other parts of the building (geometry, topology and material characteristics), using TRNBuild.
An example of temperature evolution using the obtained model using real outside temperatures (as inputs) can be seen in Figure 10.Wall temperatures are obtained as simulation outputs.This model considers not only the microgrid room, but also the other parts of the building (geometry, topology and material characteristics), using TRNBuild.
An example of temperature evolution using the obtained model using real outside temperatures (as inputs) can be seen in Figure 10.Wall temperatures are obtained as simulation outputs.
This model shows the concept of thermal inertia, which accounts for the change in wall temperatures exhibiting a time fluctuation when compared with the outside temperature and also a reduction in the total amplitude.This effect depends on the geometry and material of the building.In this case, is has a notable effect, therefore it should be taken into account.This behavior can be exploited in order to maintain adequate internal conditions in the rooms (accumulating thermal energy, hot or cold), which raises thermal efficiency and thus exergy.

Control Block
The control block has a series of interfaces.Inputs correspond to measured variables and signals from the system, while outputs correspond to "orders", that the system can accept.These inputs and outputs are listed in Table 1.This model shows the concept of thermal inertia, which accounts for the change in wall temperatures exhibiting a time fluctuation when compared with the outside temperature and also a reduction in the total amplitude.This effect depends on the geometry and material of the building.In this case, is has a notable effect, therefore it should be taken into account.
This behavior can be exploited in order to maintain adequate internal conditions in the rooms (accumulating thermal energy, hot or cold), which raises thermal efficiency and thus exergy.

Control Block
The control block has a series of interfaces.Inputs correspond to measured variables and signals from the system, while outputs correspond to "orders", that the system can accept.These inputs and outputs are listed in Table 1.This control block executes an intelligent algorithm based on homeostatic principles applied over selected variables.The result of this algorithm will be the control commands being sent to the power systems in order to generate the appropriate response under particular conditions and circumstances of operation throughout the day.

Homeostatic Control
As it was explained before, the homeostatic control system which makes the energy homeostaticity scheme possible, comprises of two different parts, reactive and predictive homeostasis.In this sense, the flow diagram for the proposed homeostatic control can be seen in Figure 11.
The predictive branch, which is divided into two separated parts, are mainly centered in the use of the thermal model of the room to keep the temperatures at adequate intervals.It must be noted that this function would take on more and more importance when the building has more mass (which implies more thermal energy storage) and also when the thermal isolation with the outside is better (which implies less losses), having then more thermal inertia and having his management more impact in the total consumption of the building.Following this idea, the temperature inside a room for the next hour will be obtained from the thermal model: The reactive branch, which conforms the core of the control system, must keep the batteries with enough charge to maintain the microgrid running, even if a blackout occurs.Additionally, the storage capacity can be used to actuate when the utility advice a high energy price (usually applied when a certain power or energy consumption value is reached), or even a DR event which requires a high reduction in the consumption of the microgrid.This fact is reflected with the parameter Plim (power limit), which depends on the received information from the utility (or the distribution system operator).The minimum or maximum level of battery charge depends on the characteristics of the event (the time in which the maximum power consumption from the grid is limited) the expected consumption, and the estimation of solar generation that could be obtained for the period (in order to assure that all that generated energy will be consumed, or stored).
The calculation of the limit power in the context of a typical DR event (of the type used by some utilities in North America [40]), is usually dependent on two variables, the client baseline for the event time and the minimum power reduction needed to avoid penalties.For the calculation of the baseline for every hour (or other time period needed), the mean of the ten previous days which are similar to the day of the event (e.g., laborable day) can be used: Energies 2019, 12, 1806 14 of 19 of course, this depend on the type of DR program and contract stablished between utility and customer (or aggregator).Following this idea, the power limit will be calculated applying the minimum power reduction needed to the baseline power: or, if the power reduction required is zero (penalties to the customer would only be applied if they consume more than their baseline): Last, if during a specific period there is not any event active, then the power limit will not be necessary (no power restriction specified).
The required power reduction can be reached by disconnecting the microgrid from the power system, or also managing internal controllable loads available).In both cases, the control system must assure that the required reduction is achieved, when possible. of course, this depend on the type of DR program and contract stablished between utility and customer (or aggregator).Following this idea, the power limit will be calculated applying the minimum power reduction needed to the baseline power: or, if the power reduction required is zero (penalties to the customer would only be applied if they consume more than their baseline): Last, if during a specific period there is not any event active, then the power limit will not be necessary (no power restriction specified).
The required power reduction can be reached by disconnecting the microgrid from the power system, or also managing internal controllable loads (if available).In both cases, the control system must assure that the required reduction is achieved, when possible.Therefore, this diagram clearly distinguishes between "predictive" and "reactive" control perspectives, which are explained in [32], to keep all the system variables in adequate value ranges.To summarize, in this case study, reactive control is related with direct energy flows management, such as when the battery must be charged or discharged.On the other hand, predictive control is directly related with the estimated temperature for the room, based on real measurements.

Results
From the point of view of the results, two main aspects must be taken into account.On the one hand, the integration and use of DER.This proof of concept only includes two solar panels, whose generation has been estimated.As an example, the estimation for each hour during the period from February 17th 2018 to February 25th 2018 can be observed in Figure 12.The mean power obtained for these days (summer days in Chile) is approximately 174 W. Therefore, this diagram clearly distinguishes between "predictive" and "reactive" control perspectives, which are explained in [32], to keep all the system variables in adequate value ranges.To summarize, in this case study, reactive control is related with direct energy flows management, such as when the battery must be charged or discharged.On the other hand, predictive control is directly related with the estimated temperature for the room, based on real measurements.

Results
From the point of view of the results, two main aspects must be taken into account.On the one hand, the integration and use of DER.This proof of concept only includes two solar panels, whose generation has been estimated.As an example, the estimation for each hour during the period from February 17th 2018 to February 25th 2018 can be observed in Figure 12.The mean power obtained for these days (summer days in Chile) is approximately 174 W. On the other hand, the main purpose of this system is to allow a better integration of the local system (the microgrid) with the utility, which is done through a more controllable power system using the homeostatic control system.In this line, an example of results obtained from the simulation can be seen in Figure 13, where all the powers implied in the microgrid can be seen.The first blackout event has been considered, as can be seen when the line "Utility" drops to zero (between 8:57 and 11:26).After that, between 18:00 and 23:00 a high-price event has been considered, this is why the microgrid is automatically disconnected from the utility grid, causing consumption to drop to zero again.During these events, the control system connects the batteries, whose charge feeds the whole system.While the utility grid is available, the batteries are being charged, albeit without exceeding the maximum power consumption that the control system establishes as a limit.For the described situation, the Figure 14 shows how the batteries SoC change during the day.On the other hand, the main purpose of this system is to allow a better integration of the local system (the microgrid) with the utility, which is done through a more controllable power system using the homeostatic control system.In this line, an example of results obtained from the simulation can be seen in Figure 13, where all the powers implied in the microgrid can be seen.The first blackout event has been considered, as can be seen when the line "Utility" drops to zero (between 8:57 and 11:26).After that, between 18:00 and 23:00 a high-price event has been considered, this is why the microgrid is automatically disconnected from the utility grid, causing consumption to drop to zero again.During these events, the control system connects the batteries, whose charge feeds the whole system.While the utility grid is available, the batteries are being charged, albeit without exceeding the maximum power consumption that the control system establishes as a limit.For the described situation, the Figure 14 shows how the batteries SoC change during the day.
Of course, other types of events could also be applied to study different cases dealing with the use of energy under various conditions and circumstances, even considering demand response programs.This is part of several cutting edge smart grid concepts and technology trends being advanced by ENEL Distribution's Smartcity Santiago in Santiago, Chile [12], and it is conceived as a system that integrates state-of-the-art technologies to optimize the production of energy and its intelligent use in the functions of an urban laboratory, much in the same way that the microgrid installed in the Lab at Universidad Técnica Federico Santa María's San Joaquin campus operates, such as lighting, HVAC, energy distribution, citizen security and communication system.Of course, other types of events could also be applied to study different cases dealing with the use of energy under various conditions and circumstances, even considering demand response programs.This is part of several cutting edge smart grid concepts and technology trends being advanced by ENEL Distribution's Smartcity Santiago in Santiago, Chile [12], and it is conceived as a system that integrates state-of-the-art technologies to optimize the production of energy and its intelligent use in the functions of an urban laboratory, much in the same way that the microgrid installed in the Lab at Universidad Técnica Federico Santa María's San Joaquin campus operates, such as lighting, HVAC, energy distribution, citizen security and communication system.

Discussion
The decentralization of the power system using distributed generation (DG) solutions like the smart microgrid for buildings, and to be managed and operated by utilities like ENEL Distribution Chile (formerly Chilectra), employing both traditional and renewable power sources (like micro-turbines and solar/wind generation) makes sense.Furthermore, if these systems can be equipped with communication and advanced data processing interconnected systems that can operate together, making the power generation and distribution elements work in a collaborative way.This structure can be managed by more flexible, less expensive, faster, and more reliable control systems instead of other complex systems (e.g., multi-agent, or expert systems) that much of the current literature on smart grid and intelligent computing is proposing."At least for smart microgrids to supply electricity and also heat using combined heat and power (CHP) as a generation alternative for cases in which a natural disaster strikes, leaving a whole neighbourhood without power, a simpler, more flexible, economical and modular control solution is possible" [32].Of course, other types of events could also be applied to study different cases dealing with the use of energy under various conditions and circumstances, even considering demand response programs.This is part of several cutting edge smart grid concepts and technology trends being advanced by ENEL Distribution's Smartcity Santiago in Santiago, Chile [12], and it is conceived as a system that integrates state-of-the-art technologies to optimize the production of energy and its intelligent use in the functions of an urban laboratory, much in the same way that the microgrid installed in the Lab at Universidad Técnica Federico Santa María's San Joaquin campus operates, such as lighting, HVAC, energy distribution, citizen security and communication system.

Discussion
The decentralization of the power system using distributed generation (DG) solutions like the smart microgrid for buildings, and to be managed and operated by utilities like ENEL Distribution Chile (formerly Chilectra), employing both traditional and renewable power sources (like micro-turbines and solar/wind generation) makes sense.Furthermore, if these systems can be equipped with communication and advanced data processing interconnected systems that can operate together, making the power generation and distribution elements work in a collaborative way.This structure can be managed by more flexible, less expensive, faster, and more reliable control systems instead of other complex systems (e.g., multi-agent, or expert systems) that much of the current literature on smart grid and intelligent computing is proposing."At least for smart microgrids to supply electricity and also heat using combined heat and power (CHP) as a generation alternative for cases in which a natural disaster strikes, leaving a whole neighbourhood without power, a simpler, more flexible, economical and modular control solution is possible" [32].

Discussion
The decentralization of the power system using distributed generation (DG) solutions like the smart microgrid for buildings, and to be managed and operated by utilities like ENEL Distribution Chile (formerly Chilectra), employing both traditional and renewable power sources (like micro-turbines and solar/wind generation) makes sense.Furthermore, if these systems can be equipped with communication and advanced data processing interconnected systems that can operate together, making the power generation and distribution elements work in a collaborative way.This structure can be managed by more flexible, less expensive, faster, and more reliable control systems instead of other complex systems (e.g., multi-agent, or expert systems) that much of the current literature on smart grid and intelligent computing is proposing."At least for smart microgrids to supply electricity and also heat using combined heat and power (CHP) as a generation alternative for cases in which a natural disaster strikes, leaving a whole neighbourhood without power, a simpler, more flexible, economical and modular control solution is possible" [32].
The research project being supported by ENEL Chile under FONDECYT Postdoctoral Project Nº 3170399, considers a microgrid tied to the grid and installed in a residential or a commercial building serviced by ENEL Distribution in Santiago, Chile.The HC strategies that employ RH and PH are termed energy homeostaticity, which in turn allows the entire energy system of the building and its individual subsystems to reach optimal performance and productivity levels when compared to traditional building energy consumption environments, while simultaneously boosting energy efficiency and exergy.The result is a power control system and EMS that simplify the overall energy management of the building while making it more efficient and nimble, even when considering the thermal model system.

Conclusions
The present paper offers a view and a use case of microgrid control, using mechanisms based on reactive and predictive homeostasis.Specifically, the results obtained show how homeostatic control (HC) can be used over a real microgrid, operating in a university campus environment that works as a Lab to study reactive homeostasis (RH) and predictive homeostasis (PH) applications for distributed hybrid energy systems to be incorporated to the electric power distribution industry.
The simulation includes three distinct parts: thermal behavior, electric system, and the control block.The thermal behavior has been modelled using the software TRNSYS, which creates a complex model using multiple building variables, including its shape and size.This model shows how thermal inertia affects the relationship between external and internal temperature through walls.
The electric system and the control block have been modelled over Matlab Simulink and includes the model of solar generation (using real irradiation data of the city of Santiago), wind generation, batteries and loads.The control block executes the described flow diagram to manage all the available actions: connect/disconnect batteries, connect/disconnect the microgrid from the utility grid and power on/off the HVAC system.This simulation gives information that can be used to make a better adjustment to the control block parameters depending on the operation conditions, overall aim and system scope, the characteristics of the microgrid itself, and its consumption profile and baseline.
The future task in this research line would imply the installation of certain channels for information exchange between utility and customer.This can be implemented using specific demand response protocols, such as the OpenADR, which is promoted by EPRI.The consideration of this total integration with the utility really connect with the idea of including the utilities perspective into the changing power system environment, as can be seen in the actions of ENEL in the mentioned project.
Energy efficiency in all of its forms contributes to improving the quality of life of people everywhere, lowering the carbon footprint and optimizing production processes while, at the same time, allowing a greater number of activities with the lowest possible energy consumption to take place.That is why it is so important to try to achieve higher levels of energy efficiency, especially in a country like Chile, where the average building consumes three times more energy than its counterparts in developed countries like the US, the UK or Germany.It is imperative that Chile advances in this effort to achieve higher energy efficiency standards homologous to its OCDE partners.

Figure 6 .
Figure 6.Temperature sensors deployed into the laboratory room.

Figure 6 .
Figure 6.Temperature sensors deployed into the laboratory room.

Figure 6 .
Figure 6.Temperature sensors deployed into the laboratory room.

Figure 9 .
Figure 9. Detail of building block in TRNSYS simulation.

Figure 9 .
Figure 9. Detail of building block in TRNSYS simulation.

Figure 14 .
Figure 14.State of charge of batteries.

Figure 14 .
Figure 14.State of charge of batteries.

Figure 14 .
Figure 14.State of charge of batteries.