Multi-Objective Fuzzy Logic-Based Energy Management System for Microgrids with Battery and Hydrogen Energy Storage System

This paper proposes a fuzzy logic-based energy management system (EMS) for microgrids with a combined battery and hydrogen energy storage system (ESS), which ensures the power balance according to the load demand at the time that it takes into account the improvement of the microgrid performance from a technical and economic point of view. As is known, renewable energy-based microgrids are receiving increasing interest in the research community, since they play a key role in the challenge of designing the next energy transition model. The integration of ESSs allows the absorption of the energy surplus in the microgrid to ensure power supply if the renewable resource is insufficient and the microgrid is isolated. If the microgrid can be connected to the main power grid, the freedom degrees increase and this allows, among other things, diminishment of the ESS size. Planning the operation of renewable sources-based microgrids requires both an efficient dispatching management between the available and the demanded energy and a reliable forecasting tool. The developed EMS is based on a fuzzy logic controller (FLC), which presents different advantages regarding other controllers: It is not necessary to know the model of the plant, and the linguistic rules that make up its inference engine are easily interpretable. These rules can incorporate expert knowledge, which simplifies the microgrid management, generally complex. The developed EMS has been subjected to a stress test that has demonstrated its excellent behavior. For that, a residential-type profile in an actual microgrid has been used. The developed fuzzy logic-based EMS, in addition to responding to the required load demand, can meet both technical (to prolong the devices’ lifespan) and economic (seeking the highest profitability and efficiency) established criteria, which can be introduced by the expert depending on the microgrid characteristic and profile demand to accomplish.


