Smart Management of Energy Storage in Microgrid: Adapting the Control Algorithm to Speciﬁc Industrial Facility Conditions

: The article introduces a method for optimizing energy storage system scheduling in industrial microgrids. It employs a PSO-based heuristic algorithm using daily generation and load forecasts. The objective is economic optimization, minimizing energy costs, and maximizing proﬁts. Market energy prices and distributor tariffs are the base of the objective function. An algorithm maintains the plan by controlling storage power based on real-time microgrid measurements, aligning with the intended power exchange curve. Due to PSO’s ability to perform multidimensional optimization, it is possible to ﬁnd the global optimum of the objective function. To validate the practical applicability of this approach, it is exempliﬁed through its implementation within a real-world industrial microgrid setting. The presented results indicate the method’s effectiveness but also show its weaknesses. For the two considered cases, a decrease in operating costs of 6.7% and 10.8% was achieved, respectively. On the other hand, the best results are obtained for shorter forecasts, which is why the algorithm, despite long planning periods, revises the ESS operation plan whenever there are signiﬁcant deviations between the forecast and the actual power.


Introduction
In contrast to conventional energy sources, renewable energy sources (RES) [1] offer an alternative.However, RES come with challenges.Photovoltaic systems (PV) generate stochastic power heavily influenced by weather, particularly on cloudy days, and are inactive at night.Wind power plants are inefficient at low wind speeds.Biomass power plants exhibit reduced efficiency in colder temperatures.Microgrids address these issues by interconnecting generation units and energy storage systems (ESS) [2].ESS stores surplus energy for release during peak demand, mitigating power fluctuations and serving as an emergency power source.There is a wide range of possibilities [3].
Control strategies for energy storage systems (ESS) in microgrids are continuously advancing, with technologies and algorithms constantly enhancing them.This ongoing refinement and innovation plays a pivotal role in optimizing the utilization of renewable energy.

The State of the Art
Energy storage system control strategies encompass five key aspects: environmental concerns, cost minimization, maximizing usage efficiency, emergency backup, and economic factors [4].In the following paragraphs, the authors analyzed the various aspects, presenting examples found in the literature, pointing out the advantages and disadvantages of the solutions presented, and possible gaps that can be used for further research.
Environmental concerns coincide with objectives for sustainable development, often intertwining with carbon emission reduction [5].For instance, a study [6] investigated the parameters and distribution of ESS within microgrids to mitigate carbon emissions, advancing decarbonization objectives.In another publication [7], attention was directed toward addressing greenhouse gas emissions.Notably, the optimization challenge does not solely involve ESS sizing but also hinges on device control strategies.A parallel inquiry [8] focused on operational cost optimization, highlighting the second facet of ESS control: cost reduction.A common theme of the papers [6][7][8] is the focus on elements such as ESS size optimization, control strategies, and uncertainty management.Thus, it is reasonable to expand research in this area, using more advanced ESS control algorithms and integrating distributed energy sources and energy storage systems further into the power grid, thus increasing the potential of ESS.
Cost reduction pertains to minimizing electricity expenses.Utilizing renewable energy sources (RES) in homes or industries cuts energy purchase costs.Storing extra energy offers added savings [9].This cost-cutting goal aligns with the broader economic aim of enhancing RES efficiency [10].In one study [11], which analyzes using partially used electric car batteries for smart grid load balancing, both goals are harmonized effectively.Another paper [12] merges cost reduction with utility optimization, leading us to the following aspect.There is a common factor linking the papers [11,12]: cost reduction, efficient use of resources, and exploration of the topic of government incentives in achieving economic and environmental goals.Both papers consider a different setting; [11] focuses on applying used batteries from EVs in individual homes, while [12] considers entire microgrids.Future research should seek to combine these aspects.For example, examining how used EV batteries and government incentives in microgrids affect the achievement of cost-effective energy solutions.
Maximizing usage time is related not only to the technical aspect of extending the life of the ESS but also to maximizing the period in which RES perform best by shifting the load, an energy dispatch (ED) problem.Hence, the objective considered in this paragraph is also linked to the economic aspect, preferably shifting the load from when energy is most expensive to when it is cheaper [4].For example, in [13], the authors solve the ED problem using controllable loads and electric cars acting as loads and energy storage systems.Also, in [14], the authors analyze the ED problem, using only controllable loads but considering the power generated by wind turbines.There is common ground in the papers [13,14] in optimizing microgrid operation for economic reasons.The difference, however, is the area of interest.Ref. [13] delves into EV and transferable load (TL) integration, offering a user-centric perspective, while [14] emphasizes wind energy and worst-case transaction cost reduction.The advantages of the research presented in [13,14] include optimizing microgrid operation through cost reduction.The disadvantage of the proposed study is the lack of practical application, for example, in an industrial facility.The analysis of the two papers also allows us to conclude that there is a need for a complex approach, combining both the complexity of the real world and various distributed energy sources.
Lastly, we address the aspect of emergency backup related to ensuring the continuity of power supply, especially during power plant failures or grid protection tripping [15].For instance, in one study [16], researchers employed a bee algorithm to regulate the ESS, ensuring continuous power supply to standalone microgrids amidst intermittent RES-generated power.The objective function also considered economic factors.Another work [17] combined the emergency backup challenge with sizing the ESS for an extended lifespan.This analysis covered scenarios where the ESS functioned as a standard grid component and an emergency power source.Papers [16,17] analyze the reliability of microgrid operation and cost-effectiveness in the context of ESS.With that said, [16] focuses on the stochastic nature of distributed sources and the importance of ESS in this context.In contrast, [17] devotes more attention to finding optimal ESS parameters that represent a solution to a demand-supply-based problem.The advantages of both papers can be mentioned: the enhancement of the resilience of microgrids to actual conditions and the profitability of investments in ESS.The disadvantage of the presented solutions is the lack of implementation in the real world.

