Improving the Efﬁciency of Renewable Energy Assets by Optimizing the Matching of Supply and Demand Using a Smart Battery Scheduling Algorithm

: Given the fundamental role of renewable energy assets in achieving global temperature control targets, new energy management methods are required to efﬁciently match intermittent renewable generation and demand. Based on analysing various designed cases, this paper explores a number of heuristics for a smart battery scheduling algorithm that efﬁciently matches available power supply and demand. The core of improvement of the proposed smart battery scheduling algorithm is exploiting future knowledge, which can be realized by current state-of-the-art forecasting techniques, to effectively store and trade energy. The performance of the developed heuristic battery scheduling algorithm using forecast data of demands, generation, and energy prices is compared to a heuristic baseline algorithm, where decisions are made solely on the current state of the battery, demand, and generation. The battery scheduling algorithms are tested using real data from two large-scale smart energy trials in the UK, in addition to various types and levels of simulated uncertainty in forecasts. The results show that when using a battery to store generated energy, on average, the newly proposed algorithm outperforms the baseline algorithm, obtaining up to 20–60% more proﬁt for the prosumer from their energy assets, in cases where the battery is optimally sized and high-quality forecasts are available. Crucially, the proposed algorithm generates greater proﬁt than the baseline method even with large uncertainty on the forecast, showing the robustness of the proposed solution. On average, only 2–12% of proﬁt is lost on generation and demand uncertainty compared to perfect forecasts. Furthermore, the performance of the proposed algorithm increases as the uncertainty decreases, showing great promise for the algorithm as the quality of forecasting keeps improving.


Introduction
The renewable energy market is growing at a rapid pace and its development is fundamental for reaching global climate targets [1][2][3][4]. Yet, advancement is not solely made by investments and expansion of renewable energy generation capacity, but also by thoroughly understanding existing energy needs in order to optimize efficiency and ultimately reduce the carbon intensity of generation and gain benefits for prosumers (small-scale consumer with microgeneration and/or storage) [5,6]. In order to achieve this, it is vital to understand current and future energy needs, which is a challenging task due to increasing uncertainties in supply and demand from new loads (e.g., electric vehicles [7,8]) and intermittent generations from renewable sources. Prosumer energy needs, together with the growing use of dynamic energy tariffs by utility providers, have underpinned the critical importance of battery storage technologies coupled with agile and accurate forecasting algorithms for efficient scheduling.
Furthermore, whether within mature energy markets or developing energy communities, the role of consumers and prosumers is of increasing importance due to several factors, across social, economic, and environmental metrics. Due to fuel poverty and the criticality of energy access, there is a need to improve accessibility to energy services. Economically, citizens are exposed to geopolitical influences on energy costs [9], amplifying fuel poverty and underpinning economic inflation. Environmentally, 73.2% of the global carbon emission in 2016 was by the energy sector, including the use of energy in buildings, industries, and transport. Moreover, the generation of electricity and heating in residential and commercial buildings made up 17.5% of global carbon emissions [10]. Therefore, it is necessary to accelerate the local generation and storage of renewable energy.
Considering a household or a community with either individual or shared renewable energy assets, e.g., solar panels or wind turbines and battery storage, a battery scheduling algorithm should handle the matching of demand and supply of energy efficiently, i.e., maximizing renewable energy usage and minimizing energy imports (and costs) from the central grid. Besides this battery scheduling problem, there are many potential key factors in the setup of the renewable energy assets, e.g., battery type or size and individual versus shared assets, that play a role in the overall efficiency and profit gained by a battery scheduling algorithm [11][12][13].
As forecasting techniques continuously evolve and the solution space for efficiently managing energy using battery scheduling algorithms remains suboptimally covered [14,15], this paper studies and defines an efficient heuristic battery scheduling algorithm that can be coupled to any forecasting technique to maximize the prosumer profit. Ultimately, exploiting future knowledge should optimize the matching of supply and demand and lead towards improving the efficiency of renewable energy assets.
The particular model of the energy management system that will be considered consists of the following components: • Solar photovoltaic(s) or wind turbine(s) encapsulated as generated power; • Battery energy storage system (BESS) of a community or household; • Household or community represented as prosumer demand; • Central grid attachment via some dynamic energy plan.
Prosumer demand can be covered by power from local renewable generation, discharging the battery or importing energy from the grid. The battery can export energy to the grid and charge via locally generated power and, moreover, excess generated power can also be sold directly to the grid. Note that, in this work, we focus on using the battery to integrate local renewable generation, not price arbitrage with the grid; hence, experimenting with charging via imports from the grid is left to future work.
The outline of this paper is as follows: Section 2 covers related work that allows the proposed smart battery scheduling algorithm to be compared and reviews the feasibility of forecasting techniques being able to deliver. Section 3 explores and defines the heuristics of the proposed smart battery scheduling algorithm. Using the materials and methods presented in Section 4, an assessment of the proposed smart battery scheduling algorithm by conducting various experiments will be demonstrated in Section 5 and debated in Section 6. Finally, Section 7 presents the conclusions and highlights future work.