Introduction
Renewable energy-based microgrids are receiving increasing interest in the research community, since they play a key role in the challenge of designing the next energy transition model [1]. However, the stochastic character exhibited by the most important renewable energy sources (RES), such as photovoltaic (PV) and wind, represents a huge disadvantage for the stability, security, and reliability of microgrids. To solve this problem, the integration of energy storage systems (ESS) is required to has attracted a lot of interest towards the field of renewable energy systems, since linguistic rules can simplify the control of these complex systems [29]. By this kind of fuzzy control system, the part-load operation of hydrogen-based systems like fuel cells [29,30] and electrolyzers [31] is technically feasible. For all these devices, the efficiency is increased by part-load operation, so it is expected that the microgrid will become more efficient.
Based on the literature review, fuzzy logic can be used not only in the development of the microgrid EMS, but also in the definition of protection strategies and the establishment of decision rules. Based on this, Bukhariet et al. [32] developed two different fuzzy systems to detect, classify, and locate the faults in microgrids, and Oliveira et al. [10] proposed a fuzzy-based methodology approach for microgrids under an islanded operation that aimed to maximize the number of supplied customers during a minimum period of time.
Regarding the scientific works that propose EMS based on fuzzy logic controllers, in [33] the stochastic nature of the solar energy collection was handled by the fuzzy logic system, which provides continuous control conditions, instead of direct digital control, where the boundaries are discontinuous.
On the other hand, Kamel et al. presented recently in [34] a comparative study to validate the results of the classic PI control with the results of a fuzzy control system. The controller must establish the fuel cell current reference on the basis of three input signals: the load power, PV power, and battery SOC. It is a simple controller that consists of eight fuzzy rules, and although the authors confirmed the PI controller is easier for implementation, they recognize future research should be focused on improving the system with regard to cost optimization.
In spite of the simplicity of these solutions, the non-use of optimization parameters based on equipment degradation, operation modes, or operating costs of the microgrid causes an inefficient solution from a technical and economic point of view.
On the other hand, technical criteria were included in the fuzzy logic-based EMS presented by Zhang et al. in [17]. The target was to use solar power to meet the power demand and the surplus to maximize the hydrogen production. This allowed for minimizing the usage of battery and therefore the overall microgrid's efficiency increased, and the battery lifespan was prolonged.
Fuzzy logic-based EMSs that include economic parameters can help to determine an optimal solution from an economic point of view. Thereby, El-Bidairi et al. proposed in [35] a multi-objective optimization technique for stand-alone microgrids which determines the optimal power generation scheduling and selects the optimal capacity of the ESSs with minimal operational cost. In this same line, the objective of the study carried out in [18] was to examine the effects of time-varying electricity prices on the performance of ESS for a grid-tied microgrid utilizing an optimized fuzzy logic controller (FLC). However, these economic solutions, with more global goals, do not determine a favorable operation for the involved devices due to not having enough technical criteria to avoid problems associated with different operating regimes.
Based on the above, the main contribution of this paper is the proposal of a multi-objective fuzzy logic-based EMS with Mandani-type structure and inference, for microgrids with combined battery-and-hydrogen ESS, which ensures the power balance according to the load demand, taking into account the improvement of microgrid performance from technical and economic points of view. The fuzzy logic approach is chosen since linguistic rules are interpretable and they can incorporate the knowledge that an expert has of the microgrid, which can simplify the management and control of it, given its complexity. In fact, the developed FLC combines the microgrid knowledge from experts and collected data to define the fuzzy rule bases. Then, the developed FLC, in addition to responding to the load demand, can meet both technical criteria (to prolong the devices' lifespan) and economic criteria (to reduce the electricity purchased from the main power grid and to improve the trade and profitability of the sale/purchase of energy). Additionally, the developed FLC considers the power balance forecast. In this case, the prediction model used to obtain the solar generation profile is based on the use of a multilayer neural network, and the demand profile model is based on a specific consumption profile proposed for a residential type application. Therefore, knowing the models of renewable production Electronics 2020, 9, 1074 4 of 23 and consumption profile, the power balance in the following sampling period can be calculated as the difference between both terms.
To highlight the novelty of the research, Table 1 summarizes the main characteristics of the authors' proposal in comparison with revised literature. This paper is organized as follows: Section 2 describes all the facilities, devices, and software that have been used to carry out the research. Section 3 develops step by step the fuzzy logic-based EMS, which will be further tested in Section 4. The results are discussed in Section 5, highlighting the principal aspects regarding the EMS functioning. Finally, in Section 6 the principal conclusions of the research are addressed.

Materials and Methods
The microgrid used to test the developed EMS is shown in Figure 1, found at the Spanish Institute of Aerospace Technology, (Spanish acronym: INTA), and it is based on the use of renewable generation and hybrid ESS based on batteries and hydrogen. The proposed configuration is designed to respond to a residential-type application, in which a bidirectional flow of energy is allowed between the renewable microgrid and the main power grid. This configuration was chosen because it allows the development of different strategies in the field of the electricity market and, in the last instance, to get an end-consumer perspective.
In the microgrid scheme of Figure 1, renewable generation is given by a 5 kW p monocrystalline technology PV field, and the use of associated power electronics to supply to the DC bus the maximum available renewable power. To decrease the current in the microgrid, reducing losses due to parasitic resistances and the sections in cables and printed circuit boards, the microgrid has been designed around a high voltage DC bus (360 VDC).
According to the demand, typical profiles for low-medium power residential applications (<10 kWe) were adopted. Additionally, the load profile associated with the recharging process of a medium-capacity electric vehicle was considered.
Regarding ESS, it is made up of two subsystems, a Li-ion battery bank (43.2 kWh) and a hydrogen system. The lead-acid battery bank (36 kWh) has the function to stabilize the DC bus voltage, therefore the lead-acid battery bank is directly connected to the DC and it will not serve as an energy storage system. This implies that lead-acid battery SOC must always be kept high, avoiding the need for a specific control system. This direct connection of the lead-acid battery bank makes it possible to take advantage of three keys issues: (1) If the lead-acid battery bank was not connected to DC bus, the grid controller would be responsible for regulating the DC bus voltage. This involves a more complex control logic because the grid is responsible for the voltage control and the setting of the operating power of the grid according to the EMS setpoint. This requires a perfect synchronism between the rectifier (energy input to the bus) and the inverter (energy output from the bus) and the rest of the elements of the microgrid, and control dynamic fast enough to guarantee the stability of the bus voltage under fast changes in generation/consumption profile. (2) The use of the lead-acid battery bank as a backup system ensures that the DC bus voltage is maintained within a known operating range under any circumstances, while guaranteeing the power balance during the transients associated with the switching on and off of the rest of the equipment, mainly the hydrogen system. In this way, the equipment linked to grid operation, rectifier, and inverter only have the function of imposing the power setpoint established by the EMS, greatly reducing the associated control complexity. Finally, (3) the battery bank can act as a short/medium-term storage system, and therefore a further degree of freedom in energy management definition is available.
With respect to the ESS, the objective of the Li-ion battery bank is to act as a short-medium-term storage system, allowing a considerably lower SOC than the lead-acid battery bank, and taking advantage of its high cycle durability. As a long-term ESS, a hydrogen system is used. In this case, a circular system, which allows the generation of hydrogen by an alkaline electrolyzer (1 Nm 3 /h, 5 kWe), its subsequent storage in a pressurized tank (1.044 Nm 3 ) at the hydrogen outlet pressure of the electrolyzer (30 bar), and the further generation of electrical energy through the use of a polymer electrolyte membrane (PEM) fuel cell (3 kW p ).
A real image of each microgrid component is shown in Figure 2, and their main technical characteristics are collected in Table 2.
As is widely known, a fuzzy logic-based controller has the advantage to manage the microgrid without the need of having a model of the microgrid. Obviously, the microgrid model will be necessary to test and fine-tune the developed EMS (if applicable) by simulation before applying it to the actual microgrid. A model of this type of microgrid (hydrogen systems hybridization with renewable energy systems) has been already developed by the authors in previous works [23]. Therefore, the general model only needs to be adapted to the specific microgrid topology in each case. Figure 3 shows the MATLAB ® -Simulink ® microgrid configuration and the fuzzy logic-based EMS implemented in MATLAB ® -Fuzzy Logic Toolbox™ environment.  As is widely known, a fuzzy logic-based controller has the advantage to manage the microgrid without the need of having a model of the microgrid. Obviously, the microgrid model will be necessary to test and fine-tune the developed EMS (if applicable) by simulation before applying it to the actual microgrid. A model of this type of microgrid (hydrogen systems hybridization with renewable energy systems) has been already developed by the authors in previous works [23]. Therefore, the general model only needs to be adapted to the specific microgrid topology in each case. Figure 3 shows the MATLAB® -Simulink® microgrid configuration and the fuzzy logic-based EMS implemented in MATLAB® -Fuzzy Logic Toolbox™ environment.

Energy Management System Design
This section develops the EMS, paying special attention to the FLC. It is assumed that sensors are available to take measurements of the necessary variables, as well as actuators for the control of the power electronics (see Figure 1) that govern the microgrid. None of these elements, parts of the EMS, are the subject of this paper. Next, the FLC design will be explained step by step.

Power Balance on the DC Bus
Based on Figure 1, the Kirchhoff's Current Law always needs to be accomplished, so the power sum in the DC bus must always be zero. If all the loads are satisfied under any circumstance, this means that the main power grid sometimes will be delivering power to the DC bus (power deficit in the microgrid) and others will be extracting power from the microgrid, which will imply energy transfer from the microgrid to the main power grid. In the microgrid shown in Figure 1, the only power source (in a strict sense) is the PV field. The hydrogen storage system, as part of the ESS, can be a source if the fuel cell is running or a load if the electrolyzer is operating. Regarding the Li-ion battery bank as part of the ESS, it depends on whether the battery bank is recharging or supplying power from/to the DC bus. Then, before adopting a signs convention, the sum of the powers on the DC bus follows Equation (1): where: P PV (k): renewable generation (PV panels) at sampling time k (W); P La (k): lead-acid battery bank power at sampling time k (W); P L (k): residential load demand at sampling time k (W); P EV (k): electric vehicle demand at sampling time k (W); P ESS (k): energy storage system power at sampling time k (W); P Grid (k): main power grid power at sampling time k (W). Being, following Figure 1: where: P Li (k): Li-ion battery bank power at sampling time k (W); P H 2 (k): hydrogen system power at sampling time k (W), P H 2 (k) = P Els (k) or P H 2 (k) = P FC (k), where P Els (k) is the electrolyzer power at sampling time k (W) and P FC (k) is the fuel cell power at sampling time k (W).
Again, following Figure 1: where: P GI (k): input power; power supplied from the main power grid at sampling time k (W); P GO (k): output power; power supplied to the main power grid at sampling time k (W). The adopted signs criteria are determined by the direction of the energy flow in the DC bus, considering the energy injected to the DC bus as positive, and the energy extracted from the bus as negative. Depending on the microgrid operation state, the signs of the different powers must assure Equation (1), taking into account Equations (2) and (3) regarding whether the subsystems are injecting to the DC bus or extracting power to/from it. Of course, in a dynamic system as the microgrid of Figure 1, the only way to satisfy Equation (1) is by means of the EMS.

Fuzzy Logic Controller Structure
The fuzzy logic-based EMS proposed in this paper is shown in Figure 4. Note that to elaborate the fuzzy rule base, the FLC input variables have been grouped into two sets, named FLC1 and FLC2. The first makes decisions about the exchange with the main power grid, and the second over the ESS use. This will be explained below. As already said, the only source (in the strict sense) in the microgrid is the PV field, so the power balance must be guaranteed by the ESS and/or the main power grid. Consequently, following the adopted sign criteria, the power balance will be defined by Equation (4), see Figure 1: P bal (k) will be positive when there is energy surplus in the microgrid and negative in case of deficit. In the first case, the surplus energy must be managed by the EMS producing hydrogen and/or recharging batteries and/or selling energy to the main power grid. In the second case, the microgrid power will be balanced taking the power of the batteries, and/or fuel cell and/or the main power grid. So, P bal (k) needs to be an input variable of the FLC. However, the EMS cannot act and verify the results of its action in the same sampling to make the appropriate decisions, so it must have information in advance. Then, for the best EMS functioning, the FLC needs to know the P bal forecasting, so P bal (k + 1) needs to be the other FLC input variable. Although it is not the subject of this document, there is a large bibliography on renewable generation forecasts and consumption profiles.
As was explained in Section 2, and based on Figure 1, the role of the lead-acid battery bank is to regulate the DC bus voltage. Therefore, it does not have tasks related to power management, except the instantaneous ones in the DC bus. So, the lead-acid battery SOC must be always high in order to assure the proper voltage in the DC bus, V bus (k). According to this, the EMS must have information in each sampling about the V bus , so this voltage must be an input variable of the FLC.
Unlike the previous case, the operating voltage of the Li-ion battery bank is not a fundamental parameter in the operation of the microgrid (see Figure 1 to note that the Li-ion battery bank is not Electronics 2020, 9, 1074 9 of 23 directly connected to the DC bus). Its role in the microgrid is its ability to store energy to be used by the microgrid when needed. The EMS needs to know its SOC (SOC Li (k))-consequently, this value must be an input variable of the FLC. Furthermore, since the Li-ion battery bank must effectively contribute to the achievement of Equation (1) delivering/absorbing energy to/from the DC bus, the EMS must decide on its power, P Li (k) and its sign, so this is an FLC output variable.
The last element of the ESS is the hydrogen system. Its availability to deliver power to the DC bus through the fuel cell is given by the level of hydrogen in the storing tank, HL(k); therefore, this need to be another input variable. On the other hand, depending on the energy state in the microgrid, surplus or deficit, the EMS must decide, respectively, to have the electrolyzer operating producing hydrogen or the fuel cell delivering energy to the DC bus. So, P H 2 (k) and its sign (negative for electrolyzer operating or positive in the case of the fuel cell) will be another FLC output variable.
Additionally, since Li-ion battery bank and hydrogen storage subsystem made up the ESS, and they need to work as a whole, it is interesting that the EMS knows the joint possibilities to deliver power to the DC bus. Thus, a new FLC input variable has been created as the average value of SOC Li (k) and HL(k); its name is SOC ESS (k).
So far, the relationships between the internal elements of the microgrid have been described. The way EMS interacts with the main power grid will be explained below. As Figure 4 shows, the FLC decides the utilization of the main power grid based on the actual SOC ESS (k), P bal (k), and the forecasting power of the ESS, P ESS (k + 1), and of the power balance, P bal (k + 1), together with the purchase price, C EP (k), and the sale price, C ES (k), of the electricity. Then, for example, in case there is power deficit and the electricity cost from the main power grid is low and SOC ESS is also low, it will be interesting to use the main power grid to balance the microgrid power and to recharge the ESS. However, if the electricity cost is high, it will be interesting to use the main power grid only for power balancing.
The FLC system schematized in Figure 4 shows that it is a complex multivariable control system with nine inputs and three outputs. Taking into account its structure, the fuzzy inference is defined by two fuzzy rule bases (one for FLC1 and other for FLC2); however, to facilitate the inference logic, FLC1 has been built using two fuzzy rule bases, one for energy surplus situations and another for deficit situations.
Integrated into the EMS, the FLC functions as follows (see Figure 4): In the sampling time k, it receives the real (physical) variables (V bus (k), SOC Li (k), HL(k), P ESS (k), SOC ESS (k), C ES (k), C EP (k), P bal (k) and the predicted P bal (k + 1)). Then, it fuzzifies these variables to convert them in linguistic ones (V bus− f uzz (k), SOC Li− f uzz (k), HL − f uzz (k), SOC ESS− f uzz (k), C ES− f uzz (k), C EP− f uzz (k), P bal− f uzz (k), P bal− f uzz (k + 1)). From here, FLC can use the linguistic variables to make the fuzzy inference, that is, to evaluate the fuzzy rules of each fuzzy rule base, which delivers the output linguistic variables P Li− f uzz (k), P H 2 − f uzz (k), and P ESS− f uzz (k). After that, the FLC makes a defuzzification process to obtain the real output variables of the FLC: P Li (k), P H 2 (k), and P ESS (k) ( Figure 5). Now, these can be used by the EMS in order to act over the microgrid and control it.

Fuzzy Sets
Based on the knowledge of the microgrid and in its operation way already explained in the previous section, the fuzzy sets of Figure 6 have been defined. Due to its simplicity and the fact that the microgrid does not need overly smooth control, fuzzy sets have been defined using triangular membership functions. The universe of discourse of each variable has been decided according to technical characteristics and the microgrid operation, Equation (5). Then, for example, limits of the DC bus voltage (V bus (k)) have been determined using two fundamental criteria, the connected devices permissible operating range (350-450 VDC), as well as the safe operating voltage for the lead-acid battery bank (330-440 VDC), responsible for maintaining the voltage in range on the DC bus. The upper and lower limits are determined by the most limiting condition. In this case, the lower limit is the connected devices' permissible operating range (350 V). On the other hand, the upper limit will be the maximum recommended battery charging voltage, which is 440 V (2.4 V/cell). See Figure 6a.
The operation limit of the Li-ion battery bank (SOC Li (k)) must correspond with its role as short-medium-term ESS. Taking advantage of its cycle durability, its minimum permissible SOC is 20%. This type of battery can operate in this range without suffering damage. See Figure 6b.
On the other hand, the lead-acid battery bank has the pivotal mission of guaranteeing the voltage stability in the DC bus, as well as to act in the very short term, guaranteeing the power balance during the transient switching of the rest of the elements connected to the DC bus. In addition to that, and as it is well known, the allowed SOC in this type of batteries is considerably more restrictive than in the case of Li-ion (never less than 60%). In any case, this is guaranteed by the range allowed for V bus (k).
On the other hand and regarding the second actor of the ESS, the universe of discourse of the hydrogen level (HL(k)) is determined by the maximum capacity of the storage tank (20 Nm 3 ), and the recommended value to ensure a minimum operating pressure (2 Nm 3 ). See Figure 6c. Then, SOC Li (k) and HL(k) ranges define the SOC ESS (k) range, whose minimum value is the average between 10% and 20%, i.e., 15%. See Figure 6d.
Regarding P bal (k), when all the P PV (k) is available and there is no consumption in the microgrid Equation (4), its value is that corresponding to the PV field, i.e., 5000 W. On the contrary, if there is not P PV (k) available and the consumption is the maximum, its value is −5000 W. See Figure 6e for P bal (k) and Figure 6f, obviously the same for P bal (k + 1). Similarly, when the ESS is being charged from the microgrid or it is supplying to the microgrid, its power range (P ESS (k)) can vary from −5000 W to 5000 W, respectively (Figure 6g). The first case represents the maximum load power of the ESS from the microgrid; the second indicates that all the microgrid loads are supplied by the ESS. In the ESS, the power will be shared between the Li-ion battery bank and the hydrogen system, so this leads to the given range of the universes of discourse in Equation (5) for P Li , P H 2 , and P ESS . Remember that the fuel cell maximum power is 3000 W. See Figure 6h,i.
Finally, the universes of discourse of C ES (k) and C EP (k) shown in Figure 6j,k have been defined, taking into account the Spanish market at the time of writing the paper.

Fuzzy Rules Base
On the basis of the above considerations respect to the microgrid functioning and considering the memberships functions described in Figure 6, three fuzzy rule bases have been defined (two for FLC1, depending on if the situation is purchasing or selling electricity to the main power grid, and one for FLC2). Each fuzzy rule base, as usual, is composed of rules of the form IF-THEN, as follows: FLC2 includes 59 rules and FCL1 contains 98 rules (36 rules in case of energy surplus and 62 in case of energy deficit). Regarding the high number of rules, the usual format (detail rule by rule from each fuzzy rule base) may not be the easiest and most illustrative way to do this. Therefore, to illustrate in a glance the inference of the three fuzzy rule bases, Figures 7-9 illustrate the respective flow charts.
In the case of energy excess, Figure 7 (P bal (k) > 0), the use of the microgrid's own resources is prioritized over the use of the main power grid, as long as the energy stored is close to its maximum level (SOC ESS− f uzz (k) = VH). In the event that the ESS is not capable of absorbing more energy (SOC ESS− f uzz (k) = VH), exclusive use of the main power grid is made to accomplish Equation (1).
In the event that the energy stored reaches a medium or high value, it is possible to sell the energy excess to the main power grid with the aim that while the energy reserves in the ESS are guaranteed, the EMS looks for economic profits. Energy sales to the main power grid will be determined by the energy excess, sale price, stored energy, and the power balance forecast in the next sampling period. Finally, if the ESS is not capable of absorbing more energy, exclusive use of the main power grid is made to accomplish Equation (1).  Figure 5). It is understood that the sets used are fuzzy.
By contrast, during energy deficit situations, Figure 8 (P bal (k) < 0), the use of the microgrid's resources is prioritized over the use of the main power grid, as long as the energy stored is not close to its minimum level (SOC ESS− f uzz (k) = VL). If this is the case, to guarantee the power balance the EMS makes use of the main power grid.
On the other hand, if the stored energy in ESS is at an intermediate level, joint use of the ESS and main power grid can be made to satisfy demand if the cost of purchasing energy is low, allowing a more conservative use of the microgrid's resources. As in the previous case, energy purchases from the main power grid will be determined by the energy deficit, purchase price from the main power grid, stored energy, and prediction of generation and consumption in the next sampling period.
With respect to the FLC2, the designed flow chart to build its fuzzy rule base is shown in Figure 9. Its function is to calculate the power setpoint of each device that integrates the ESS: the Li-ion battery bank and hydrogen system. The control premise is determined by the role of each system, the level of stored energy, and operating restrictions.
With respect to the Li-ion battery bank, its high performance and the high number of operating cycles mean the battery bank does not require special control actions for its operation. Its storage capacity will be maximized by making use of its high depth of discharge (DOD), resulting in a more conservative use of the hydrogen system.  Figure 5). It is understood that the sets used are fuzzy.
Considering the direct connection of the lead-acid battery bank to DC high voltage bus (Figure 1), it is necessary to implement a maximum voltage charging protocol, which guarantees the safe and efficient use of the battery bank. It is also necessary to limit the minimum discharging voltage, ensuring the DC bus voltage. Based on the described functionality and with the objective of prolonging the lead-acid battery bank lifespan, a strict V bus control has been defined. Considering the hydrogen system, due to its role as a long-term storage system, its reduced lifespan, and high cost, it is necessary to guarantee a conservative use. To get it, the developed FLC2 will work on two lines of action. The first one is to prioritize the use of the Li-ion battery bank, and the second is to reduce the operating stress of electrolyzer and fuel cell. For this purpose, it is necessary to carry out the correct definition of the membership functions of the FLC2 in order to guarantee smooth changes in the power set-points.  Figure 5). It is understood that the sets used are fuzzy.
Based on the above criteria, in case of energy excess, the ESS can take energy from the DC bus to be charged (P ESS < 0). Then, the lead-acid battery bank will be ready to be recharge until a medium DC bus voltage is reached (V bus− f uzz (k) ≤ M; V bus (k) ≤ 390 V). Once this voltage is reached, the Li-ion battery bank and hydrogen subsystem will be used to absorb the energy surplus, implementing a maximum charging voltage protocol. The priority in the recharge energy coming from the DC bus will be determined by the role of each element in the ESS, prioritizing the use of the Li-ion battery over the hydrogen system if its SOC is low (SOC Li− f uzz (k) ≤ M).
On the other hand, in case the ESS should supply energy to the microgrid (P ESS > 0), energy deficit situation, the use of the Li-ion battery bank will be prioritized in the first instance (P Li− f uzz (k) = P and P H 2 − f uzz (k) = Z) if its SOC is above 60% (SOC Li− f uzz (k) ≥ M). In this case, the hydrogen level shall be assessed (HL − f uzz (k) ≤ M), a prominent use of this resource shall be made while maintaining a medium-high level as long as possible.
Finally, in all the situations where both storage systems have energy available, Low < SOC Li− f uzz (k) < Medium and Low < HL − f uzz (k) < Medium , energy distribution between Li-ion batteries and the hydrogen system will be chosen, depending on the power balance and their stored energy capability.