Research Gaps and Contribution of the Work
Reviewing the literature reveals that addressing energy storage system control challenges entails employing a combination of suitable strategies rather than relying solely on a singular approach.The authors present a novel ESS control algorithm in this context, integrating cost reduction and emergency backup function.Cost reduction centers on minimizing energy purchase costs and maximizing revenue from energy sales, as Poland's new net-billing energy system operates hourly.Additionally, the objective function incorporates maintaining the state of charge (SoC) of ESS at a predetermined level by the scheduling period's end for emergency backup.This translates into a high-dimensional optimization challenge, where each scheduled power value becomes an independent dimension of the objective function.Given the function's nonlinearity, non-continuity, and presence of multiple local extrema, the particle swarm optimization (PSO) algorithm, a computational intelligence approach, is employed for resolution.Furthermore, the proposed ESS operational plan is validated in an industrial setting-two optimized scenarios: one constrained by limited grid collaboration and the other without limitations.

Nomenclature
The article uses the abbreviations and symbols listed in Nomenclature part in back matter.

Microgrid Parameters
The research was conducted for an existing industrial microgrid that powers a factory producing metal components using laser cutting methods on steel.A 20 kV distribution network supplies the company.The average power demand is 400 kW.Within the industrial microgrid, there is a 317 kWp photovoltaic installation and an energy storage system with a capacity of 175 kWh and a nominal power of 50 kW for the bidirectional inverter.Additionally, the storage system is equipped with a second unidirectional inverter with a power of 150 kW, which, together with the battery, functions as an uninterruptible power supply (UPS) for the production halls during outages and voltage fluctuations.Due to its UPS function, the lower discharge limit of the storage system was set at 20% of its maximum capacity.
The provided analyses relate to measurements taken within the discussed, actual industrial facility.The effectiveness of the suggested algorithms was confirmed after integrating them into the ESS control system.
Figure 1 illustrates a simplified outline of the microgrid, forming the foundation for power flow calculations.
The ESS is equipped with a control system that supervises the operation of all equipment, with a programmable logic controller (PLC) as its main component.The PLC monitors the states of devices and distribution boards in the energy storage system.Control is implemented using digital signals and communication modules that allow communication with devices using the Modbus TCP/IP protocol.Recording of electrical and non-electrical values in the monitoring and control system is integrated into a custom information system.Measurement modules installed in the main distribution board nodes form the basis for monitoring energy flow in the microgrid.They make it possible to measure all relevant electrical data.Voltages are measured by direct connection, and the current of the three phases is fed through current transformers.RMS values of voltage and current, active power, complex power, reactive power, frequency, phase shift angle, and harmonics are measured.The measurement step is 1 s, with a 10-s aggregation used in the control algorithms analyzed.The ESS is equipped with a control system that supervises the operation of all equipment, with a programmable logic controller (PLC) as its main component.The PLC monitors the states of devices and distribution boards in the energy storage system.Control is implemented using digital signals and communication modules that allow communication with devices using the Modbus TCP/IP protocol.Recording of electrical and non-electrical values in the monitoring and control system is integrated into a custom information system.Measurement modules installed in the main distribution board nodes form the basis for monitoring energy flow in the microgrid.They make it possible to measure all relevant electrical data.Voltages are measured by direct connection, and the current of the three phases is fed through current transformers.RMS values of voltage and current, active power, complex power, reactive power, frequency, phase shift angle, and harmonics are measured.The measurement step is 1 s, with a 10-s aggregation used in the control algorithms analyzed.

MatPower Model
In the simulations, a basic microgrid model was employed.The MatPower library within the Matlab environment was used for power flow calculations.For optimization, the Global Optimization Toolbox was used.However, as preliminary studies have shown [18], both the AC and DC models yield comparable results for active power flow.The analyses involved active power balance computations, considering losses and ESS selfconsumption during load forecasting in the microgrid.Given that, this analysis concerns an actual installation; the project design assumptions already considered the influence of generation and storage on voltage values at nodes and currents in lines.As a result, there is no risk of surpassing acceptable values due to the management of the storage system's operation.

ESS Characteristics
The energy storage system's limitations are defined by its charging and discharging characteristics, dependent on its state of charge.The manufacturer should provide such a profile, which can be determined through measurements.The authors described the experimental method for determining this profile in [18].The shape of the ESS profile

