Optimal Battery Dispatch Using Finite-Input Set Non-Linear Model Predictive Control: Algorithm Development and Case Study

: The advancement in battery manufacturing has played a signiﬁcant role in the use of batteries as a cost-effective energy storage system. This paper proposes an optimal charging and discharging strategy for the battery energy storage system deployed for economic dispatch and sup-ply/demand balancing services in the presence of intermittent renewables such as solar photovoltaic systems. A decision-making strategy for battery charge/discharge operations in a discrete-time rolling horizon framework is developed as a ﬁnite-input set non-linear model predictive control instances and a dynamic programming procedure is proposed for its real-time implementation. The proposed scheme is tested on controllable loads and a photovoltaic generation scenario in the premises of a sports centre, as a part of a pilot demonstration of the inteGRIDy EU-funded project. The test results conﬁrm that the implemented stacking of the battery and optimal decision-making algorithm can enhance net saving in the electricity bill of the sports centre, and lead to corresponding CO 2 reductions.


Motivation
Decarbonisation, digitalisation and decentralisation are transforming energy systems across all continents and supporting the sustainability drive in both industry and society. Smart grids are a predominant feature in this respect and are essentially electrical grids that include a variety of interoperable communication and control devices to optimally (or near-optimally) facilitate the production and distribution of electricity. Smart grids allow for better integration and management of volatile renewable energy sources, flexible transmission resources, energy storage devices, electric vehicles, microgrids and controllable loads; they are key enablers in the decarbonisation of both industry and society [1]. This article is concerned with the use of localised digital control and optimization techniques applied to distributed energy storage devices, within a wider smart grid context. Battery energy storage systems (BESS) play a significant role in improving grid stability, and when employed locally can help increase the efficiency and effectiveness of potentially volatile distributed generation units (DGs) such as solar panels and wind turbines through provision of local buffering services [2]. BESS have gained continuous research attention due to these features and given substantial advancement in battery technologies and increasing decentralisation of grid operations, localised controls are receiving much attention [2,3]. This has resulted in the introduction of various battery control and management algorithms, and led to the development of batteries with an increased capacity-to-size ratio featuring faster charging and discharging rates, longer life spans and relatively lower prices [2,4,5]. The main parts of the BESS are the charge/discharge decision-making algorithms which are required to ensure optimum use of the battery and maximise the utilisation of the DGs over a given period, and the monitoring and state estimation techniques which are deployed for battery situational awareness and degradation analysis [1]. Although there have been many developments in research in these areas, to date there has been, with some exceptions, a noticeable lack of technology transfer beyond laboratory prototypes and into real-world implementations of more advanced sensing, estimation, and charge controls for BESS [2].
As argued above, smart microgrid energy systems based on renewables are the key players in meeting the rising demand for electricity while maintaining greenhouse gases (GHG) emissions at acceptable levels. Due to technological advancement and declining prices solar photovoltaic (PV) panels, in particular, have become increasingly popular in climates with suitable insolation levels. This is evidenced in the total PV capacity installed globally, which increased from 40 to 219 GW between 2010 and 2015 and about 7% of the total global energy generation in 2020 [6]. Power grids, on the other hand, face challenges in integrating electrical power generated by renewable energy resources (RES) such as solar panels and wind turbines. Among other complexities, the availability of RES power depends on natural resources that are uncontrollable by humans, which brings more complexity to the management of the power generation systems. Although BESS can provide buffering solutions in these situations, to achieve maximum benefits then efficient monitoring and degradation-aware charge dispatch algorithms are required for operation in real-world environments with fluctuations in energy prices, local supply availability, and local demands.