Defuzzification
After the inference process, the fuzzy sets P Li− f uzz (k), P H 2 − f uzz (k) and P ESS− f uzz (k) need to be converted to real variables (crisp values). For that, a defuzzification process needs to be implemented to lead to P Li (k), P H 2 (k), and P ESS (k). In this case, the centroid method has been used.

Results
In order to validate the proposed fuzzy-based EMS, two simulation tests in MATLAB ® environment of the microgrid defined in Section 2 were developed, in accordance with the configuration shown in Figure 1. To carry out the test, the MATLAB ® -Simulink ® microgrid model of Figure 3 was used.
In the simulation test, a residential-type daily profile of renewable generation, grid utilization cost, and typical residential consumption was created. The generation profile corresponded to a 5 kW p photovoltaic field, for typical radiation and ambient temperature in Huelva (southwest of Spain).
The cost of purchasing energy from the main power grid corresponded to a typical night rate profile in Spain, Figure 10. On the other hand, the sale of energy to the grid (considering the Spanish situation) was carried out by a decrease in the bi-monthly electricity invoice, with a fixed rate value agreed with the electricity company of −0.06 €/kWh. In the test, a sampling time of 1 min was used. The microgrid was tested in its whole configuration, i.e., as showed in Figure 1. In order to check the correct operation of the proposed controller, solar generation profile was considered without and with fluctuations ( Figures 11 and 12, respectively).
The usual residential profile, where residents are outside during most of the daylight hours, is characterized by consumption valleys during the day (when it takes place the maximum production of photovoltaic) and consumption peaks just after the noon (if residents go home for lunch) and especially at night (involving the ESS use); hence the interest of the night rate (see Pload in Figures 11  and 12). As a residential type microgrid, the electric vehicle contributes to the demand profile (see PEV in Figures 11 and 12). It reflects a daily use of the vehicle corresponding to 40% of its energy capacity, and the recharge energy consumption will be carried out coinciding with the night rate.
Finally, to evaluate the economic performance of the proposed strategy against traditional control techniques, the reference study case presented in [24] was chosen. This reference proposes a hysteresis SOC-based EMS. This EMS determines the power setpoint of the energy storage system and grid, taking into account only the battery SOC and hydrogen level. The main grid will be used to guarantee the power balance in extreme conditions. The parameters that defined the EMS strategy are shown in Table 3.   The results from the test carried out are shown in Figures 11 and 12. Similarly, the DC bus voltage profile and the energy stored (SOC La , SOC Li , and HL) are shown in Figures 13 and 14 respectively. Figure 15 allows the comparison of the hourly grid cost obtained from the proposed fuzzy-based EMS with respect to the traditional case connected exclusively to the main power grid and the reference study case based on hysteresis EMS (€ > 0 means residential facility purchases energy to the main power grid, € < 0 means that the microgrid of the residential facility sells energy to the main power grid).