MatPower Model
In the simulations, a basic microgrid model was employed.The MatPower library within the Matlab environment was used for power flow calculations.For optimization, the Global Optimization Toolbox was used.However, as preliminary studies have shown [18], both the AC and DC models yield comparable results for active power flow.The analyses involved active power balance computations, considering losses and ESS self-consumption during load forecasting in the microgrid.Given that, this analysis concerns an actual installation; the project design assumptions already considered the influence of generation and storage on voltage values at nodes and currents in lines.As a result, there is no risk of surpassing acceptable values due to the management of the storage system's operation.

ESS Characteristics
The energy storage system's limitations are defined by its charging and discharging characteristics, dependent on its state of charge.The manufacturer should provide such a profile, which can be determined through measurements.The authors described the experimental method for determining this profile in [18].The shape of the ESS profile stems from storage technology and Battery Management System (BMS) algorithms, which manage cell operations by responding to temperature changes, voltage, current levels, charge status, cell degradation, and more.The profile also establishes the discharge threshold, set at 20% in accordance with the storage unit manufacturer's instructions, accounting for the system's backup function during outages as a UPS. Figure 2    The algorithm calculates the excess or shortfall in generated power and decides on charging or discharging the ESS accordingly.If the decision is to charge, the charging power is the minimum value derived from comparing three factors: the specified charging power P ST , the power from the storage characteristic P ST CH CH , and the power resulting from the current state of charge P ST CH EN .If the decision is to discharge, the discharging power is the maximum value obtained by comparing: the specified discharging power P ST , the power from the P ST DI CH storage characteristic, and the power resulting from the current state of charge P ST DI EN .

Planning Algorithm
The presented planning algorithm employs energy prices along with generation and load forecasts.The authors do not delve into forecasting methods in this work but utilize forecasts developed within the research team for the ongoing project.The process of controlling the energy storage system is carried out so that, first, the generation and load forecasts are computed.Then, a controller constructed for the project takes the forecasts and sends them to an algorithm that schedules the operation of the ESS.During planning, constraints arising from the ESS characteristics are taken into account.The planning objective is economically optimal control of the storage system's power.A novel approach, previously unused in such contexts, pertains to optimization in a high-dimensional space, where each planned power value in the ESS schedule is an individual point in the search space.The objective function is nonlinear and discontinuous and features several local extremes.Classical optimization methods are inadequate in this scenario.Given the extensive search space and the nature of the objective function, the PSO algorithm is employed.Unlike other computational intelligence algorithms, PSO yields favorable results within a reasonable processing time.

Net-Billing
The economic aim of energy storage schedule planning is based on energy prices.In Poland, a new system of settlements for prosumers will be introduced on 1 July 2024.Under the net-billing system, prosumers will sell excess energy at market prices.However, to cover energy shortfalls, they will purchase energy according to tariffs applied by the operator.Alterations in the compensation approach concern micro-installations and small renewable energy sources with a combined installed capacity of no more than 1 MW, connected to an electrical network with a nominal voltage lower than 110 kV.
The introduction of net-billing serves to enact European legislation.The RED II Directive [19] pertains to promoting the use of renewable energy, increasing the adoption of RES in a distributed and community-oriented manner.Furthermore, the introduced alterations aim to enhance the operational security of Polskie Sieci Elektroenergetyczne S.A. (the Polish system operator).As of April 2023, the count of installations in Poland exceeded 1.25 million, with the combined power of PV installations surpassing 13.5 GW.With continued robust growth in investments in renewable energy, the Polish system operator cannot absorb the escalating quantity of energy generated by prosumer installations.
The surplus settlement will be conducted using a value approach in the net-billing system.The distributor will assess energy injected into the grid based on the market price of electric energy published by the Polish system operator.Conversely, the energy consumed will be calculated per the energy seller's tariff.Decisions will take place at hourly rates.The prosumer's account will record the value of electric energy introduced into the grid, constituting what is known as a consumer deposit.If the market energy price is negative in a given settlement period, the value of produced energy during that period is considered zero.The funds accrued by the prosumer over the month will be aggregated and attributed to the calendar month.These funds will then be used for settlement and must be utilized within a year.Funds not settled within this time frame will be forfeited.Energy distribution fees cannot be deducted from the prosumer's deposit.Embracing these principles aims to encourage self-consumption, optimizing the size of renewable energy installations, and promoting the usage of energy storage systems.
In the new settlement system, the investor's financial account becomes less foreseeable, and energy prices in the long term remain a significant unknown.Hence, methods of intelligent energy management currently hold importance.