Related Work
The control of distributed energy storage devices in smart grid applications involves the coordinated management of many smaller energy storages, typically embedded within microgrids or sub-networks in a wider, grid-of-sub-microgrids situation [2]. There has been much recent interest related to controlling aspects of supporting power-sharing balance and sustainability, increasing system resilience and reliability, and balancing distributed state of charge; please refer to Al-Saadi et al. for a recent comprehensive review of this area [2]. In general, control of energy storage mechanisms can be sub-divided into decentralized, centralized, multiagent, and intelligent/optimal control strategies [2]. A potentially large range of services can also be provided by these storages, each having differing control complications and complexity of proposed solutions.
The typical standard hierarchical control architecture of a decentralised, system-ofsystems (grid-of-microgrids) model network with storage can be classified into three typical levels, which relate to hierarchical and specific regulatory roles in an AC-connected, DCbus based-microgrid [2]. These control levels provide specific services, and are broadly explained as follows: (1) Primary Control: The objective is to regulate the load sharing of distributed energy resources and storage via the local control of output voltage and frequency to attain balanced and autonomous operation of these distributed systems [7,8]. The prototypical strategy is droop control, which dispatches local storage based upon local active and reactive power estimates and frequency voltage/measurements and requires no time-critical communication to a centralised entity [9]. (2) Secondary Control: Secondary control has the responsibility of correcting system-wide voltage and frequency offsets that are achieved by the primary control. Therefore, and an entity to play the role of a system-wide or local system state observer to provide trim commands for the primary control is required. Reactive power-sharing, accurate frequency regulation and PQ compensation are prototypical services provided, using trim commands for frequency and voltage [10,11]. Typically, time-critical communication to a centralised entity playing the role of system-wide observer is required [9]. In a decentralised (or partially decentralised) solution, communications to a central entity are not required (or kept to a minimum) at the expense of added local complexity. (3) Tertiary Control: This is the highest control level of the control hierarchy. Tertiary Control is typically liable for managing gross active and reactive power entering or leaving the local microgrid, to solve system-wide optimal power flow problems and constraints (OPF) [12]. Again, an entity to play the role of a system-wide state observer is required to solve the OPF and provide local power flow commands. Again timecritical communication to a centralised entity playing the role of system-wide observer is required [9]. In a decentralised (or partially decentralised) solution, communications to a central entity are not required (or kept to a minimum) at the expense of added local complexity.
In the context of the current work, the focus is upon partially decentralised control of BESS to support system resilience and integration of renewables and is principally concerned with tertiary controls in which the BESS is dispatched locally to meet systemwide balancing constraints. In this situation, the only communication requirement to a central entity is intermittent, soft-real time and is related to market-based price signals for importing/exporting energy. Loads and local renewable supply are forecasted locally, and the storage is dispatched based upon the solution of a local real-time economic dispatch algorithm which takes storage degradation into account.
With respect to similar previous works in the area, in [13,14] solar PV and battery storage along with operation scheduling algorithms were implemented, wwhereas BESS without RES generation was also presented by authors in [15]. The battery is charged from the grid when the demand is low and discharged when the demand increases. By utilizing BESS, power generation sources can be run at optimum, while the energy storage accounts for variation in the demand. BESS should be of a suitable range of storage and power capacity to function over the required duration and can react instantaneously to the grid demand variations.
Technologies such as compressed air energy storage facilities [16], flywheels [17,18], etc., have been developed for the purpose of storing large-scale energy generation. However, some of these technologies are limited in their site dependence and response capabilities. Among the different types of energy storage, batteries have relatively higher energy efficiency and offer flexible configurations for different application requirements without geographical conditions [19]. The advancement in newer battery chemistries has enabled a wide range of battery options for storage applications. Although at present, BESS accounts for a small portion of energy storage within the grids, they are seen as an irreplaceable option in distributed new energy integration and ancillary grid operations [20,21]. BESS is required to store electricity; the stored electricity can then be used when needed with the aim to reduce the electricity consumption cost and peak loads by increasing the penetration rate of RES and maximizing the self-consumption of its production. The electrical power is stored when it is available and/or price is low and used when it is unavailable and/or price is high. To achieve the optimum operation of the BESS, an optimal schedule algorithm is required to decide when to charge, discharge or hold (no charge and no discharge) the battery. The algorithm should consider electricity consumption, RES generation and electricity prices.
With the increasing development and widespread deployment of electrical vehicles (EVs), the idea of using EV batteries as portable power storage systems have been proposed. The EVs' batteries are used to store electricity when the EV is parked and then the stored electricity can be used to balance the grid. Storing electricity when there is a surplus and selling electricity back into the grid when there is a wider demand. A considerable amount of research has been done to investigate the applicability of this approach and a significant number of BESS has been proposed with the aim is to maximize the benefits to grid operators and EV owners. As such, BESS is considered the fastest growing type of energy storage technology [22]. However, most of these studies have considered aspects and limitations that are directly related to the use of the EVs such as the habits and preferences of the EVs' owners as well as travel and waiting time [23,24]. To ensure the performance and safe use of the EV batteries, they must be electrically and terminally monitored and controlled and accurate models to predict working voltage, capacity, SoC and SoH are needed [25]. These functionalities are commonly implemented within the BESS. However, as discussed in [2] and other works above, although many highly sophisticated control and monitoring mechanisms for BESS have been proposed, in terms of wide-scale deployment, advanced techniques capable of real-time operation have progressed little beyond the laboratory due to complexities involved in reliable implementation on potentially resourceconstrained field devices. There is clearly a pressing need to address this issue if progress is to be made on realising the potential of distributed and (partially or fully) decentralised BESS in real-world situations.