Discussion
According to the generation and consumption profile, Figures 11 and 12, the microgrid started daylight hours in an energy surplus situation that remained virtually during the period 8 h ≤ t ≤ 19 h. This was used by the EMS to recharge the Li-ion battery bank (Figures 11a and 12a). As there was still energy surplus, the EMS ordered to start the hydrogen production (Figures 11b, 12b and 14). Despite the electrolyzer operation, there was still energy excess, which was sold to the main power grid (Figures 11b and 12b).
According to the EMS performance, the decision criteria of the fuzzy logic-based controller are not only meet with the load demand but also guarantee the best performance according to technical and economic parameters. Then, with the aim to enlarge the electrolyzer lifespan, it was tried that the electrolyzer had an operation regime that was as stable as possible, to the detriment of more variable use of the Lithium battery bank and grid.
Along the first considered period (8 h ≤ t ≤ 19 h) it was easy to demonstrate that the behavior of the lead-acid battery bank was as expected. Indeed, its contribution to the DC bus power was very little and only dedicated to balancing the bus (Figures 11a and 12a). On the other hand, the DC bus voltage was really under control, with fluctuations below 10 Volts, i.e., less than 4% (see Figure 13). Additionally, the bus voltage kept on increasing until the end of the simulation time. The reason is that the control strategy made it possible to derive part of the surplus energy directly to the lead-acid battery bank if the voltage value was below the design voltage established at 390-400 VDC, see FLC2 flowchart in Figure 9. Moreover, this voltage guaranteed the proper SOC of the lead-acid battery bank, always over limits values (see Figure 14).
From 19 h < t ≤ 32 h, an energy deficit situation appeared; the load demand increased and energy was required for the residential load and to charge the electric vehicle, while the supply from the PV panels went on decreasing until it was null. In this period, the load demand was guaranteed by the Li-ion battery bank (Figures 11a and 12a) and the main power grid support (Figures 11b  and 12b). In energy deficit periods, the EMS criterium is to promote a joint use of the ESS and the main power grid, which is recommendable when the cost of purchasing energy is low. This allows a more conservative use of the microgrid's resources. The fuel cell operation was delayed until 24 h < t ≤ 29 h (Figures 11b and 12b), i.e., until the moment when the SOC of the Li-ion battery bank began to drop considerably ( Figure 14). The power setpoint of each device that makes up the ESS was defined by FLC2 (Figure 9), and it was established that the hydrogen subsystem provides energy (P H 2 − f uzz (k) = Positive) when Low ≤ SOC Li− f uzz (k) < Medium (40% ≤ SOC Li (k) < 60%) and Low ≤ HL − f uzz (k) < Medium (2 Nm 3 ≤ HL(k) < 10 Nm 3 ). This situation generated, obviously, the consequent decreasing of the stored hydrogen level ( Figure 14). In the last part of the one-day period, 29 h < t ≤ 32 h, the residential load was supplied exclusively by the main power grid (Figures  11b and 12b). This is the case (see Figure 8) when C EP− f uzz (k) ≤ Medium (C EP (k) ≤ 0.075 €) and SOC ESS− f uzz (k) < Medium (SOC Li (k) = 50% and HL(k) = 4 Nm 3 ), so P ESS− f uzz (k) = Zero (Figures 11  and 12). During this interval, the lead-acid battery bank harnessed the energy availability to slightly increase its state of charge ( Figure 14). This increasing was, sensibly, more accused at the beginning of the new period because P bal (k) was positive, renewable (photovoltaic) power was available (see Figures 11 and 12).
The behavior described above was repeated during the following two days. It is possible to see from Figure 14 the little delay between the charging/discharging of the Li-ion battery bank and the hydrogen tank. The EMS prioritizes the use of the battery bank versus the hydrogen tank, with the aim to make more conservative use of the hydrogen-based devices and avoid them having a higher degradation rate. On the other hand, Figure 13 shows that the use of the lead-acid battery bank was reduced and was limited to guaranteeing the power balance during the switching transient of the rest of the systems, and to keep the voltage of the DC bus inside the allowed range (380 V ≤ V bus (k) ≤ 400 V). Really, the behavior is excellent because of the allowed margin, Equation (5): 350 V ≤ V bus (k) ≤ 440 V.
Finally, taking into account the main power grid utilization cost (Figure 15), the developed EMS allows a higher economic performance of the residential-type microgrid. It takes advantage of selling energy excess and promoting energy consumption in the most favorable situations according to the energy cost rate. Then, during the three-day test, the electricity invoice and grid utilization ascended up to €5.33 and 73 kWh in the case of the main power grid connection, while in the case of microgrid with hysteresis-based strategy, the cost associated with the use of the grid and grid utilization decreased to €0.5772, 11.17 kWh, and €0.8063, 15.76 kWh for low renewable fluctuations and variable generation profile, respectively. For the proposed fuzzy logic-based EMS, the electricity invoice and grid utilization descended to €0.15, 7.6 kWh, and €0.6, 18.07 kWh for low renewable fluctuations and variable generation profile, respectively. This means a cost saving of 97.2% and 88.74% for the full grid utilization, and 74.0% and 25.59% for the hysteresis-based EMS for favorable and variable generation profile, respectively. In light of the results, it can be seen how the proposed fuzzy logic-based strategy increases the economic performance of the system with respect to the other cases studied, considering the use of the grid and the purchase/sale price as an additional decision factor.