Algorithm Principle
The planning algorithm is presented as the pseudocode of the Algorithm 2 function.The algorithm employs the PSO method to determine the optimal power profile of storage unit P ST [1..N], and thus the enforced exchanged power with the electrical system P DS FOR [1..N].The algorithm plans storage control while optimizing the economic aspect.The objective function minimizes energy purchase costs and maximizes energy sales profits.Additionally, a technical aspect can be introduced to the objective function.Regarding technology, ESS applications for collaboration with the electrical grid can have various objectives.These include maintaining required energy quality parameters, load, generation peak reduction and shifting, minimizing overload losses, voltage level control, backup power supply, and storage protection.
Applying the Weighting Objectives Method reduces multi-objective optimization to a single-objective task.As a technical aspect of this work, maintaining the SoC of the storage unit at a specified level at the end of the planned schedule period is proposed.
In the presented analyses, optimization was conducted in a 24-dimensional space (for hourly resolution and a one-day planning period).However, the algorithm can optimize schedules in a significantly larger space if calculated with a smaller time step or over a longer time interval.If forecasts are available at a resolution of 15 min daily, the space will become 96-dimensional.However, in real-world tasks, PV generation forecasts are computed using weather services that provide weather data at hourly intervals.Similarly, energy prices in the day-ahead market are published with hourly resolution.
As input data, the algorithm uses matrices of generation power forecasts P GE [1..N] and load power P LO [1..N], time step T, maximum storage capacity E ST MAX , maximum storage power P ST MAX , and minimum SoC value SoC MIN .At the beginning of each computational step, the current state of charge SoC INI is introduced.
The storage @char characterizes permitted charging power P ST CH CH and discharging power P ST DI CH , depending on SoC.The algorithm also calculates allowable charging and discharging power (P ST CH EN , P ST DI EN ), which depend on available capacity or ESS energy.
The algorithm's operation begins within the PSO loop by generating a random P ST profile P ST [1..N].For the initial SoC INI , P ST [k] power values are adjusted according to the established storage characteristics, and the power balance is computed in the flow model for P GE [k], P LO [k], and P DS FOR [k] values.The result is a vector of storage power values and a vector of exchanged power with the distribution system.Next, the PSO heuristic algorithm evaluates the solution based on the given objective function.If the search for the optimum yields satisfactory results, the algorithm terminates (e.g., after reaching a designated number of iterations or achieving no change in the objective function value within a defined tolerance).If not, a new P ST [1..N] vector is computed, and the evaluation process is repeated.The algorithm's outcome is an optimal schedule for storage unit operation P ST [1..N] and an optimal energy exchange profile with the distribution system P DS FOR [1..N], which is used in the storage control algorithm.

PSO
In the proposed method, selecting PSO parameters is crucial and should be preceded by extensive research.The PSO parameters applied in the planning algorithm are shown in Table 1.

Lb
Lower bound min(P LO + P GE ) 1 min(P LO [k] + P GE [k]) 2 1 The maximum and minimum values (P LO + P GE ) over the total control range were taken as a boundary. 2The maximum and minimum values (P LO [k] + P GE [k]) for each control step were taken as a boundary.
Besides tests involving various new PSO modifications such as ant algorithms, bee algorithms, bird algorithms, etc., the impact of optimization progress was examined by parameters like swarm size, the maximum number of iterations, self and social adjustment coefficients, inertia, and tolerance.The convergence of optimization and result repeatability were significant considerations.Processing time was also noted, though it is not a critical parameter in the case of one-day-ahead scheduling.Multiple runs of the PSO algorithm were employed to ensure consistent optimization outcomes, selecting the best solution.

Objective Function
Optimizing the economic criterion involves minimizing purchased energy costs and maximizing profits from energy sold.The P DS FOR [1..N] array is divided into the P − DS FOR array, containing only negative values when energy was drawn from the system (cost), and the P + DS FOR array, containing only positive values when energy was fed back (profit).The cost or profit at each time step is the product of energy and its respective price C MA [k] or C DS [k].Hence, the minimized objective function takes the form: The optimal F 1 can take positive values, indicating a predominance of cost within the planned time interval.When F 1 is negative, there is a predominance of profit within the scheduled time interval.
The energy purchase price, C DS , is tied to the three-tier energy tariff of the distribution system operator.The selling price relates to the market electricity price, C MA , published by Polish system operator.The daily price profiles for 1 June 2023, are shown in Figure 3. Objective function F2, which takes into account the technical aspect of maintaining the energy storage state of charge at the end of the planning period at a specified level, e.g., 80%, is formulated as: To calibrate the weight w, the value of F1 was computed as the economic objective only using Equation (1), and then the weight was adjusted to balance the rank of the components in (2): w = 100/F1 (3) In the considered case, the economic component for the analyzed storage installation F1 operates at daily energy costs of around 10,000 PLN, while the SoC [%]-related component is about 10, so the weight (3) in the calculations was set at a level of 0.001.
The objective functions (1) and ( 2) are nonlinear and contain numerous local minima.This is due to their inclusion of generation and load forecast profiles and daily energy price profiles.The objective function also incorporates the nonlinear characteristic of the ESS obtained from measurements.When using methods to determine power flows in the network, a nonlinear system of equations is solved.The optimization takes place in a highdimensional space.In summary, this is an extremely challenging optimization problem. Figure 4 shows the value of the objective function F1 (its distribution), with changes in ESS power from minimum to maximum at selected planning hours.ESS power is a 24dimensional variable (for each hour, one dimension).Since it is impossible to draw a graph in 24 dimensions, here, the sample relationships of F1 on two random dimensions are chosen.For example, the F1 [14] column and F1[9] row markings show the changes in the value of the objective function when the ESS power is changed from −50 kW to +50 Objective function F 2 , which takes into account the technical aspect of maintaining the energy storage state of charge at the end of the planning period at a specified level, e.g., 80%, is formulated as: To calibrate the weight w, the value of F 1 was computed as the economic objective only using Equation (1), and then the weight was adjusted to balance the rank of the components in (2): w = 100/F 1 In the considered case, the economic component for the analyzed storage installation F1 operates at daily energy costs of around 10,000 PLN, while the SoC [%]-related component is about 10, so the weight (3) in the calculations was set at a level of 0.001.
The objective functions (1) and ( 2) are nonlinear and contain numerous local minima.This is due to their inclusion of generation and load forecast profiles and daily energy price profiles.The objective function also incorporates the nonlinear characteristic of the ESS obtained from measurements.When using methods to determine power flows in the network, a nonlinear system of equations is solved.The optimization takes place in a high-dimensional space.In summary, this is an extremely challenging optimization problem. Figure 4 shows the value of the objective function F 1 (its distribution), with changes in ESS power from minimum to maximum at selected planning hours.ESS power is a 24-dimensional variable (for each hour, one dimension).Since it is impossible to draw a graph in 24 dimensions, here, the sample relationships of F1 on two random dimensions are chosen.For example, the F1 [14] column and F1[9] row markings show the changes in the value of the objective function when the ESS power is changed from −50 kW to +50 kW at the 14th and 9th hour of planning.In the planning algorithm, there are two options for search space constraints.The first option prohibits charging the energy storage system from the distribution grid and discharging it into the grid.In other words, the storage system only utilizes surplus generated energy and handles only the energy deficit required by loads.Upper bounds Ub [1..N] and lower bounds Lb [1..N] for each variable are determined based on the PGE[1..N] + PLO [1..N] curve.The second option allows interaction between the storage system and the distribution grid.The only constraint, in this case, is the maximum power capacity of the PST MAX storage system.The Ub[1..N] vector assumes a permissible charging value of 50 kW, and Lb [1..N] assumes a permissible discharging value of −50 kW.

