*2.1. HESS Model*

The setup considered in this work was a scenario of a microgrid that is equipped with RES; in the presented case, this was in the form of a photovoltaic (PV) installation. The system was equipped with a behind-the-meter HESS as shown in Figure 1.

**Figure 1.** The schematic model of the HESS operating in a microgrid.

Energy profiles were extracted from the historical data recorded by power analyzers at the KEZO Research Centre, Jabłonna, Poland. The usage was gathered from 3 buildings, which had laboratories, conference rooms, kitchens, bathrooms, administration offices, hotel rooms and a server room. The annual consumption was around 221 MWh; it was characterized with irregular patterns of usage—there were long intervals with a very high level of usage, but also non regularly appearing peaks. The usage was variable, ranging from 10 kW to 60 kW, with two dominating values around 20 kW and 38 kW (Figure 2). The centre was equipped with PV installations amassing 180 kWp in total, generating 144 MWh annually. The profiles of power generation and usage were aggregated in 15 min intervals, which is a commonly used interval of energy data gathering and it is consistent with the standard output of the energy meters. The usage and production aggregated per month is presented in Figure 3.

The HESS installed and used in the KEZO power system and modelled in this work consisted of a vanadium redox flow battery (VRFB) and a lithium-iron-phosphate (LFP) battery. The parameters of HESS batteries used for simulations are given in Table 1. Generalized battery cost and performance (number of cycles, efficiency) data were based on [24]. The batteries were connected logically in one network and were managed by the EMS system installed on an industrial computer.

**Figure 2.** The histogram of power of consumption in the used example in KEZO Research Centre.

**Figure 3.** The energy of usage and production aggregated by month (data from the KEZO Research Centre).


**Table 1.** Hybrid energy storage system parameters assumed for the simulation.

The model included linear battery degradation, which reflected the battery capacity loss during its usage and the cost of replacing the battery block (*ReCi*) after exceeding nominal energy throughput (*Thi*). To evaluate depreciation cost of operating the battery, the degradation cost was calculated by multiplying discharge energy by a degradation cost factor (DCF). This factor was calculated as follows for each of the batteries (*i*—index of each battery in the HESS):

$$DCF\_i = \text{Re}C\_i / Th\_i \tag{1}$$

where:

$$T\text{h}\_{i} = \text{NoC}\_{i} \* \left(DoD\_{i} \* E\_{\text{bol},i} \right) \tag{2}$$

The *Thi* is the nominal throughput of the storage calculated as the multiplication of number of cycles (*NoC*), depth of discharge (*DoD*) and the nominal capacity (*Ebol*)—the values for the considered setup are presented in Table 1.

The battery model also accounted for energy losses in the batteries. At the battery charging instants, a round trip efficiency (*RTE*) factor was applied to calculate the energy available for discharge.

For the sake of model simplification and reduction of computational burden, efficiency and degradation remained independent of the battery's operational parameters, such as temperature, current and *DoD*.

The model was simulated with up-to-date Polish market prices in tariff B23, which is a real tariff for this type of building and usage. The energy tariff has three zones: the morning peak (from 7:00 until 12:00)—2.53 PLN/kWh, the evening peak (varies between seasons but ranges from 16:00 until 22:00)—3.43 PLN/kWh and the off-peak—1.96 PLN/kWh [25]. Surplus of energy was sold at the flat rate of 0.472 PLN/kWh [26]. The price profiles are depicted in Figure 4.

**Figure 4.** The price tariff for the selling and purchase of energy to/from the grid for months October–March.

The aim was to show that the HESS can be economically justifiable and that it increases the self-consumption of the energy produced from the RES. The aim of the implemented optimization method was solely to minimize the cost of operation, a problem for which a solver was used. A simple control method—energy balancing—was given as a benchmark. Control methods are described in detail in the following sections. We assumed that the usage and production of the energy was not subject to changes. The only thing that changed the balance at the point of coupling with the grid was the operation of the HESS.

#### *2.2. Energy Balancing*

The benchmark method was chosen to represent the most simplistic operation of the ESS in the given setup. The idea of the basic energy balancing was very simple: the energy storage charges when production exceeds load and discharges when power was imported from the grid [27]. This control method minimized the exchange of energy with the external grid and did so without considering tariffs or even energy prices, thus foregoing possibilities for price arbitrage. On the other hand, such a method was guaranteed to use as much of the local RES overproduction as possible, in which case it potentially managed to increase self-consumption. In periods with low production from RES, the energy storage may not have a chance to charge. In our model, which assumed PV sources, this occurred in times with less sunshine, and, as a consequence, the HESS spent most of the winter time in a discharged state, thus not helping to decrease the costs of energy. On the upside, not using the battery implied that there is no degradation cost—the model is simplified and did not consider any degradation that might be caused by leaving the battery in an extremely low state of charge.