Related Work
To be able to compare the heuristic approach of the smart battery scheduling algorithm and assess the feasibility of the forecasting techniques being able to deliver, several related research efforts are discussed in this section.
Facing the financially driven challenge of managing energy in certain battery systems has resulted in the evolution of many different techniques to achieve performance. There are two main types of approaches to battery scheduling algorithms proposed in the prior literature: optimization-based and heuristic-based.
Linear programming (LP) has been extensively studied for the battery scheduling problem. Torres et al. [16] consider the optimal energy scheduling of photovoltaic (PV) and conventional energy generations in addition to a battery, and linear programming is applied to optimize the operational cost. Luna et al. [17] and Elkazaz et al. [18] formulate the optimal day-ahead energy scheduling of a microgrid with renewable energy sources and a battery as a mixed-integer linear programming (MILP). Similarly, Nguyen et al. [19] use MILP to minimize the day-ahead operational cost of a multi-microgrid system with a demand response program. Furthermore, Couraud et al. [20] also study residential battery scheduling using MILP, considering operational cost as well as battery depreciation cost. Given perfect data (i.e., perfect forecasts with no uncertainty), LP approaches can be used to determine the optimal schedule, however, they require a wide lookahead window, suffer from high computational complexity, and often assume accurate knowledge of future generation and demand. There do exist some robust optimization methods under uncertainty: for example, Zhang et al. [21] consider PV output uncertainty in the energy scheduling of a multi-microgrid system. However, only fixed tariffs have been considered in their work. Other optimization methods include dynamic programming [22], quadratic programming [23,24], genetic algorithm [25,26], particle swarming [26][27][28][29], honey bee mating [30], as well as machine learning techniques, most notably reinforcement learning [31][32][33].
Though the optimization and scheduling methods have been shown to reduce importing energy as well as the total energy costs, they can be computationally costly and often rely on an accurate forecast of energy generation and demand. Rule-based algorithms are another branch of battery scheduling methods that have the advantage of being highly efficient and adaptive to incoming input (generation, demand). Fitting in this direction, and representing a key starting point for this work is the model of Norbu et al. [34], which presented a highly efficient and easily implementable heuristic-based battery scheduling algorithm. The algorithm can be depicted as a concise decision tree that determines whether to interact with the battery, i.e., charge or discharge, or interact with the central grid, i.e., sell or buy energy, based on the current residual power and battery state-see Figure 1. The approach performs well; when not considering (forecasted) future data and using static pricing, it delivers solid results. Yet, heuristic-based methods can further benefit from incorporating predicted forecasts. Ouedraogo et al. [35] show that their proposed rule-based battery scheduling method with predicted forecasting of 6 h ahead using ARMA achieved 94.9% relative performance to the baseline LP method.  Given that Section 5 aims to assess the stability of the proposed smart battery scheduling algorithm not by using any actual forecasting technique but by using a range of various uncertainties based on actual data, it is critical to justify the feasibility of various uncertainties by denoting the ability of several techniques (with different complexities) used to forecast certain types of data, as explored below.
The related body of literature regarding wind predictions is as follows. O'Brien and Ralph [36] found an error of 25-30% in true wind speeds for forecasts of 30 h by evaluating the performance of a wind-forecasting system that utilised a Numerical Weather Prediction (NWP) model and was operated in a similar environment as the data used in this paper. Forbes and Zampelli [37] describe the accuracy of wind energy forecasts in the UK and found an energy-weighted RMSE of 32% for forecasting a day ahead. The energy trading market is leading (also in complexity) and can accurately forecast 36 h ahead at high frequencies using ensemble learning as described by Suárez-Cetrulo et al. [38], which shows several techniques obtaining a scaled RMSE and scaled mean absolute error of less than 1 × 10 −3 . Another promising long-term prediction model is demonstrated by Torabi et al. [39], a cascade neural network that is able to improve one-day-ahead forecasts by 84% and one-week-ahead predictions by 73% based on the RMSE of other already progressive prediction models. Skittides and Früh [40] propose a wind forecasting tool based on Principal Component Analysis (PCA), which is trained on past data to predict wind speeds using an ensemble of dynamically similar past events, and show good performance in forecasting the wind up to 24 h ahead.
Forecasting energy consumption based on electricity consumption data provides promising results, presumably due to the nature of repetitive and alike human behaviour causing stable patterns in the data, of 62.5 h ahead with a prediction error of around 10% using the TBATS model (which forecasts time series based on multiple seasonalities) according to Gellert et al. [41]. The combination of weather and load prediction alone can already decrease operation costs substantially using a hybrid machine learning strategy of Faraji et al. [42]: a multilayer perceptron (MLP) artificial neural network (ANN), adaptive neuro-fuzzy inference system (ANFIS), and radial basis function (RBF) ANN.
While tariffs are often known for various types of contracts, some agile contracts or energy markets call for predicting electricity prices as future tariffs remain unknown. The energy trading sector has led to the proper development of forecasting tools in this area, even though a decade review by Lu et al. [43] shows the serious challenge of predicting electricity prices due to many variables: economic factors, trade factors such as cross-border energy flow, policy factors, environmental factors, calendar factors such as holidays, and lastly general consumption, production, supply, storage, and capacity play a role in energy prices. Using artificial neural networks, day-ahead predictions with a mean absolute percentage error of 7.8% have been achieved [44].

Heuristics of a Smart Battery Scheduling Algorithm
In this section, logical actions and properties are defined and translated into the definition of a smart battery scheduling algorithm that possesses the characteristics of the designed optimal behaviour, i.e., optimally manage energy using future knowledge. Following journal requirements, the extensive definitions of mathematical symbols used can be found in the Nomenclature.

Case Analysis
Before presenting our battery scheduling algorithm, based on the careful analysis and processing of various distinguishing scenarios, some key cases that underpin the battery scheduling algorithm developed in this paper are summarized below. This will form the basis of the algorithmic definition in Section 3.2.