Control Algorithm
The control algorithm presented as pseudocode in Algorithm 3 is designed to maintain the planned schedule by controlling the energy storage system's power in real time.The algorithm aims to preserve the intended level of power exchange with the distribution system.As input data, besides the storage parameters and its characteristics, the algorithm takes current measurements such as generation power PGE, load power PLO, the current state of charge, and the planned power exchange with the distribution system PDS FOR.
Surplus energy is primarily directed to the storage, while the storage handles energy deficits.The algorithm adjusts PST according to the ESS characteristic and calculates the power flows in the microgrid.The algorithm's output includes the adjusted charging or In the planning algorithm, there are two options for search space constraints.The first option prohibits charging the energy storage system from the distribution grid and discharging it into the grid.In other words, the storage system only utilizes surplus generated energy and handles only the energy deficit required by loads.Upper bounds Ub [1..N] and lower bounds Lb [1..N] for each variable are determined based on the P GE [1..N] + P LO [1..N] curve.The second option allows interaction between the storage system and the distribution grid.The only constraint, in this case, is the maximum power capacity of the P ST MAX storage system.The Ub[1..N] vector assumes a permissible charging value of 50 kW, and Lb [1..N] assumes a permissible discharging value of −50 kW.

Control Algorithm
The control algorithm presented as pseudocode in Algorithm 3 is designed to maintain the planned schedule by controlling the energy storage system's power in real time.The algorithm aims to preserve the intended level of power exchange with the distribution system.As input data, besides the storage parameters and its characteristics, the algorithm takes current measurements such as generation power P GE , load power P LO , the current state of charge, and the planned power exchange with the distribution system P DS FOR .
Surplus energy is primarily directed to the storage, while the storage handles energy deficits.The algorithm adjusts P ST according to the ESS characteristic and calculates the power flows in the microgrid.The algorithm's output includes the adjusted charging or discharging power of the storage P ST , the power exchange with the distribution system P DS , and the SoC.

Simulations and Analysis
The analyses were conducted for an actual industrial metallurgical facility.Daily forecasts for generation and load in 1-h resolution were used for planning.Measurements taken at 1-s intervals were utilized to simulate real-time energy flow control.The simulations were carried out for a typical working day on 1 June 2023.Weather conditions on this day were favorable for photovoltaic generation, as indicated by the generation power chart.
As an indicator of economic efficiency of control, a parameter was adopted that compares energy costs (or profits) in the system without and with energy storage.The storage is controlled using the proposed algorithm.The economic effect, expressed in PLN, is the difference between energy charges (or profits) in both systems calculated over a single day.Only the net energy price was considered when calculating the daily effect, excluding distribution fees and fixed charges.This aligns with the planned approach for settling with prosumers in the net-billing system.
The presented case concerns the optimal plan economically and considers technical limitations.The first limitation involves managing only the surplus of locally generated energy and its deficit.An additional technical constraint in the objective function is that the SoC at the end of the planning period is to be at a specified level, e.g., 80%.This also has practical significance due to the UPS function that the studied storage system fulfills.The parameter SoC INI remains constant for successive planning periods.
Figure 5 illustrates the power flow in the microgrid, P ST [1..N] storage schedule, and enforced power exchange profile with the distribution system P DS FOR [1..N], calculated based on forecasts P GE [1..N], P LO [1..N].
Sustainability 2023, 15, x FOR PEER REVIEW 11 of 16 discharging power of the storage PST, the power exchange with the distribution system PDS, and the SoC.