Contributions
In this paper, an efficient rolling-horizon decision-making algorithm for optimal charging and discharging for a BESS is proposed, implemented using dynamic programming and studied in a real-world case study. The system is designed to operate under the variabilities of electricity pricing, consumption loads and renewable generation output, and to integrate with monitoring mechanisms and implement degradation-aware control features in a partially or fully decentralised system-of-systems-based smart grid solution. A generic decision-making strategy for battery charge/discharge operations in a discretetime rolling framework is developed as a finite-input set of non-linear model predictive control (MPC) instances and a dynamic programming (DP) procedure is proposed for its real-time implementation. To progress beyond a laboratory prototype, the technique has been implemented, tested, and validated in the premises of a sports centre located at Rambla del Celler, in Sant Cugat, Barcelona, as a part of a pilot demonstration of the inteGRIDy EU-funded project. The aim of the proposed case-study system is to reduce the electricity bills of the sports centre and increase self-consumptions, thus, making the objective of the work carried out unique in its formulation. Our findings indicate that (i) the proposed technique is simple enough to be implemented on resource-constrained field devices and operate with required sample times for typical BESS requirements, and that (ii) the algorithm implementation achieved non-trivial reductions (≈15%) in energy costs and CO 2 emissions. We conclude the proposed generic scheme is a promising candidate to support partially decentralised control of BESS for services related to system resilience and integration of renewables.

Structure
The rest of the article is organized as follows: Section 2 states assumptions and describes the generic battery model which is employed and describes the mathematical formulation of the decision-making algorithm framework and its implementation. Section 3 presents the case studies, focusing on the description of the pilot site and use case specification. In Section 4, the results and analysis are presented. Section 5 concludes the paper, followed by references.

Methodology
As discussed in the introduction, in the context of the current work we assume a situation in which partially decentralised tertiary charge/discharge controls of a BESS to support system resilience and integration of renewables is required in real-time. It is assumed that forecasts of local renewable supply availability and local demands are available (see e.g., [26] and other works on forecasting), prices to import/export energy to the wider grid are available, and that the charge dispatch controls are to be integrated with a BESS SoC/SoH monitoring system. The solution we propose is a tertiary control service in nature and can easily be vertically integrated into decentralised or partially decentralised primary and secondary control schemes, as required.

Model and Assumptions
Consider a discrete-time framework in which the battery SoC is represented at each discrete time-step k = 0, 1, 2, 3, 4, 5, . . . by the non-negative real variable C(k) ≥ 0, with units kWh. Consider that a source/sink node is connected locally to the battery, and the corresponding source/sink power level is represented by the real variable L(k), with units kW such that a positive L(k) indicates a local node demand, while a negative L(k) represents a local node supply-such as may occur in the presence of local renewable supply exceeding local demand. The battery and local node are also connected to a grid which may source or sink energy at each time step k at corresponding cost P(k, x), where the function P(k, x) returns the economic cost of delivering power demand x kW during time step k, with € units. Appropriate definition of the generic function P(k, x) for a constant sampling time interval ∆ between any discrete steps k and k + 1 allows for the implementation of many forms of electricity pricing structures, including time of use (ToU), real-time pricing (RTP) and 2-tier pricing (2TP) [20]. The presence of feed-in-tariffs (FITs) can also be included, and within a rolling horizon context, interactions with a wider balancing market and/or ancillary services market and specific demand response (DR) events can be implemented by an appropriate online, dynamic generation of the form and co-efficient of P(k, x), for appropriate values of k across the future considered horizon [27,28].
We consider the evolution of the SoC of the battery between each discrete time step to be given by the general non-linear model: For appropriate functions f and g, and charge/discharge (control) signal u(k), with units kW. In this work, we assume that the control signal u(k) is discrete in nature and restricted to be drawn from a finite set of charge/discharge levels, such that: Typically, in many applications, the set U will have a cardinality of three, representing charge input of ∆c kW, discharge input of ∆d kW, and hold input of zero. Capacity constraints on the battery must also be present, which can be represented by the expressions in (3): In other words, the battery cannot hold more than its maximum capacity charge or less than its minimum. We also consider that during lifetime operation, under repeated cycling of charge/discharge operation, the battery will experience degradation. This degradation has multiple root causes, mostly electro-chemical and mechanical in nature, and previous work has indicated that these effects should be incorporated into any longterm optimization formulation or modeling exercise [29]. Under the assumption that the battery is operated in near-constant temperature conditions, the principal mechanism of capacity loss is due to repeated charge/discharge cycles over a given time period [29]. In order to provide a means to control such behavior, define the following binary indicator variables I(k) to signal changes in input (charging) state:

Charge/Discharge Optimization
The objective of this discrete-time battery optimization problem is to minimize the lifetime economic cost associated with serving the load using grid-sourced energy, by making intelligent decisions regarding charging and discharging of the battery, within its operational limit. For practical purposes, a rolling-horizon non-linear Model Predictive Control (MPC) with finite discrete input set has been developed (see, e.g., [30] for an overview of MPC). The optimization problem to be solved at each discrete-time step k is the minimization of the following multi-stage non-linear cost function: Minimize: with respect to u(k + i), ∀i = 0, 1, 2, 3, 4, . . . H, subject to model Equations (1), input state set decisions (2), capacity constraints (3), indicator variable constraints (4), and for suitably defined electricity pricing functions P(k + i, x). The integer H represents the length of the prediction horizon under consideration. Note that at each step k, the exact load balance L(k + i) is not known exactly and must therefore be forecasted. Known techniques for this can be applied, and this is not considered further in this section. The optimization minimizes the economic costs of serving the predicted load at each time over the prediction horizon, in conjunction with the economic cost of cycling the battery due to degradation loss. Translation from economic costs to emissions costs (or a weighted combination of both) is relatively straightforward: equivalent CO 2 emissions costs at each time step k can be incorporated into the cost functions P(k, x). Such data is now becoming available digitally from regional and national electricity network operators (e.g., see Carbon intensity API, https://carbonintensity.org.uk/ (accessed on 5 September 2020)). Under certain restrictions, the optimization problem described above is easily formulated as a mixed integer linear program (MILP) [31,32]. Alternatively, the dynamic programming (DP) method could be applied (Bellman,[33]). DP is a computational method for solving optimal control problems with separable, additive performance indices. It is based on the recursive application of Bellman's 'Principle of Optimality': An optimal policy has the property that whatever the initial state and the initial decision are, the remaining decisions must form an optimal policy with regard to the state resulting from the first decision.
The mathematical form of this idea can be expressed as a backward sequence featuring the solution of simpler optimization problems at each stage. Continuing backward from the end stage N to the current stage k-and applying the principle of optimality at each stage-will result in the following recurrence relations for discrete DP [34]: where J k (x k ) is the cost of entering stage k with state x k , g k (x k ) is the cost for entering stage k with state x k , U k (x k ) is the set of allowed controls for the input u k when the state x k is entered at stage k, and f k (x k , u k ) is a function which maps the state x k onto state x k+1 when control and control u k is applied at step k. In discrete DP (DDP), the state vector is mapped onto a grid of size S and the controls onto a grid of size U. By iterating through the recursion and trying all admissible control values at each admissible set of state values, a vastly reduced search space is explored when compared to a pure brute-force search; at the end of the minimization, a solution grid is obtained and the optimal control is obtained from the position in the grid corresponding to the current state.
In this current context, the state variable is the SoC C(k). The admissible controls are the set U, which in most cases have three possibilities which are charge, hold, and discharge (|U| = 3). For a first-order non-linear battery model, the SoC can be mapped into a discrete grid over a suitable working range, e.g., 10-90% of battery capacity, having Cardinality |C|; the control is already discrete in nature. During the recursion, the minimal cost function is stored for each admissible state along with the final component of the objective function. Thus, the run-time complexity of the DDP algorithm is given by O(H.|U|.|C|), and the algorithm runs efficiently even for a relatively large prediction horizon H = 96 (e.g., 24 h with ∆ = 15 min) and |C| = 1000 (e.g., charge state represented to 0.1% accuracy), which in general gives very accurate results. For many applications involving grid energy storage, a sampling time requirement of approximately fifteen minutes is sufficient for battery dispatch. The algorithm has been coded in embedded C using good practice guidelines [35]. Testing has shown that execution times of order one second are achievable on a modern 32-bit ARM microcontroller platform, making the approach suitable for deployment without undue problems in small, modern embedded systems. A flowchart shows a diagrammatic representation of the algorithm is presented in Figure 1. The diagram describes the data required by the algorithm and also provides a breakdown of the essential steps to solving the optimisation problem.

Description of the Pilot Site
The pilot demonstration is aimed at analyzing the increase of on-site self-sufficiency (the available storage solutions and on-site PV generation) and the interaction between the grid. The pilot site, shown in Figure 2, is a swimming pool with a sports centre located at Rambla del Celler, in Sant Cugat, Barcelona, Spain. To test the BESS in a real operation scenario, a PV system with electrical storage and monitoring devices for building energy management were added to the energy system of the swimming pool. In this section, the technical specifications of these components will be described.

Description of the Pilot Site
The pilot demonstration is aimed at analyzing the increase of on-site self-sufficiency (the available storage solutions and on-site PV generation) and the interaction between the grid. The pilot site, shown in Figure 2, is a swimming pool with a sports centre located at Rambla del Celler, in Sant Cugat, Barcelona, Spain. To test the BESS in a real operation scenario, a PV system with electrical storage and monitoring devices for building energy management were added to the energy system of the swimming pool. In this section, the technical specifications of these components will be described. The swimming pool energy system is monitored with a SCADA system and comprises a boiler, heat pump, and air handling unit (AHU). Besides the physical equipment installed in the sports centre, i.e., the PV system components and energy metering, temperature and humidity sensors, the pilot incorporates a comprehensive set of virtual tools and software modules developed for its realization. The general physical view of the pilot site is presented in Figure 3, and the main components of the BESS are in Figure 4. The swimming pool energy system is monitored with a SCADA system and comprises a boiler, heat pump, and air handling unit (AHU). Besides the physical equipment installed in the sports centre, i.e., the PV system components and energy metering, temperature and humidity sensors, the pilot incorporates a comprehensive set of virtual tools and software modules developed for its realization. The general physical view of the pilot site is presented in Figure 3, and the main components of the BESS are in Figure 4.
The BESS under test consists of a PV with a total capacity of 5.025 kWp, an inverter with 96.6% efficiency and a lithium-ion battery with a total nominal capacity of 1080 Ah. The PV modules are manufactured by JA Solar (Beijing, China) and consist of high-performance monocrystalline silicon panels. The corresponding technical parameters are presented in Table 1. The electrical characteristics correspond to standard test conditions (STC) (irradiation of 1000 W/m 2 , air mass (AM) spectrum 1.5 and a cell temperature of 25 • C). A total of 15 panels arranged in two arrays of seven and eight modules were installed on the rooftop of the sports centre at 41.47008 • latitude and 2.08408 • longitude. The total panels' area was 25.5 sqm and the slop and azimuth were 10 • and 31 • respectively.
A Sunny Boy solar inverter from SMA (Niestetal, Germany) is used to connect the two arrays of PV panels to the swimming pool energy system. The inverter is the PV system component responsible for transforming the direct current (DC) generated by the PVs into alternating current (AC) that can be fed into the grid. The technical parameters of the inverter are presented in Table 2 below. The inverter is occupied with built-in overvoltage protection, insulation and automatic disconnection in case of out-of-range voltage or frequency.   The BESS under test consists of a PV with a total capacity of 5.025 kWp, an inver with 96.6% efficiency and a lithium-ion battery with a total nominal capacity of 1080 A The PV modules are manufactured by JA Solar (Beijing, China) and consist of high-p formance monocrystalline silicon panels. The corresponding technical parameters are p sented in Table 1. The electrical characteristics correspond to standard test conditio    The BESS under test consists of a PV with a total capacity of 5.025 kWp, an inverter with 96.6% efficiency and a lithium-ion battery with a total nominal capacity of 1080 Ah. The PV modules are manufactured by JA Solar (Beijing, China) and consist of high-performance monocrystalline silicon panels. The corresponding technical parameters are presented in Table 1. The electrical characteristics correspond to standard test conditions  The battery storage system is composed of 96 lithium-ion battery cells connected in a 16s6p scheme and a battery manager. The battery bank is connected in a way that each six battery cells is connected in parallel to form 6p, and then connected in series to make 16s. This grants a total nominal capacity of 1080 Ah and a nominal voltage of 51.2v. The technical parameters of the battery bank and of the individual battery units are presented in Table 3. A Sunny Island 6.0H (bidirectional energy storage inverter) battery manager is used for battery charging and discharging management. Internal control and status variables of the unit, including SoC measurements and charge/discharge command state, are accessible via Modbus. The unit is capable of precisely determining the SoC of the battery attached to it. Different three methods are combined and used by the unit for estimation of the SoC, the unit reaches a measuring accuracy of more than 95%.

Use Case Specification
The aim of the use case is to maximize self-consumption of the PV generation, minimize the electricity bill for the swimming pool and improve grid stability. A neighborhood energy management and optimization tool (NEMO) has been developed to implement the use case. It consists of software components to optimize the use of the PV and battery, as well as modules to support communications with other tools that are used in energy management such as SCADA, Web services, IEC-104, and OpenADR. The general structure of the NEMO tool is shown in Figure 5. The PV generation forecasts and decision-making and optimization algorithm described in Section 2 are the main components of the NEMO tool and are utilized to optimize the scheduling of charging and discharging decisions of the battery. For the NEMO functionality, the tool reads the weather forecast and consumptions forecast of the swimming pool as well as the electricity prices and status of the battery from the reference knowledge warehouse (RKW). RKW is a time series database module used to store the real time data associated with pilot site operation, configuration, settings and environment. The RKW retrieves the weather forecast and electricity price from external providers, the battery status, PV generation and swimming pool consumptions from the SCADA system. The RKW also receives the PV generation forecast from NEMO and the swimming pool consumptions forecast from the distributed energy management system (DEMS) tool. DEMS is one single system developed by Siemens (Munich, Germany) to manage demand and supply of distributed energy resources for a wide variety of use cases.

Results and Analysis
The data and results of the optimization and decision-making algorithm from 12 April 2021 to 21 July 2021 are reported and analyzed in this section. To describe the functionality of the BESS, snapshots of the main parameters of the swimming pool energy system are also presented. The total electricity consumption of the swimming pool during the reporting period was 13,853.67397 kWh. The daily electricity consumption in most days ranges from 50 and 225 kWh/day, it usually starts to increase at 8 am and decrease at 8 pm with an almost a flat peak of 3.5 kWh between 10 am and 6 pm. A snapshot of the daily electricity consumption of the pool during the period between 13.04.2021 and 30.06.2021 is shown in Figure 6.
The price of electricity was changed several times during the reporting period and different tariff systems were used. Between 12 April and 30 April 2021, a two-tier pricing system was implemented, with energy priced at 0.06177 €/kWh from 00:00 to 08:00 am With the PV and battery information, the battery model of NEMO computes the battery charging and discharging time and the PV model computes the PV generation forecast. Subsequently, the decision-making and optimization algorithm decide whether to charge, discharge or hold the battery considering the electricity price and swimming pool consumption. The decision is then sent to the RKW in a form of a status order. The RKW converts the status order to a control signal which is sent via SCADA to instruct the battery to act accordingly. Since the configuration and settings of the battery and PV are almost fixed for the pilot site, they are stored locally in plain text format files. The data relating to the pilot operation is time-series data that consists of potentially very large arrays of numbers that are indexed by a time variable. This data is stored remotely on the RKW.

Results and Analysis
The data and results of the optimization and decision-making algorithm from 12 April 2021 to 21 July 2021 are reported and analyzed in this section. To describe the functionality of the BESS, snapshots of the main parameters of the swimming pool energy system are also presented. The total electricity consumption of the swimming pool during the reporting period was 13,853.67397 kWh. The daily electricity consumption in most days ranges from 50 and 225 kWh/day, it usually starts to increase at 8 a.m. and decrease at 8 p.m. with an almost a flat peak of 3.5 kWh between 10 a.m. and 6 p.m. A snapshot of the daily electricity consumption of the pool during the period between 13 April 2021 and 30 June 2021 is shown in Figure 6.  The price of electricity was changed several times during the reporting period and different tariff systems were used. Between 12 April and 30 April 2021, a two-tier pricing system was implemented, with energy priced at 0.06177 €/kWh from 00:00 to 08:00 a.m. and 0.06559 €/kWh for the rest of the day; weekends had a fixed price of 0.06559 €/kWh. In May 2021, the prices were changed to 0.058388 and 0.06344 for weekdays and 0.058388 for weekends respectively. From 1 June, the pricing system was altered to a three-tier tariff, with 0.058043 €/kWh from 00:00 to 08:00 a.m., 0.06189 from 08:01 a.m. to 09:00 a.m., and 0.6869 from 09:01 a.m. to 15:00 a.m., then 0.061987 from 15:01 a.m. to the end of the day for weekdays, but remained at 0.058388 for weekends. On 15 June these prices were again changed to 0.05804, 0.08, 0.0891 and 0.08 for the periods 00:00 to 07:00 a.m., 07:01 to 10:00 a.m., 10:01 a.m. to 18:00, and 18:01 to end of the day respectively. The prices of electricity for the full testing period are shown in Figure 7. Daily energy consumption of the swimming pool complex. The consumption is measured every 15 min, every single point in the figure represents the sum of 96 measurements. In the zoomed area, hourly consumption for two days is shown, every four measurements are added to form the consumption of each hour in the day.

Figure 7.
Electricity prices of the swimming pool. The prices were changed several times during the testing period. A two-tier tariff system was used for April and May with 0.058388 lowest and 0.06559 highest. For June and July, a three-tier tariff system was used with 0.058043 lowest and 0.0891 highest. Figures 8 and 9 show snapshots of the operation of the BESS system. To visually illustrate the operation of the battery charging/discharging algorithm, different scales for the SoC, price, electricity consumption and PV output were used. No axis labels were used in the figures as they are just presented to clarify how the SoC of the battery follows the changes in the price, consumption and PV generation. As shown in Figure 8, the state of charge of the battery follows the price signal. When the price goes up, NEMO discharges the battery and the SoC goes down, and when the price goes down, NEMO charges the battery and the SoC goes up. Figure 9 shows another scenario of the operation when the . Electricity prices of the swimming pool. The prices were changed several times during the testing period. A two-tier tariff system was used for April and May with 0.058388 lowest and 0.06559 highest. For June and July, a three-tier tariff system was used with 0.058043 lowest and 0.0891 highest. Figures 8 and 9 show snapshots of the operation of the BESS system. To visually illustrate the operation of the battery charging/discharging algorithm, different scales for the SoC, price, electricity consumption and PV output were used. No axis labels were used in the figures as they are just presented to clarify how the SoC of the battery follows the changes in the price, consumption and PV generation. As shown in Figure 8, the state of charge of the battery follows the price signal. When the price goes up, NEMO discharges the battery and the SoC goes down, and when the price goes down, NEMO charges the battery and the SoC goes up. Figure 9 shows another scenario of the operation when the SoC signal follows the difference between the values of the PV output and the consumption of the pool. In this case, when the PV output was higher than the consumption of the pool NEMO charges the battery even if the price of the electricity was in higher tariff. SoC signal follows the difference between the values of the PV output and the consumption of the pool. In this case, when the PV output was higher than the consumption of the pool NEMO charges the battery even if the price of the electricity was in higher tariff.  . The decision-making and optimisation algorithm follows the price signal, charges the battery when the price is low and discharges when the price is high. Figure 9. The operation of the BESS (PV output is dominant). When the consumption of the swimming pool is lower than the PV generation, the decision-making and optimisation algorithm will charge the battery even if the price is high.
A snapshot of the cost of the electricity imported from the grid before and after the use of BESS is shown in Figures 10 and 11. In Figure 10, the cost of imported electricity with a 15-min granularity for the period between 12 April 2021 and 14 April 2021 is presented. In the figure, it can be seen that the cost of electricity consumption after applying the BESS solution is sometimes higher or lower than the cost before applying the solution. This is to be expected as the electricity imported from the grid increases when the battery is charged and decreases when the battery is discharged. The cost saving is achieved as SoC Price Consumption PV Generation

SoC
Consumption PV Generation Price Figure 9. The operation of the BESS (PV output is dominant). When the consumption of the swimming pool is lower than the PV generation, the decision-making and optimisation algorithm will charge the battery even if the price is high.
A snapshot of the cost of the electricity imported from the grid before and after the use of BESS is shown in Figures 10 and 11. In Figure 10, the cost of imported electricity with a 15-min granularity for the period between 12 April 2021 and 14 April 2021 is presented. In the figure, it can be seen that the cost of electricity consumption after applying the BESS solution is sometimes higher or lower than the cost before applying the solution. This is to be expected as the electricity imported from the grid increases when the battery is charged and decreases when the battery is discharged. The cost saving is achieved as NEMO increases the imported electricity when the rates are low and/or the electricity generated by the PV system is also low and decreases imported electricity when the electricity rates are high and/or the electricity generated by the PV system is also high. The amount of the remuneration depends on the differences in electricity rates, the amount of electricity produced by the PV system and battery specifications. In future work, a simulation study will be performed to quantify the impact of various parameters such as maximum battery capacity, charge/discharge rate and PV system output power profile on the energy cost savings achieved by the proposed algorithm. The aim is to optimise these parameters in order to obtain the best specification of PV and battery that maximize the energy cost savings.
To measure the impact of the BESS on the electricity cost of the swimming pool, the 15 min measured data are aggregated and the equations below are used: cost saving = cost withoutBESS − cost withBESS (9) where EI is the electricity imported from the grid, PV is the electricity generated by the PV system and ∆SoC is the change in the state of charge of the battery and given by: where P is the price of the electricity imported from the grid and n is the number of measured data points, 96 measured points for each day.
NEMO increases the imported electricity when the rates are low and/or the electricity g erated by the PV system is also low and decreases imported electricity when the electric rates are high and/or the electricity generated by the PV system is also high. The amou of the remuneration depends on the differences in electricity rates, the amount of electr ity produced by the PV system and battery specifications. In future work, a simulat study will be performed to quantify the impact of various parameters such as maximu battery capacity, charge/discharge rate and PV system output power profile on the ener cost savings achieved by the proposed algorithm. The aim is to optimise these paramet in order to obtain the best specification of PV and battery that maximize the energy c savings. Figure 10. Cost of imported electricity at 15 min granularity. The cost of imported electricity w and without BESS is shown. The cost with BESS is higher than the cost without BESS when the BE charges the battery and lower when discharges the battery.
To measure the impact of the BESS on the electricity cost of the swimming pool, 15 min measured data are aggregated and the equations below are used: where EI is the electricity imported from the grid, PV is the electricity generated by the system and ∆ is the change in the state of charge of the battery and given by: where P is the price of the electricity imported from the grid and n is the number of me ured data points, 96 measured points for each day. The daily cost of imported electricity with and without the BESS for the period fr 13.04.2021 to 30.05.2021 is shown in Figure 11. As the figure reveals, there is a visible d ference between the daily baseline cost of energy consumption and the daily cost af implementing BESS in the swimming pool. A summary of the results obtained from the swimming pool after the implementation of the BESS is reported in Table 4. A percentage difference in the electricity cost saving of 19.65% was obtained after optimal scheduling of the use of the battery and use of the PV system. The reduction in the imported electricity from the grid during this period was 2335.33 kWh resulting in a reduction of 16.88% of the imported electricity consumption of the swimming pool and an increase in self-consumption. Subsequently, the achieved total reduction in the CO2 emission amounted to 772.99 KgCO2 (emission factor is 0.331) With BESS Without BESS Figure 11. The daily cost of imported electricity before and after the use of BESS. The consumption is measured every 15 min, every single point in the figure represents the total consumption of one day (sum of 96 measurements).
The daily cost of imported electricity with and without the BESS for the period from 13 April 2021 to 30 May 2021 is shown in Figure 11. As the figure reveals, there is a visible difference between the daily baseline cost of energy consumption and the daily cost after implementing BESS in the swimming pool.
A summary of the results obtained from the swimming pool after the implementation of the BESS is reported in Table 4. A percentage difference in the electricity cost saving of 19.65% was obtained after optimal scheduling of the use of the battery and use of the PV system. The reduction in the imported electricity from the grid during this period was 2335.33 kWh resulting in a reduction of 16.88% of the imported electricity consumption of the swimming pool and an increase in self-consumption. Subsequently, the achieved total reduction in the CO 2 emission amounted to 772.99 KgCO 2 (emission factor is 0.331).

Summary and Conclusions
In this article, it has been proposed that there is a pressing need to innovate and implement efficient BESS monitoring and control algorithms for real-time field deployment if progress is to be made on realising the potential of BESS in practice. An efficient rolling-horizon decision-making algorithm for optimal charging and discharging for a BESS has been proposed, implemented using dynamic programming and studied in a real-world case study. The technique has been implemented, tested, and validated in the premises of a sports centre located at Rambla del Celler, in Sant Cugat (Barcelona, Spain) as a part of a pilot demonstration of the inteGRIDy EU-funded project. The aim of the proposed case-study system is to reduce the electricity bills of the sports centre and increase self-consumptions, thus, making the objective of the work carried out unique in its formulation. Our findings indicate that: (i) the proposed technique is simple enough to be implemented on resource-constrained field devices and operate with required sample times for typical BESS requirements, and that (ii) the algorithm implementation achieved nontrivial reductions (≈15%) in energy costs and CO 2 emissions. We conclude the proposed generic scheme is a promising candidate to support partially decentralised control of BESS for services related to system resilience and integration of renewables. We also caution that further work is needed to further validate the system and to fully quantify the benefits obtained in larger case studies, and this is an area of ongoing work. Funding: The work presented in this paper was carried out as part of inteGRIDy project, co-funded by the EU's Horizon 2020 framework program for research and innovation under grant No. 731628. The authors wish to acknowledge the European Commission for their support, the efforts of the project partners and the contributions of all those involved in the inteGRIDy project.

Data Availability Statement:
The data that supports the findings of this study are available from the inteGRIDy consortium through the first author, but restrictions apply to the availability of these data which were used under license for the current study and so are not publicly available.

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