#### *2.3. Economic Optimization*

The operation of the HESS is described by its average power in a time period *t* and denoted as *pHESS*(*t*) = <sup>∑</sup>*i*∈{*LFP*, *VRFB*} *pi*(*t*). The optimization happened in a time window, which had *T* periods. Any length of time window can be chosen, but the size of this time window correlated with the duration of the computation: the longer the total time, the longer the computation will be. As we assumed that energy comes from PV and, in general, daily cycles are observed in usage patterns, it made sense to choose the total duration of *T* as 24 h. To speed up the calculation of the solver, an initial solution was calculated and passed to the optimizer; this was a vector of length *T* of values *pi*(*t*), where *i* ∈ {*LFP*, *VRFB*}. This initial solution suggested discharging at times of high-price tariff and charging in the low-price tariff. The gain in the time of calculation was small and neglectable. The grid balance at time *t* was denoted by *pgrid(t)*. The general rule was that the energy sent from the installation to the grid and the energy from the installation to the battery was positive; the energy taken from grid and the energy taken from the battery was negative.

The aim was to minimize the total balance that is influenced by the battery operation; therefore, the goal function *fi* was:

$$f\_i = \sum\_{t=0}^{T} \begin{cases} \left| p\_{\text{grid}}(t) + p\_i(t) \right| \* c\_{\text{buy}}(t) + d \text{erg}\_i(t), \text{ if } \left( p\_{\text{grid}}(t) + p\_i(t) \right) > 0 \\ \left| p\_{\text{grid}}(t) + p\_i(t) \right| \* c\_{\text{sell}}(t) + d \text{erg}\_i(t), \text{ if } \left( p\_{\text{grid}}(t) + p\_i(t) \right) \right| \le 0 \end{cases} \tag{3}$$

$$\deg r(t) = \begin{cases} \ p\_i(t) \* DCF\_{i\prime} & \text{if } \begin{aligned} \chi\_i(t) < 0\\ 0, & \text{if } \begin{aligned} \chi\_i(t) > 0 \end{aligned} \end{aligned} \tag{4}$$

The goal function includes the tariffs: *cbuy*(*t*) is the unit cost for buying energy from the grid for the given time frame *t*, and *csell*(*t*) is the unit profit for selling energy to the grid. As we assumed that the tariff can change in each *t*, the main difference with peak shaving was that now it was not just the amount of energy that mattered at a time *t*, but this amount was linked via the tariff with the time at which it occurred. This combined energy with price, allowing an optimization for the general idea of reducing the amount of energy bought during price peaks with the aim of reducing the cost.

The constraints included the limitation for charging power:

$$\forall t: p\_i(t) + p\_{chg,i} > 0 \tag{5}$$

where *pchg*,*<sup>i</sup>* is the maximum power allowed for charging the battery.

Symmetrically there is a limitation for discharging power:

$$\forall t: p\_{d \text{chg}, i} - p\_i(t) > 0 \tag{6}$$

where *pdchg*,*<sup>i</sup>* is the maximum power allowed for discharging the battery. In the examples, *pchg*,*<sup>i</sup>* = *pdchg*,*<sup>i</sup>* = *Pmax*,*i*.

Constraints of the state-of-charge (*SOC*) values were defined for each of the consecutive power values for energy storage at each time *t*. For not exceeding maximum state of charge, constraints were defined as follows:

$$\forall t: \left( E\_{\text{bol},i} - e\_i(t) \right) - \sum\_{j=0}^{t} e\_i(j) > 0 \tag{7}$$

There are T-1 such constraints for charging the energy storage as power had to be recalculated to the equivalent energy *e*(*t*) that was inserted into the battery. The charging energy was multiplied by the RTE value.

For not exceeding minimum state of charge, constraints were defined as follows:

$$\forall t: \left( e\_i(t) - E\_{bol,i} \* \left( \frac{SOC\_{min,i}}{100} \right) \right) + \sum\_{j=0}^{t} e\_i(j) > 0 \tag{8}$$

In this equation *e*(*t*) is the energy that is discharged or charged, in case the charging of the RTE value is considered.