Simulations and Analysis
The analyses were conducted for an actual industrial metallurgical facility.Daily forecasts for generation and load in 1-h resolution were used for planning.Measurements taken at 1-s intervals were utilized to simulate real-time energy flow control.The simulations were carried out for a typical working day on 1 June 2023.Weather conditions on this day were favorable for photovoltaic generation, as indicated by the generation power chart.
As an indicator of economic efficiency of control, a parameter was adopted that compares energy costs (or profits) in the system without and with energy storage.The storage is controlled using the proposed algorithm.The economic effect, expressed in PLN, is the difference between energy charges (or profits) in both systems calculated over a single day.Only the net energy price was considered when calculating the daily effect, excluding distribution fees and fixed charges.This aligns with the planned approach for settling with prosumers in the net-billing system.
The presented case concerns the optimal plan economically and considers technical limitations.The first limitation involves managing only the surplus of locally generated energy and its deficit.An additional technical constraint in the objective function is that the SoC at the end of the planning period is to be at a specified level, e.g., 80%.This also has practical significance due to the UPS function that the studied storage system fulfills.The parameter SoCINI remains constant for successive planning periods.Meanwhile, the result of the control algorithm's operation for real-time power measurements in the microgrid is depicted in Figure 6.In the case of measurements at a 1-s resolution, significant momentary variations in load power can be observed, stemming from the specific nature of production involving laser cutting of steel.This leads to a similar variation in storage power, as the control algorithm aims to maintain the planned energy exchange with the distribution system.Meanwhile, the result of the control algorithm's operation for real-time power measurements in the microgrid is depicted in Figure 6.In the case of measurements at a 1-s resolution, significant momentary variations in load power can be observed, stemming from the specific nature of production involving laser cutting of steel.This leads to a similar variation in storage power, as the control algorithm aims to maintain the planned energy exchange with the distribution system.
Comparing the enforced profile P DS FOR with the one executed by the control P DS (Figure 7), periods when the plan closely matches the executed curve can be observed (hours 0:00-6:00).In other time intervals, the control cannot precisely execute the plan due to power, capacity, and storage characteristic limitations.However, even in those intervals, the energy exchange profile P DS is much flatter compared to the microgrid without storage.This is an advantage of the proposed control, as from the distributor's perspective, it helps reduce load peaks and valleys, improving power quality.Comparing the enforced profile PDS FOR with the one executed by the control PDS (Figure 7), periods when the plan closely matches the executed curve can be observed (hours 0:00-6:00).In other time intervals, the control cannot precisely execute the plan due to power, capacity, and storage characteristic limitations.However, even in those intervals, the energy exchange profile PDS is much flatter compared to the microgrid without storage.This is an advantage of the proposed control, as from the distributor's perspective, it helps reduce load peaks and valleys, improving power quality.
Simulations were conducted with an initial state of charge, SoCINI, set at 80%.The planned and actual changes in SoC are depicted in Figure 8.According to the objective function, the control discharges the storage during high purchase prices and charges it when purchase prices are low.As can be observed, the planning and control system behaves correctly, also fulfilling the condition of maintaining the final SoC at the specified level.For the presented planning day, the cost of energy drawn to the industrial microgrid without storage would amount to 1472 PLN.The planned economic effect is 100 PLN (6.7%), and the effect actually achieved by the plan maintenance algorithm is 103 PLN (6.7%).Comparing the enforced profile PDS FOR with the one executed by the control PDS (Figure 7), periods when the plan closely matches the executed curve can be observed (hours 0:00-6:00).In other time intervals, the control cannot precisely execute the plan due to power, capacity, and storage characteristic limitations.However, even in those intervals, the energy exchange profile PDS is much flatter compared to the microgrid without storage.This is an advantage of the proposed control, as from the distributor's perspective, it helps reduce load peaks and valleys, improving power quality.
Simulations were conducted with an initial state of charge, SoCINI, set at 80%.The planned and actual changes in SoC are depicted in Figure 8.According to the objective function, the control discharges the storage during high purchase prices and charges it when purchase prices are low.As can be observed, the planning and control system behaves correctly, also fulfilling the condition of maintaining the final SoC at the specified level.For the presented planning day, the cost of energy drawn to the industrial microgrid without storage would amount to 1472 PLN.The planned economic effect is 100 PLN (6.7%), and the effect actually achieved by the plan maintenance algorithm is 103 PLN (6.7%).Simulations were conducted with an initial state of charge, SoC INI , set at 80%.The planned and actual changes in SoC are depicted in Figure 8.According to the objective function, the control discharges the storage during high purchase prices and charges it when purchase prices are low.As can be observed, the planning and control system behaves correctly, also fulfilling the condition of maintaining the final SoC at the specified level.For the presented planning day, the cost of energy drawn to the industrial microgrid without storage would amount to 1472 PLN.The planned economic effect is 100 PLN (6.7%), and the effect actually achieved by the plan maintenance algorithm is 103 PLN (6.7%).
The second case of analysis focuses on planning without restrictions on energy exchange with the distribution system.This means charging the storage with energy from the grid and discharging it to the grid when economically favorable is permitted.Allowing the interaction of the storage with the distribution grid has the advantage that during periods of low generation, there is the possibility to replenish the stored energy to the required level.The planning prepares the storage to discharge a maximum during high energy purchase prices.Charging, on the other hand, occurs during periods of low energy prices.
In this scenario, the activity related to energy sales prices is noticeable.The algorithm uses minor differences in sales prices to manipulate charging and discharging to enhance the economic effect (Figure 9).As a result, the planned economic effect amounts to 186 PLN (12.6%), whereas the execution by the control yields 159 PLN (10.8%).The course of planned SoC and the one realized by the control confirms increased storage activity, as shown in Figure 10.The second case of analysis focuses on planning without restrictions on energy exchange with the distribution system.This means charging the storage with energy from the grid and discharging it to the grid when economically favorable is permitted.Allowing the interaction of the storage with the distribution grid has the advantage that during periods of low generation, there is the possibility to replenish the stored energy to the required level.The planning prepares the storage to discharge a maximum during high energy purchase prices.Charging, on the other hand, occurs during periods of low energy prices.In this scenario, the activity related to energy sales prices is noticeable.The algorithm uses minor differences in sales prices to manipulate charging and discharging to enhance the economic effect (Figure 9).As a result, the planned economic effect amounts to 186 PLN (12.6%), whereas the execution by the control yields 159 PLN (10.8%).The course of planned SoC and the one realized by the control confirms increased storage activity, as shown in Figure 10.The second case of analysis focuses on planning without restrictions on energy exchange with the distribution system.This means charging the storage with energy from the grid and discharging it to the grid when economically favorable is permitted.Allowing the interaction of the storage with the distribution grid has the advantage that during periods of low generation, there is the possibility to replenish the stored energy to the required level.The planning prepares the storage to discharge a maximum during high energy purchase prices.Charging, on the other hand, occurs during periods of low energy prices.In this scenario, the activity related to energy sales prices is noticeable.The algorithm uses minor differences in sales prices to manipulate charging and discharging to enhance the economic effect (Figure 9).As a result, the planned economic effect amounts to 186 PLN (12.6%), whereas the execution by the control yields 159 PLN (10.8%).The course of planned SoC and the one realized by the control confirms increased storage activity, as shown in Figure 10.As demonstrated by the conducted research, good results are achieved for planning periods of one day or longer.However, this is associated with the risk of inaccurate forecasts, necessitating plan adjustments.Recalculating the plan can be triggered at any time in cases where current predictions deviate from the entered ones or when measured parameters deviate from the planned values, such as the state of charge.As demonstrated by the conducted research, good results are achieved for planning periods of one day or longer.However, this is associated with the risk of inaccurate forecasts, necessitating plan adjustments.Recalculating the plan can be triggered at any time in cases where current predictions deviate from the entered ones or when measured parameters deviate from the planned values, such as the state of charge.