Order of Covering Demand
Demand can be covered by power coming from the grid, generator, or battery. In this case, the order matters for optimal energy management. A solid intuitive approach directly covers demand with ("free") generated power as much as possible. To verify this behaviour, all usage cases for generated power should be examined. If indeed generated power is used first to cover demand, the flow looks as depicted in Figure 2.
If generated power were to be used to charge the battery directly, the flow would be as presented in Figure 3. Demand remains uncovered, thus, we need to cover it by either using the battery or importing from the grid. The battery is already charging, and by discharging it, it would be more efficient to directly cover demand using generated power. Considering a charging efficiency η c and discharging efficiency η d both in the range of [0, 1], directly covering is optimal as it does not deal with the redundant (dis)charging efficiency factor of η c · η d < 1. Ultimately, this idea is redirected back to the scenario shown in Figure 2.  . Scenario in which generated power is used first to cover demand, either in case of excess power (more generated power than demand) or excess demand (less generated power than demand). demand generated power battery grid charge battery now for later usage or exporting, this could be a cheaper move overall not covering using battery, would be less efficient due to (dis)charging inefficiencies compared to then covering using generated power directly cover using grid The other option is to charge the battery using generated power while covering the demand using imported energy from the grid. This could be a valuable move, as more expensive future excess demand might be possible (Section 3.1.3 elaborates on this). However, we can still argue that covering the demand using generated power first is as optimal as the aforementioned if we charge the battery using the central grid, see Figure 4. By interacting with the battery, (dis)charging inefficiency will have to take place in both scenarios, and the cost of importing energy is the same as an equal amount of energy in any circumstance needs to be imported. Consider an amount of generated power g, an amount of demand d, Method 1 being the first method shown in Figure 4, and Method 2 being the second method shown. When the battery cannot be completely charged with g (battery is full at some point), consider b the possible amount for charging the battery (0 ≤ b ≤ g) and s = g − b as the amount of energy that can be exported (profit). By definition, Method 1 imports d from the grid, charges the battery with b, and exports s to the grid. As suggested, Method 2 is able to achieve the same: • If g ≥ d, then Method 2 can completely cover d using g, resulting in remainder g − d.
Similarly, an amount of d can be imported from the grid, resulting in a total remainder of g (= (g − d) + d). The battery needs to be charged with amount b, which can be achieved using the available g, resulting in a leftover of g − b = s. Thus, s can be exported to the grid. • If g < d, then Method 2 covers d using g, yielding a remaining demand of d − g (since g < d). Similarly, an amount of d can be imported from the grid, which can be used to cover the remaining demand d − g and results in g remaining (g = d − (d − g)).
The battery needs to be charged with amount b, which can be achieved using the available g, resulting in a leftover of g − b = s. Thus, s can be exported to the grid.
Given that both Method 1 and Method 2 import d, charge the battery with b and export s, it can be deduced that covering the demand using generated power first remains optimal. The call to import energy from the grid (for beneficial reasons) as presented in this scenario is discussed in Section 3.1.6.

Method 1 Method 2
demand battery generated power grid demand battery generated power grid = Figure 4. Covering demand using the grid and charging the battery with generated power is the same as charging the battery using the grid and covering demand using generated power, based on examining the overall (dis)charging inefficiencies and cost of importing.
Lastly, directly exporting generated power needs to be analysed. The flow of this scenario is illustrated in Figure 5, in addition to an equally effective flow which instead directly covers demand using generated power. . Scenario in which generated power is directly exported to the grid. Instead of directly exporting the generated power, it can be shown to be equally effective to directly cover demand using generated power while still being able to export and import the same amount of energy (thus equal profit and loss) and discharge the battery equivalently.
To show that both methods in Figure 5, from now on referred to as Method 3 (left) and Method 4 (right), are equally effective, consider an amount of generated power g and some demand d, of which some amount b comes from the battery and the remainder r is imported by the grid. By definition, Method 3 exports g, discharges b, and imports r. As suggested, Method 4 is able to achieve the same: then Method 4 can completely cover d using g, resulting in remainder g − d.
Similarly to Method 3, r can be imported from the grid and b can be discharged, resulting in d = b + r. In total, this results in (g − d) + d = g which can be exported. • If g < d, then only g can be covered, resulting in a remaining demand of d − g. Similarly to Method 3, r can be imported from the grid and b can be discharged, resulting in d = b + r. With this, the remaining demand d − g can be covered and results in d − (d − g) = g, which can be exported. Given that both Method 3 and Method 4 export g, discharge b, and import r, it can be deduced that covering the demand using generated power first remains optimal. The call to discharge battery energy to export to the grid (for beneficial reasons) as presented in this scenario is discussed in Section 3.1.2-it should never occur. Thus, covering demand using the battery while having generated power available should never occur either (and again shows the optimality of covering demand using generated power first). Then, only covering demand using imported energy while exporting generated power would be something to consider. This would only be beneficial if the export price is higher than the import price, which rationally makes no sense to occur (providers would be better off by keeping their energy); however, it can be accounted for with a simple if-statement for completeness.
Another edge case to consider is importing energy being the most optimal action when there is an energy surplus on the network and the provider decides to pay prosumers for importing energy in order to prevent blackouts [45], or disruptive providers trying to shift peak demand [46] by paying prosumers for importing energy.
All in all, unless export prices are higher than import prices or import prices are negative (i.e., you get paid to consume energy), the optimal order of covering demand is first using generated power and then either discharging the battery or importing energy based on (forecasted) future knowledge, as explored below, to minimize loss and maximize profit (without such knowledge, discharging would seem cheaper than importing energy).