Conclusions
This paper has presented a fuzzy logic-based EMS for microgrids with hybrid ESS based on a batteries and hydrogen system, which ensures the power balance according to the load demand, while taking into account the improvement of microgrid performance from a technical and economic point of view.
The fuzzy logic approach was chosen because: (1) linguistic rules are interpretable and they can simplify the management and control of complex microgrids, (2) it can incorporate expert knowledge that takes advantage of the accumulated knowledge about the microgrid, and (3) it does not need to dispose of the microgrid model to carry out the controller design.
The developed fuzzy logic-based EMS uses the knowledge from experts, which is incorporated into fuzzy rules bases. This allows the inclusion of both technical and economic criteria into the inference process, which ensures the power balance of the microgrid at all times, pursuing, in addition, its best performance and efficiency, ensuring the best lifespan of its elements and the most advantageous economic exchange with the main power grid.
On the other hand, with the objective to test the microgrid performance in a stress situation, the developed EMS has been subjected to a residential-type profile consumption for 72 hours (three days) and stable and fluctuating solar generation profiles. The residential profile is characterized by consumption valleys during the sunny hours, while consumption peaks take place at night, out of sunlight hours, compromising the use of battery and hydrogen storage system.
The results show that the fuzzy logic-based EMS guarantees the residential-type demand, while it keeps a conservative use of those systems that suffer higher degradation. Regarding economic criteria, the developed fuzzy logic-based EMS allows savings of up to €630/year in the electricity invoice.

Conflicts of Interest:
The authors declare no conflict of interest.

HL(k)
Hydrogen storage level (Nm 3 ) P bal (k) Power balance (W) P Els (k) Electrolyser operating power (W) P ESS (k) Energy storage system power (W) P EV (k) Electric vehicle charging power (W) P FC (k) Fuel cell operating power (W) P Grid (k) Main power grid operating power (W) P GI (k) Purchased power from the main power grid (W) P GO (k) Sold power to the main power grid (W) P H 2 (k) Hydrogen system operating power (W) P L (k) Residential load power (W) P La (k) Lead-acid battery bank power (W) P Li (k) Li-ion battery bank power (W) P PV (k) Renewable (solar) power (W) SOC La (k) State of charge of lead-acid battery bank (Ah) V bus (k) DC bus voltage (V)