Discussion and Conclusions
Managing a microgrid's energy storage system efficiently involves balancing economic conditions and technical constraints, making the objective function more complex.This paper presents a heuristic algorithm for scheduling energy storage, focusing on achieving optimal economic outcomes.A real-time control algorithm is also proposed to maintain the storage operation schedule.Two scenarios are explored for one day of planning and control based on measurements from a real industrial microgrid.Simulation results confirm that modern optimization techniques like PSO and well-defined objective functions effectively control microgrid ESS operations.
The research presented addresses the gaps identified in Chapter 1 by proposing a method to optimize ESS operation in a microgrid.This involves combining a recognized optimization algorithm from the literature with an objective function customized to fit the distinct needs of the industrial facility in question.The approach taken integrates technical and economic components.
The strengths of this research lie in the optimal adjustment of the parameters of the particle swarm optimization algorithm to solve the problem in question, the use of real parameters of both the grid and the energy storage system, and the implementation of the proposed algorithm in an actual industrial facility.Additionally, the authors considered numerous aspects of the objective function.The algorithm considered economic goals, such as reducing energy purchasing costs and maximizing energy sales profits.Additionally, it also considered technical requirements, such as maintaining the state of charge of the ESS for backup power.In comparison, most approaches in the literature focus on single or dual objective functions; they are also rarely applied in an actual plant.
The research carried out indicates that it is possible to control the energy storage system in such a way as to achieve an improvement in economic results under preset technical constraints.This translates into significant savings while not exposing the industrial facility to the losses associated with a power outage.In the article, the authors considered two scenarios.In the first case, a restriction was set on the energy exchange with the distribution system.The ESS could only charge itself with power from the photovoltaic plant.This control of the energy storage system saved 6.7% of the amount the industrial facility would have paid for energy.Both the planned and realized savings amounted to the same percentage.The second scenario allowed charging the ESS from the distribution system; the planned savings were 12.6%, while the actual savings due to existing conditions were 10.8%.The weak point of the presented approach is the length of the forecasts, which the authors had no control over.The problem was solved so that the algorithm automatically reacted to significant changes in the plan relative to the actual value, modifying the operation as new knowledge was provided.
To conclude, the article presents an approach applied to an actual industrial facility.By adjusting the objective function and selecting optimal PSO parameters, it was possible to solve a complex optimization problem that considered both technical and economic aspects.The complexity and adaptability of the proposed approach make it applicable to other facilities as well.Another advantage is its compatibility with the new net-billing energy law in Poland, enabling microgrid energy control in line with current market conditions.
Future work could involve further developing the ESS control algorithm to adapt it to the current needs of industrial partners.Work must also be carried out on the discrepancy between the actual state and the forecast.The authors are considering introducing a forecasting algorithm into the ESS control algorithm so that the operation of the driver itself is not significantly prolonged.