Matching Demand with Battery Capacity
When not looking into the future, the safe approach for battery scheduling algorithms, e.g., the algorithm by Norbu et al. [34], Figure 1, is to charge as much as possible whenever there is no demand to be covered anymore. However, with future knowledge, this is not optimal, as it can miss out on selling opportunities. For example, consider some excess power α at timestamp t, i.e., the surplus of generated power compared to the demand: g(t) − d(t) > 0, and some (forecasted) future excess demand β at t + 1, i.e., g(t + 1) − d(t + 1) < 0. Moreover, excess power α is even more than the amount needed to cover excess demand β when taking into account (dis)charging inefficiencies: α > |β| η c ·η d . Furthermore, excess power α could charge the battery without exceeding the capacity of the battery (ω) and α is less than the maximal amount of power that can be currently charged (δ c (t)) when also taking into account charging efficiency: α · η c ≤ δ c (t) ≤ ω. Additionally, excess demand β can be covered by the battery (only when charged sufficiently), given that its discharging boundary (δ d ) multiplied by the discharging efficiency at the respective timestamp is considered to be |β| ≤ δ d (t + 1) · η d . Then, only considering these two timestamps (timespan T = 2) and starting with an empty battery, the safe approach (charging using all of α) misses out on exporting (α + β) · ∆t (i.e., the combined residual power times the duration of the timestamp = amount of export energy). In essence, the battery should never be filled more than needed with the knowledge of perfect future data.