Figure 1 .
Figure 1.A simplified diagram of the analyzed microgrid.

Figure 1 .
Figure 1.A simplified diagram of the analyzed microgrid.
illustrates a typical ESS profile.Sustainability 2023, 15, x FOR PEER REVIEW 5 of 16stems from storage technology and Battery Management System (BMS) algorithms, which manage cell operations by responding to temperature changes, voltage, current levels, charge status, cell degradation, and more.The profile also establishes the discharge threshold, set at 20% in accordance with the storage unit manufacturer's instructions, accounting for the system's backup function during outages as a UPS.Figure2illustrates a typical ESS profile.

Figure 2 . 1 Figure 2 .
Figure 2. ESS charging and discharging characteristics.Algorithm 1: The Characteristic function constrains the specified charging and discharging power values.This function is invoked by the ESS work plan calculation algorithm and the real-time power control algorithm for the storage system.Algorithm 1 Characteristics

Algorithm 1 : 1
The Characteristic function constrains the specified charging and discharging power values.This function is invoked by the ESS work plan calculation algorithm and the real-time power control algorithm for the storage system.Algorithm Characteristics function P ST = match_P ST (T, E ST MAX , P ST MAX , SoC MIN , SoC, @char, P ST ) P ST CH EN = E ST MAX (1-SoC)/T; % charging power based on available ESS energy P ST DI EN = E ST MAX (SoC MIN -SoC)/T; % discharging power based on available ESS energy P ST CH CH = @char(E ST MAX, P ST MAX ,SoC); % charging power based on ESS characteristics P ST DI CH = @char(E ST MAX, P ST MAX ,SoC); % discharging power based on ESS characteristics if P ST > 0 P ST = min{P ST , P ST CH EN , P ST CH CH } % charging else P ST = max{P ST , P ST DI EN ,P ST DI CH } % discharging end

Figure 3 .
Figure 3. Energy market price changes (C MA ) and distributor tariff (C DS ) on 1 June 2023.

Figure 4 .
Figure 4. Relationships between selected two variables for the 24-dimensional objective function F1.

Figure 4 .
Figure 4. Relationships between selected two variables for the 24-dimensional objective function F 1 .

Figure 5 .
Figure 5. Plan of microgrid power flows on 1 June 2023.PGE-generation power, PLO-load power, PDS FOR-forced energy exchange power with the DS, PST-power of ESS.

Figure 5 .
Figure 5. Plan of microgrid power flows on 1 June 2023.P GE -generation power, P LO -load power, P DS FOR -forced energy exchange power with the DS, P ST -power of ESS.

Figure 7 .
Figure 7.Comparison of power profile of energy exchange with distribution system, planned (−PDS FOR), real without ESS (PGE + PLO) and with ESS (−PDS)-Case 1.

Figure 6 .
Figure 6.Microgrid power flows on 1 June 2023.P GE -generation power, P LO -load power, P DS -energy exchange power with the DS, P ST -power of ESS.

Figure 7 .
Figure 7.Comparison of power profile of energy exchange with distribution system, planned (−PDS FOR), real without ESS (PGE + PLO) and with ESS (−PDS)-Case 1.

Figure 7 .
Figure 7.Comparison of power profile of energy exchange with distribution system, planned (−P DS FOR ), real without ESS (P GE + P LO ) and with ESS (−P DS )-Case 1.

Figure 8 .
Figure 8. Changes in the state of charge of ESS on 1 June 2021.SoC 1 s-real, SoC 1 h-plan.Case 1.

Figure 8 .
Figure 8. Changes in the state of charge of ESS on 1 June 2021.SoC 1 s-real, SoC 1 h-plan.Case 1.

Figure 9 .
Figure 9.Comparison of power profile of energy exchange with distribution system, planned (−P DS FOR) , real without ESS (P GE + P LO ) and with ESS (−P DS) )-Case 2. Sustainability 2023, 15, x FOR PEER REVIEW 14 of 16

Figure 10 .
Figure 10.Changes in the state of charge of ESS on 1 June 2021.SoC 1 s-real, SoC 1 h-plan.Case 2.

Figure 10 .
Figure 10.Changes in the state of charge of ESS on 1 June 2021.SoC 1 s-real, SoC 1 h-plan.Case 2.