Expensive Future Excess Demand
Given some usable capacity in a battery at some t, i.e., the current state of charge is above the minimum (SoC(t) > SoC min ) and discharging is possible (δ d (t) > 0), and consecutive negative residual power, i.e., excess demand in the (forecasted) future that is more than the battery can cover, i.e., g( where future import tariffs are higher than the current import tariff, i.e., ∀x ∈ X \ {t}, it holds that τ b (t) < τ b (x), it is intuitively smarter to buy energy currently at t and discharge the battery at a later moment (when import tariffs are the highest) as this reduces the total cost for covering excess demand in X.

Maximizing Profit Exported Energy
Considering some (forecasted) future where we currently are in a timespan with excess power, i.e., g(x) − d(x) ≥ 0 for x ∈ X where X = {t, t + 1, . . . , m}, and as far as we can look in the future (denoted as timestamp n), excess demand timespans, i.e., g(i) − d(i) < 0 for i ∈ Y where Y = {m + 1, m + 2, . . . , n}, do not exist or are already known to be covered maximally by current excess power from X while still resulting in leftover energy to export, it is optimal to calculate the amount of energy that needs to be charged for possible future coverage of Y and then charge the battery at times when selling prices are as low as possible until the desired SoC is reached to ultimately export any leftover energy at the highest export prices.

Mandatory Profits and Losses
Then, if β > 0 or γ > 0, the battery cannot handle charging or discharging this amount of residual power (α) and thus β needs to be exported or γ needs to be imported. No smart algorithm can go beyond these battery constraints, these profits or losses must occur.

Expensive Charging Exploit
Charging the battery with imported energy should be considered at any t if this is possible from a technical standpoint (intuitively, it is similar to using your phone while it charges). It is needed to truly cover all demand as cheaply as possible whenever the battery, even given perfect knowledge, is not able to. Any excess demand that needs imported energy should have, if and only if there was room to charge (RtC, in kWh per timestamp) up until the current t, charged previously at some timestamp t prev with imported energy if the import tariff (τ b ) was substantially cheaper, i.e., When looking back at the period [t prev , t), the available import amount for t is capped at the maximum throughput for the RtC within this period and of course considering any other constraints such as the respective (dis)charging boundaries. To be more precise, RtC is the usable capacity of the battery per timestamp within the minimum and maximum limits provided by SoC min and SoC max , respectively. Any action within the lookahead window could require readjusting the RtC accordingly. For example, when charging at a timestamp t c to discharge at a later timestamp t d , the RtC needs to be reduced accordingly within the range [t c , t d ). The RtC serves a purpose in calculating the amount of energy that can "travel" between two timestamps within the lookahead window, also described as the maximum throughput. The maximum throughput is a reverse traversal of a range of timestamps where each RtC value (or any other list of values) is compared with the current global minimum, defined as ∞ at the start of the traversal, until 0 or the start of the range has been reached. Essentially, this is a boundary that needs to be taken into account by certain operations of the proposed algorithm in Section 3.2.

Definition of the Smart Battery Scheduling Algorithm
This section defines the smart battery scheduling algorithm, while simultaneously elaborating on the implementation of the beneficial insights and derived properties from the case analysis in Section 3.1.
Algorithmically, the idea is to process future timestamps and their data by looking back each time in a stepwise manner and rearranging the past optimally. Then, after processing the whole forecast, the most optimal action-based on the forecast data-is discovered for the current timestamp. It is important to be aware of this direction of processing and thinking in the next subsections, as the previous case analysis in Section 3.1 denotes the basis of the to-be-implemented logic in a future-orientated manner at times (and thus needs to be converted yet satisfied). Moreover, be aware that each timestamp looks at the residual power, i.e., g(t) − d(t), since directly covering demand using generated power is (generally) always a first step (see Section 3.1.1), thus either the remaining excess demand or excess power is considered.

Step 1: Skipping Excess Power
Any excess power within the lookahead window, i.e., g(t) − d(t) ≥ 0, is skipped by the algorithm (meaning no decisions are made immediately), as then its leftover residual power can be used in future timestamps within the lookahead window which look back respectively. If no future timestamp needs or is able to use this residual power (completely), all leftover power will be exported to the central grid when post-processing the current timestamp (see Section 3.2.7). This step falls back on the idea of matching demand with battery capacity (in this case skipped excess power is potential battery capacity) optimally as presented in the case analysis in Section 3.1.2.

Step 2: Using Battery Power
As analysed in Section 3.1.1, and also under the hypothesis that the battery is filled knowing it was needed in the future, which could be now, the first action of covering excess demand is using battery power-unless τ b (t) < 0, then importing energy is optimal. Thus, any excess demand will be covered as much as possible or needed using the battery, i.e., min(δ d (t) · ∆t, SoC(t) · ω, g(t)−d(t) η d /∆t ). Do note that such actions require changes to be made for RtC, SoC, p bat d , and other variables the algorithm keeps track of. Additionally, it might seem like this step will yield suboptimal results given the possibility of expensive future excess demand as illustrated in Section 3.1.3, however, step 4 (Section 3.2.4) will satisfy said case.

Step 3: Using Past Excess Power
If excess demand is still not fully covered by the previous step (2) and δ d (t) > 0, the algorithm continues to look for available excess power that can be used to charge the battery between the starting timestamp of the lookahead window and the current future timestamp that is being looked at. To maximize the profit of exported energy as discussed in Section 3.1.4, the algorithm will sort any previous timestamps with g(t) − d(t) > 0 and δ c (t) > 0 based on ascending export tariffs, such that the revenue remains as large as possible. Before that, the algorithm should also know how much energy at such timestamps can be discharged and should not consider any timestamps before other timestamps that have no room to charge, as the energy cannot reach the current timestamp due to said bottleneck. Thus, iterating back until, for some timestamp x, RtC(x) = 0 or the starting timestamp of the lookahead window is reached, a list to keep track of throughput values is generated by calculating min(RtC(t), min global ), where min global is a variable, initially set to ∞, to keep track of the minimal global throughput and t, the respective timestamp. Then, based on the aforementioned pricing strategy and (dis)charging boundaries at the respective timestamps, excess power will be charged into the battery as much as possible and needed at the available timestamps.

Step 4: Using Previously Discharged Energy
If excess demand is still not fully covered by the previous steps (2 and 3), it can only be covered by importing energy. However, instead of directly importing, the first thing to consider is the case in Section 3.1.3 that depicts a scenario with expensive future demand, which could be the case for the current timestamp (i.e., import tariff is currently higher than previous timestamps). If any previous timestamp, let us refer to such a timestamp by x, had a lower import tariff and discharged energy from the battery, it is possible to swap the discharged energy at x for imported energy and use the newly available energy in the battery, if δ d (t) > 0, at the timestamp t which is currently being looked at. Additionally, it needs to be checked whether enough room to store energy is available during the period of [x, t). Then, sorted on ascending import tariffs, discharged energy is swapped as much as possible and needed to cover the demand at t.

Step 5: Using Previously Imported Energy
Besides the previous step (4), there is another possibility for additional benefit regarding the need to import energy, if the renewable energy system is set up accordingly, by preventively charging using substantially cheaper imported energy as discussed in Section 3.1.6. The algorithm should compare the benefit compared to the previous step and also, similarly to step 3, calculate how much room to charge is available and needed.

Step 6: Directly Importing Energy
If excess demand is still not fully covered by the previous steps, which would be the case if it is out of control as illustrated in Section 3.1.5, or simply since buying energy at the current timestamp is the best option (left), energy needs to be imported from the grid. Similar to the first step of skipping excess power, the excess demand can be skipped and any leftover excess demand will be imported from the grid by the algorithm when post-processing the current timestamp (see Section 3.2.7).

Output of the Algorithm
After processing the steps taken by the algorithm as described above, the algorithm should return the actions for the current timestamp t (= 0 within the lookahead window, referred to as 0 la ) which are as follows: • g(0 la ) · ∆t, denoting the leftover energy that will be exported (values in g have been altered to reflect actions taken within the lookahead window), referred to as opt export (t). • d(0 la ) · ∆t, denoting the leftover energy that will be imported (values in d have been altered to reflect actions taken within the lookahead window), referred to as opt import (t). • p bat c (0 la ) · ∆t, denoting the optimal amount to charge at t, referred to as opt charge (t) (which is the energy change in the battery, not the actual input). • p bat d (0 la ) · ∆t, denoting the optimal amount to discharge at t, referred to as opt discharge (t) (which is the energy change in the battery, not the actual output).
It can then be deduced that:

Constraints of the Algorithm
When running the algorithm, at each t ∈ T, the following assertions are made to check if the algorithm satisfies properties that classify the algorithm as working properly: Equation (3) checks whether more or less output has been created from some input, i.e., the residual energy at t equals the leftover energy (which will be exported or needs to be covered using imports) combined with the energy going into the battery to charge (part of the original residual energy) minus the energy coming out the battery by discharging (not part of the original residual energy) based on a supposedly optimal decision at t.

Processing an Example Scenario Using the Smart Battery Scheduling Algorithm
To possibly increase the intuitiveness behind the functioning of the algorithm beyond the power of words, a figurative systematic walkthrough of the smart battery scheduling algorithm for an example scenario with expensive future demand is presented in Figure 6.
In this scenario, initially ∆t = 1, SoC init = 0, and ω = 1. The algorithm considers three timestamps when looking ahead, i.e., κ = 3. Furthermore, to simplify, efficiency is not considered (η c = η d = 1). The bottleneck of this scenario is the substantially higher import tariff at the third timestamp compared to the second timestamp (5 > 1) and the lack of generated power in the first timestamp to cover all future demand. Thus, it would be optimal to import energy at the second timestamp instead of the third to reduce total cost, which a basic present-orientated battery scheduling algorithm (e.g., Figure 1) does not consider as it discharges immediately and then requires to import at the third timestamp.

Methods and Data Used in Experimental Validation
In order to assess the newly introduced heuristics for a smart battery scheduling algorithm using (forecasted) future knowledge, several experiments that simulate experimental yet practical settings should be conducted. The materials and methods for such experiments are described in this section.

Baseline Comparison and Generated Power Data
As a baseline for comparing the proposed heuristics of the smart battery scheduling algorithm, the battery scheduling algorithm by Norbu et al. [34] is used. The authors of Norbu et al. [34] also granted access to repositories containing an assemblage of code that simulates this basic battery scheduling algorithm and provides data for generated power based on calculations of UK weather data (i.e., solar and/or wind). The baseline battery scheduling algorithm will be compared to the proposed smart battery scheduling algorithm, of which a concise implementation by de Bekker [47] can be utilised.

Data for Demand and Tariffs Used in Experimental Validation
Regarding data available for simulation, a collection of recorded energy demands of households connected to a smart grid during two trials, i.e., Thames Valley Vision and Low Carbon London, and dynamic tariffs from an Octopus Agile energy plan are utilized. The Thames dataset by Scottish & Southern Electricity Networks [48] contains 200 households over a timespan of a year (from January 2017 to December 2017) with intervals of 30 min. The London dataset by UK Power Networks [49] contains 5567 households over a time span of 2.5 years (from November 2011 to February 2014) with intervals of 30 min.
Historical data of the Octopus API have been recorded by EnergyStatsUK [50] and provides Octopus Agile import and export tariffs for London from roughly 2018 to 2022 with intervals of 30 min (∆t = 0.5). Given the similarity in interval frequency, all data can adequately be matched on a month-day basis. As for matching the years, unfortunately, no proper overlap is achievable in the data, thus the best remaining option for simulation is using complete years. Tariff data used are from 2020 to 2021, whereas the London and Thames data are the first complete year available, i.e., 2012 and 2017, ultimately resulting in T = 365 · 24 · 2 = 17520 time periods.
To be able to put any output of the simulated experiments into perspective, the annual energy bills for the average prosumer have been calculated for the datasets of Thames and London in Table 1 and could also be seen as baseline annual bills for these simulated environments. Table 1. Annual energy bills for the average prosumer in the simulated Thames or London environment without battery or generated power.

Setup
Thames Additionally, an indication of the shape of the Octopus Agile import and export tariffs used in experiments is provided in Figure 7.

Battery Data Used in Experiments
As for simulating the battery, based on the research of May et al. [51], a lead-acid battery is a remarkably well-established option for energy storage and is the only BESS that is nearly entirely recycled (99% in Europe and the USA), which supports the ultimate goal of improving renewable energy assets: sustainability. Lithium-ion batteries have a problematic low rate of recyclability (less than 1%), yet as a result of rapidly developing technologies are deemed to be the future of batteries due to a longer life cycle and higher energy density [52]. Additionally, based on the research of Kebede et al. [53], lithiumion batteries are also considered to be more techno-economically viable than lead-acid batteries. Given the mentioned advantages of lithium-ion batteries and the future potential of proper recycling as comes with battery maturity according to Yanamandra et al. [52], lithium-ion batteries have been selected to be simulated. The technological downsides that need to be accounted for when simulating a BESS using a lithium-ion battery are a depth of discharge (DoD) of 80% and practical efficiencies of around 85% for (dis)charging the battery, according to performance tests carried out by Bila et al. [54]. The aforementioned translates into the following attributes: η c = η d = 85% and SoC min = 20%. The optimal sizing of battery capacity (ω) to gain the most benefit requires taking into account many (local) factors and performing additional experiments, which is not the main focus of this paper. Instead, a wide range of battery capacities for the average prosumer are considered in the experiments.

Simulation of Forecasting Methods
In order to be more certain that the smart battery scheduling algorithm works adequately, the robustness is tested by experimenting with erroneous future forecasts for power and demand predictions in addition to tariff predictions. As there are various techniques used to estimate the future-some more accurate or costly than others-which all deserve to be considered, a broad range of functions that alter the data uniquely have been experimented with and are clarified below.

Constant Uncertainty Margins
The simplest function to quickly assess the robustness of the algorithm is a constant margin of the form y ± c · σ data in which uniformly a random value is picked for x ∈ (0, κ]. Note that the standard deviation is not within the lookahead window but the complete data to gain more stable insights.

Linear Uncertainty Margins
Future estimations often become more inaccurate as time passes, as patterns are often not that clear for longer periods. To illustrate the robustness of the smart battery scheduling algorithm with uncertainty following said characteristics, a linear function of the form y ± c · x · σ data where x ∈ (0, κ] is considered for the margins to uniformly pick a random value.
An example of the shape of such a margin function can be seen in Figure 8.

Complex Uncertainty Margins
Usually, uncertainty boundaries are not constant or linear, thus, a more complex experiment is also contemplated where up until a point in the lookahead window the uncertainty converges and then starts diverging. This led to creating the following function for setting the margins to uniformly pick a random value: In Equation (4), s denotes a scalar, where s 1 scales the converging function and s 2 scales the diverging function with exponent n. Another scalar is w, which can be seen as a control for the width. In the performed experiments, w is commonly defined as κ − d (= (1 − r) · κ ). The d is the timestamp within the lookahead window where the converging function is continued by the diverging function, which can also be defined as a ratio r of the lookahead window multiplied by its size κ.
This function aims to be a more naturalistic margin for the picked random values where the beginning can be fairly accurate and then shift into larger misconceptions.
An example of the shape of such a margin function can be seen in Figure 9.

Calculating the Bill of a Community or Prosumer
When computing the cost of a community (e.g., London or Thames), this paper considers b(T) to be the bill of the total operational cost for the whole community, which is the sum of the imported and exported energy times the respective tariff for each timestamp in T, for all prosumers in the dataset: Thus, the total operational profit is defined as −b(T) and is most suited for plotting results of the simulations as the generated power and smart energy management result in comparing profits rather than costs. For the bill of the average prosumer, the operational profit or cost for a community is divided by N, the number of households/size of the dataset, respectively.

Experimental Results
In this section, the practical performance of the proposed smart battery scheduling algorithm is assessed by conducting and describing the experiments in various settings based on the data and methods used, as discussed in Section 4.

Performance of Perfect Forecasts
To obtain an initial understanding of the performance of the newly introduced battery scheduling algorithm, the baseline algorithm and the smart battery scheduling algorithm are both simulated within the environment as described in Section 4 but in combination with perfect future knowledge (i.e., original data). Battery size and how far we look into the future (lookahead window) are not specific, thus, various values have been considered to gather a complete overview: •  Figure 10 by showing, for the average prosumer, the operational profit gained by the smart battery scheduling algorithm as a boxplot (based on outcomes for the various κ) per battery size. For the baseline battery scheduling algorithm, the operational profit per prosumer, i.e., −b 0 (T)/N, has been plotted per battery size as well to compare the algorithms.
All the details per κ per battery size can be seen in Appendices A and B for the London and Thames dataset, respectively. These details reveal that a lookahead window of 8-12 h nearly always outperforms the baseline battery scheduling algorithm and looking ahead 24 h was always more profitable compared to the baseline battery scheduling algorithm. Additionally, based on the annual bills when having generated power yet no battery, on average, when getting a battery, the smart battery scheduling algorithm is able to achieve between 20% to 60% more operational profit compared to the baseline battery scheduling algorithm, as shown in Table 2. Figure 10. High-level comparison between operational profits of the baseline algorithm and smart algorithm for the average prosumer using various battery sizes across the lookahead amounts represented in boxplots, following the experiment described in Section 5.1. Table 2. Relative operational profit for the average prosumer from using the smart algorithm over the baseline algorithm in the simulated Thames or London environment. The underlying basis for comparison is no battery and/or generated power (Table 1).

Robustness of the Smart Battery Scheduling Algorithm
In order to be more certain that the smart battery scheduling algorithm works adequately, the robustness is tested by experimenting with erroneous future forecasts for power and demand predictions in addition to tariff predictions as described in Section 4.4. All experiments performed in this subsection consider κ ∈ {6, 8, 16, 24, 32, 40, 48, 64, 72, 96} and battery sizes similar to Section 5.1.

Robustness of Constant Uncertainty Margins
As for the constant c, values ranging from 0.5 up to 100,000 have been considered and the results of 3080 experiments have been summarized in Figure 11.
Based on these experiments, the smart algorithm outperforms the baseline algorithm each time with complete future tariff knowledge; however, when tariff uncertainty is introduced next to power and demand uncertainty, the smart battery scheduling algorithm always only beats the baseline battery scheduling algorithm for a margin of less than or equal to one standard deviation. Thus, directly having substantial constant uncertainty in future tariffs most likely results in suboptimal output, unless more sophisticated forecasts are used as in the next experiments. Moreover, the results of this experiment indicate that by becoming a prosumer with both generated power and a battery, on average, the smart battery scheduling algorithm maximally loses only 3% operational profit with constant generation and demand uncertainty compared to perfect forecasts, as shown in Table 3. Table 3. Relative performance of the smart algorithm with constant generation and demand uncertainty compared to perfect forecasts in the simulated Thames or London environment. The underlying basis for comparison is no battery and/or generated power (Table 1).

Base Comparison Thames Dataset London Dataset
No generated power and no battery Avg: 97%, Min: 92% Avg: 100%, Min: 98% Generated power and no battery Avg: 96%, Min: 90% Avg: 87%, Min: 65% Figure 12 summarizes 1400 experiments using various linear margin functions in combination with various sizes for the lookahead window (κ) and various sizes for the battery per prosumer (ω/N). Interestingly, c ≤ 0.05 outperforms even the smart battery scheduling algorithm using perfect forecasts, also with tariff uncertainty. Moreover, all functions outperform the baseline battery scheduling algorithm with only power and demand uncertainty. Moreover, the results of this experiment indicate that by becoming a prosumer with both generated power and a battery, on average, the smart battery scheduling algorithm only loses 1% to 2% operational profit with linear generation and demand uncertainty compared to perfect forecasts, as shown in Table 4. Table 4. Relative performance of the smart algorithm with linear generation and demand uncertainty compared to perfect forecasts in the simulated Thames or London environment. The underlying basis for comparison is no battery and/or generated power (Table 1).

Base Comparison Thames Dataset London Dataset
No generated power and no battery Avg: 98%, Min: 97% Avg: 99%, Min: 99% Generated power and no battery Avg: 98%, Min: 96% Avg: 84%, Min: 80% Figure 13 summarizes 1400 experiments using various converging and diverging margin functions in combination with various sizes for the lookahead window (κ) and various sizes for the battery per prosumer (ω/N). The results show similar (profitable) results compared to the smart battery scheduling algorithm using perfect forecasts and remarkably tolerable tariff uncertainty compared to previous experiment types. Moreover, the results of this experiment indicate that by becoming a prosumer with both generated power and a battery, on average, the smart battery scheduling algorithm maximally loses only 1% operational profit with converging and diverging generation and demand uncertainty compared to perfect forecasts, as shown in Table 5. Table 5. Relative performance of the smart algorithm with converging and diverging generation and demand uncertainty compared to perfect forecasts in the simulated Thames or London environment. The underlying basis for comparison is no battery and/or generated power (Table 1).

Discussion
After introducing a smart battery scheduling algorithm defined in Section 3 and putting it to the test in Section 5 by simulating a manifold of scenarios based on Section 4, this section will reflect on particularities present in the conducted experiments.
Firstly, a conceivably anomalous sight of more profitable simulations with respect to the simulations using perfect forecasts can be seen in the outcomes of some experiments testing the robustness of the algorithm in Section 5.2. A probable justification for this occurrence could be that the lack of knowledge after the lookahead window causes a suboptimal decision no matter the accuracy of the forecast, as the lookahead window does not span the range of timestamps that would influence the perfect decision in retrospect. From all the detailed results of simulations for various sizes of κ with perfect forecasts, presented in Appendices A and B, the total operational cost, i.e., b(T), with respect to κ follows the shape of a positive-indexed reciprocal function, i.e., y = 1/x for x > 0, and Π(T) does not decrease, which confirms that more (accurate) knowledge guides the smart algorithm to make more profitable decisions. Based on said beliefs and findings, it seems that some of the imperfect forecasts accidentally directed the decision unknowingly towards a decision that matched the supply and demand of energy more or most optimally. Therefore, it could be worth investigating uncommon actions or trends in lookahead windows of unusually computationally large size in order to assess whether using these actions based on the estimation of some machine learning techniques in small lookahead window sizes would benefit the overall efficiency of the smart battery scheduling algorithm.
Secondly, it is essential to denote limitations regarding the experiments to critically assess the proposed smart battery scheduling algorithm appropriately. Computationally speaking, the available equipment used to run simulations had an inferior level of performance to calculate the "most optimal" profit possible where κ = |T|, which would provide even finer insight into the level of performance of the simulations carried out in Section 5.2 where randomness was introduced to sample the robustness of the smart battery scheduling algorithm. Moreover, due to a lack of available data, the simulations were run on real data yet originating from different years, thus, it merely provided a sound environment to evaluate the behaviour of the proposed smart battery scheduling algorithm, whereas true-to-life data could have supplied more relatable insights into actual cost and profit differences, especially for the energy communities that were considered in this paper. From weather to demand, all variables in the setup have a sensitive correlation, as confirmed by Hernández et al. [55]; thus, any output cannot be truly considered genuine or useful for any recommendations besides performance testing. It would be interesting, as then the outcomes could provide practical recommendations for the size of a battery storage unit for a particular prosumer as well. In addition, various types of tariffs could be considered to gain a perspective of the usefulness of adapting to the proposed smart battery scheduling algorithm for a particular prosumer. Essentially, actual forecasting models and more real data should be explored using the proposed battery scheduling algorithm in order to advance towards practical deployment and directly improve the efficiency of renewable energy assets.

Conclusions and Further Work
In this paper, customised heuristics for a smart battery scheduling algorithm are developed to improve the utilisation of renewable energy and storage assets by efficient matching of energy supply and demand. For a theoretically optimal decision, the future should be taken into account, which realistically can be forecasted with the current state of technology. Based on the idea of having perfect knowledge in the complete range of time, the following broad principles should be taken into account: • A battery should never be filled more than needed as otherwise the surplus of energy could have been sold. • If battery power is considered to be utilised, while in the future excess demand needs to be covered by buying energy for a higher price than the current price, it would be beneficial to buy energy now and use battery power in the future. • If energy can be sold to the central grid on multiple occasions, it should be sold at times when the selling price is as high as possible. • If the battery is able to charge using imported energy from the grid, charging the battery with bought energy should be considered if it is more profitable than having to buy energy later at a substantially higher price.
• If the available generated power and battery power cannot cover the demand, there is no other option than to buy energy. Similarly, if the battery cannot be charged more or at a higher rate, energy needs to be sold to the central grid.
Based on several thousands of simulations in areas of the UK with various probable ranges of forecasts and battery sizes, the smart battery scheduling algorithm has demonstrated to gain additional profit for both theoretically perfect forecasts and plenty more realistic forecasts by exploiting the aforementioned characteristics. On average, the results show that when a prosumer uses a battery to store generated energy, the newly proposed algorithm outperforms the baseline algorithm, obtaining up to 20-60% more profit for the prosumer from his/her energy assets with perfect forecasts. With various types and levels of simulated uncertainty in generation, demand, and tariff forecasting, the proposed algorithm has shown robustness: it produces greater profit than the baseline method and only 2-12% of profit is lost compared to perfect forecasts. The performance of the proposed algorithm increases as the uncertainty decreases, showing great promise for the algorithm as the quality of forecasting keeps improving. In conclusion, the proposed smart battery scheduling algorithm can be considered a proper improvement in the efficiency of renewable energy assets and also serve as a foundation for the heuristics of smart energy management systems using forecasting techniques.
In future work, we plan to focus on exploring how other advanced techniques from machine learning and modern AI can be leveraged to design more efficient control algorithms for integrating renewable generation, demand, and battery storage, such as, for example, those coming from Bayesian reasoning, reinforcement learning, or deep learning neural nets [56]. The design of intelligent scheduling algorithms for this problem, that leverage recent advances in AI and the use of forecasting data, remains a key direction for further work. Other promising directions for extending the work include better integration of the battery control with renewable forecasting (for example, wind forecasting), as well as the use of our heuristics from price arbitrage and trading with the grid, taking advantage of dynamic time-of-use prices, which are increasingly used by power system operators to encourage flexible demand. Looking further ahead, it may be fruitful to integrate our approach with other smart energy problems-for example, the control of charging of electric vehicle batteries [57], including two-directional charging in vehicle-to-grid (V2G) schemes [58]. Additionally, algorithms such as ours could be used for distributed demandside response [59][60][61], also incorporating behavioural factors, such as perception of comfort loss by energy users [62].

Appendix B. Detailed Results of Forecasts on Thames Dataset
This appendix shows the details of the experiments carried out in Section 5.1 using the Thames dataset to give more insight regarding how far the smart battery scheduling algorithm needed to look ahead (κ) in order to be more profitable than the baseline battery scheduling algorithm for a broad range of battery sizes. The results can be seen in Figures A3 and A4. Note: BA stands for "baseline battery scheduling algorithm" and SA stands for "smart battery scheduling algorithm" in the legend. On average, a lookahead window of size κ = 16 (i.e., 8 h) outperformed the BA. For larger battery sizes, the greedy charging approach of the BA works so sufficiently that the SA can barely outperform BA in smaller lookahead windows. Only for substantially higher lookahead windows is the SA able to outperform BA. This makes sense, as a lot of room in the battery means that charging the battery is rarely a mistake short-term, thus, a larger lookahead window has to provide these details.