1 Introduction

In recent years, home energy management (HEM) has attracted considerable attention as the residential sector accounts for a significant portion of the total energy consumption. Solar power generation represents a promising and sustainable alternative to reduce the household consumption and the carbon footprint. Supported by continuously decreasing system costs and government incentives, Photovoltaic (PV) systems are nowadays widely applied, especially at the residential level. An annual average growth rate of about 50% has been observed between 2010 and 2020Footnote 1 confirming the PV generation as one of the key energy technologies in the energy transition.

The possibility of consuming the self-produced energy has changed the role of the end-users in the energy supply chain. “Prosumer” is the term used to designate this new entity. PV systems are typically integrated with storage devices to mitigate the effects of the intermittent and unpredictable nature of solar production. Decoupling production from consumption, storage systems help to maximize the self-consumption, reducing the prosumer’s electricity bill. In addition to new energy solutions, the wide diffusion of “smart” devices, which can be easily scheduled and controlled, allows the definition of more efficient load profiles and the implementation of demand response programs. For this reason, prosumer’s role can go a step further, becoming now “prosumager,” thanks to the possibility to effectively plan and manage the local energy resources exploiting the flexibility of the controllable loads (see Sioshansi 2019; Lee and Choi 2020). As a further evolution in the energy sector, new forms of coalitions of heterogeneous end-users (simple consumers, prosumagers) are emerging worldwide. These aggregations can have different characteristics on the basis of the availability of resources, like microgrids (Werner and Remberg 2008) or Virtual Power Plants (VPP) (Martin-Martínez et al. 2008), and aim at creating a sort of cooperative system in which single users have economic benefits w.r.t. the standard retailers market (Ferrara et al. 2021). A coalition aggregates a number of users to act as a single operator in the power market and to fully exploit the available resources. The optimal management and operation of these emerging forms of aggregation pose new challenging decision problems. Just to name a few, we mention the management of shared resources (Beraldi et al. 2018), the definition of the optimal tariffs for the coalition members (Violi et al. 2018; Ferrara et al. 2021), the interaction between the aggregation and the power grid (Heredia et al. 2018). Considering all the mentioned problems, prosumagers play a crucial role and the efficient and effective management of the consumption profile and of the available resources becomes of fundamental importance also at the energy coalition level.

In this paper, we deal with the optimal HEM problem faced by a prosumager that can control part of the loads (the flexible ones) and manage the available resources eventually exchanging the energy produced locally with the distribution grid. Smart meters enable the real-time monitoring of energy production and consumption and the activation of household appliances according to the scheduled plan. The final aim is the minimization of the total electricity procurement cost taking also into account the user’s discomfort to shift flexible appliance load.

Due to its practical relevance, many contributions related to the HEM problem have been recently proposed, although a much greater effort is still required in defining optimization models including real features in order to improve the accuracy of the solutions provided (Benetti et al. 2016). Most of the contributions propose deterministic formulations that differ from the real features that are mathematically represented. Typically two types of load are considered: non-controllable and controllable. While the former must be activated at fixed hours of the day (e.g., refrigerator) or their activation cannot be scheduled (e.g., TV, lighting), the latter may operate at any time within a time interval specified by the end-user (e.g., washing machines, dryers) or the operating cycle can be intermittent (e.g., electric vehicle). Thus, depending on the electricity tariffs, it may result convenient to shift or to interrupt the use of some flexible appliances. Martinez-Pabon et al. proposed in Martinez-Pabon et al. (2018) a deterministic model for the optimal scheduling of the flexible appliances aimed at minimizing the total energy cost. Yahia and Pradhan extended in Yahia and Pradhan (2018) the model by incorporating the consumer’s preference by a bi-objective function where the first term accounts for the energy cost, whereas the second one for the “inconvenience”, measured in terms of disparity between the preferred and the optimal schedule. Some other authors consider the inconvenience issue by modeling the consumer’s preferences as a constraint (Sou et al. 2011). In Wang et al. (2015), the robust-index method is proposed for the household load scheduling in order to handle the uncertainty due to the customer behavior while minimizing the comfort violation.

Some contributions integrate the scheduling with the optimal management of local resources. We mention the recent paper by Belli et al. 2019 where the authors propose a mixed-integer problem that also accounts for the management of thermal equipment. In Althaher et al. (2015), the authors deal with the scheduling of appliances and of energy resources under user’s comfort level constraints by means of a mixed-integer nonlinear programming model. A home energy consumption model for smart grid households with energy storage systems under variable electricity tariffs is proposed in Rajasekharan and Koivunen (2014). Recently, in Li et al. (2018) the authors proposed a quality of experience (QoE)-aware smart appliance control algorithm for the smart HEM system with renewable energy sources and electric vehicles in order to reduce the peak load and the overall procurement cost. A hierarchical deep reinforcement learning method is proposed in Lee and Choi (2020) for the optimal scheduling of smart home appliances and distributed energy resources.

Few papers acknowledge the importance of explicitly accounting for the inherent uncertainty affecting the main problem parameters. We cite the contribution by Chen et al. who proposed in Chen et al. (2013) a stochastic scheduling technique which involves an energy adaptation variable \(\beta \) to model the stochastic consumption patterns of the various household appliances. Correa-Florez et al. proposed in Correa-Florez et al. (2018) a stochastic programming model for the optimal management of the prosumer’s resources without accounting for the scheduling of the controllable loads. For further references on HEM contributions we remind to the recent survey in Leitão et al. (2020).

Our paper contributes to the scientific literature by proposing a two-stage stochastic programming model that integrates the optimal management of the available resources with the scheduling of heterogeneous controllable loads. This work extends the preliminary formulation proposed in Beraldi et al. (2019) by including and modeling the presence of three kinds of controllable appliances, and for each of them defining a specific regret measure. The aim is the minimization of the overall cost, without exceeding a certain discomfort level for each category of controllable appliances. An extensive computational experience has shown how the flexibility offered by the decision support model allows a significant cost reduction and how the attitude of the user for an eventual discomfort has an impact from an economic point of view.

The rest of the paper is organized as follows. Section 2 introduces the problem and the stochastic formulation. Section 3 is devoted to the presentation of the numerical results carried out by considering a real case study. Concluding remarks and future research developments are discussed in Sect. 4.

2 Problem definition and formulation

We consider a residential prosumager equipped with a system of PV panels and a battery energy storage (BES) device of given sizes.

The prosumager’s loads are classified into uncontrollable and controllable (see Fig. 1). Oven, refrigerator and lighting belong to the first group: they are loads that are not deemed for control and define the baseline demand assumed to be uncertain.

Fig. 1
figure 1

Overview of the prosumager’s home loads and resources

The controllable loads can be further divided into three sets: shiftable noninterruptible (SNI), shiftable interruptible (SI) and thermostatically controllable. The first set contains appliances that can be scheduled within a certain time window, but whose operation cycle cannot be interrupted once started (for example, washing machine). The second set includes appliances whose operation can be interrupted as long as a given amount of energy is supplied during a specified time slot, e.g., electrical vehicles (EV). Finally, in the third category there are appliances, such as the air conditioning system (AC), that can be switched on/off or supplied at a fraction of the nominal power according to the parameterization of a thermostat.

Flexible loads allow the prosumager to control, to some extent, the energy consumption patterns by properly defining the time of operations. For example, dishwasher can operate during hours with higher solar energy supply or when the electricity rates are lower.

The integration of the scheduling decisions makes the overall problem more involved entailing the use of binary decision variables. Moreover, the problem is clearly affected by uncertainty since the main input data, e.g., the solar production, the temperature used to control the thermostatic loads, are not known being influenced by the meteorological conditions.

We model the HEM problem with flexible loads by the stochastic programming paradigm and we represent the uncertain parameters by random variables defined on a given probability space (\(\Omega \), \(\mathcal {F}\), \(\mathrm{I\!P}\)). Under the assumption of discrete distributions, we consider a set \(\mathcal {S}=\{1,\ldots ,S\}\) of future realizations, “scenarios”, each one occurring with a probability \(\pi ^s\).

The problem is solved every day with updated data and provides the optimal operation of the household resources and the scheduling of the flexible loads for the next day. We assume that the daily horizon \(\mathcal {T}\) is divided in time steps (typical hours or fractions) \(t = 1,\ldots , T\) and we denote by \(D_{ts}\) the base load at time t under scenario s. As for the flexible appliances, some preference data, eventually changing from day to day, may be specified.

We denote by \(\mathcal {K}=\{1,\dots ,K\}\) the set of the SNI loads. For each appliance \(k \in \mathcal {K}\), we denote by \([l_k, u_k]\) the comfort time window and by \(st_k\) the preferred starting time. Moreover, we assume that the operation cycle is divided in \(n_k\) stages and we denote by \(d_{kq}\) the required energy at each stage \(q = 1,\ldots , n_k\). This general representation (see, for example, Soares et al. (2020)) allows to more faithfully model the actual operation cycle overcoming the unrealistic assumption to supply an appliance with a constant amount of energy for service completion. The activation of some SNI appliances can be constrained by precedence relations. For example, the operation of a clothes dryer follows that of the washing machine. To mathematically represent these relations, we introduce a binary parameter \(f_{ki}\) taking the value 1 if load k cannot start before load i (\(k,i\in \mathcal {K}\)), and 0 otherwise. Moreover, we denote with \(g_{ki}\) the minimum number of time steps of delay (if any) between the operation of k and i.

We further denote by \(\mathcal {J}=\{1,\ldots ,J\}\) the set of the SI appliances. For each \(j \in \mathcal {J}\) the prosumager can specify a working time window \([l_j,u_j]\), during which a given amount of energy, denoted by \(d_j\), should be supplied.

As for the thermostatically controllable loads, we model an AC system. Its operation (see, for example, Lee and Choi 2020; Liu et al. 2019; Soares et al. 2020) depends on some specific environmental and technical parameters, represented by the coefficients \(\alpha \) and \(\beta \), and by the uncertain outdoor temperature denoted, for each time step t and scenario s, by \(\theta ^{O}_{ts}\).

The proposed model takes into account the possibility of limiting the discomfort due to the appliance scheduling. Due to the nature of the loads, we consider different regret measures and we assume a maximum cumulative dissatisfaction value for each type. In particular, for the appliances \(k \in \mathcal {K}\) we define a unit regret rate \(r_k\) for each time step shifting from the preferred starting time \(st_k\). As for the SI appliances, the regret is related to the number of time steps to complete the operation cycle, assuming that a shorter time is preferable. Finally, for the AC we model the user’s regret in terms of deviation of the indoor temperature from a user-defined reference value \(\Theta ^{\mathrm {ref}}_t\) for each time step t.

For each time step t, the overall demand is satisfied at least partially by the production from the PV panels, denoted, for each scenario s, by \(R_{ts}\). Unused energy can be stored in the BES and used later or eventually fed back, if convenient. We denote by C the nominal capacity of the BES and by \(\eta _{\mathrm {in}}\) and \(\eta _{\mathrm {out}}\) the efficiency rate for energy injection and withdrawal. Moreover, we indicate by \(\varphi ^{LB}\) and \(\varphi ^{UB}\) the BES operative range in terms of minimum and maximum percentage of the nominal capacity. We assume that the prosumager belongs to an energy aggregation and that can purchase and/or selling electricity at known rates, denoted by \(P_t\) and \(W_t\), respectively (Ferrara et al. 2021).

The main decisions in the proposed formulation refer to the scheduling of the different types of household appliances, the management of the local resources and the eventual purchase (or sale) of energy from the aggregation. While some choices should be taken in advance without knowing the realization of the random parameters, other decisions can be postponed and used as corrective actions to guarantee the satisfaction of the stochastic constraints under each scenario. In the proposed model, first stage decisions refer to the scheduling of the flexible loads. In particular, for each \(k \in \mathcal {K}\) we denote by \(\delta _{kqt}\) the binary variable taking value 1 if the load appliance k is “on” in the stage q at time t and 0 otherwise. Similarly, for the appliance \(j \in \mathcal {J}\), the binary variable \(\gamma _{jt}\) is 1 if the SI appliance is “on” at time step t. Finally, we denote by \(E_{jt}\) the energy amount reserved to j at time t.

Second stage decisions are scenario-dependent actions. They refer to the AC operation, the management of the storage system and the buy and selling decisions. In particular, for each scenario s and time step t, we denote by \(E^{AC}_{ts}\) the amount of energy consumed for regulating the indoor temperature denoted by \(\theta ^{I}_{ts}\). As regards the BES, we indicate by \(SL_{ts}\) the state of charge and by \(SIN_{ts}\) and \(SOUT_{ts}\) the amount charged in and discharged from the system at time t under scenario s. Finally, \(x_{ts}\) and \(y_{ts}\) represent the amount of energy to purchase from and sell to the coalition at time step t under scenario s, respectively. The proposed mathematical formulation is reported below.

$$\begin{aligned}&\min z = \sum _{s=1}^S \pi ^s \sum _{t=1}^T (P_t x_{ts} - W_t y_{t}) \end{aligned}$$
(1)
$$\begin{aligned}&s.t. \nonumber \\&\quad x_{ts} + SOUT_{ts} - SIN_{ts} - y_{ts} = D_{ts} - R_{ts} \nonumber \\&\quad \ \ \ \ \ \ \ + \sum _{k = 1}^K \sum _{q = 1}^{n_k} d_{kq} \delta _{kqt} + \sum _{j = 1}^J E_{jt} + E^{AC}_{ts} \nonumber \\&\quad \forall t \in \mathcal {T}, \forall s \in \mathcal {S} \end{aligned}$$
(2)
$$\begin{aligned}&\delta _{k(q+1)(t+1)} \ge \delta _{kqt} \nonumber \\&\quad \forall k \in \mathcal {K}, q=1,\ldots ,n_k-1, l_k \le t \le u_k-1 \end{aligned}$$
(3)
$$\begin{aligned}&\sum _{t=l_k}^{u_k} \delta _{kqt} = 1\qquad \qquad \ \forall k \in \mathcal {K}, q=1,\ldots ,n_k \end{aligned}$$
(4)
$$\begin{aligned}&\sum _{t=l_k}^{u_k-n_k+1} \delta _{k1t} = 1 \qquad \ \forall k \in \mathcal {K} \end{aligned}$$
(5)
$$\begin{aligned}&\sum _{q=1}^{n_k} \delta _{kqt} \le 1 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall k \in \mathcal {K}, l_k \le t \le u_k \end{aligned}$$
(6)
$$\begin{aligned}&\delta _{k1t} \le \sum _{h=l_k}^{t-g_{ki}}\delta _{i1h} l_k \le t \le u_k, \ \ \ \ \ \ \ \ \ \forall (k,i) \in \mathcal {K}|f_{ki}=1 \end{aligned}$$
(7)
$$\begin{aligned}&\sum _{t = l_j}^{u_j} E_{jt} = d_j \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall j \in \mathcal {J} \end{aligned}$$
(8)
$$\begin{aligned}&E^{\mathrm {Min}}_{j} \gamma _{jt} \le E_{jt} \le E^{\mathrm {Max}}_{j} \gamma _{jt} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall j \in \mathcal {J}, l_j \le t \le u_j \end{aligned}$$
(9)
$$\begin{aligned}&\theta ^I_{ts} = \theta ^{I}_{t-1 s} + \alpha (\theta ^O_{ts} - \theta ^{I}_{t-1 s}) + \beta E^{AC}_{ts} \nonumber \\&\forall t \in \mathcal {T}, \forall s \in \mathcal {S} \end{aligned}$$
(10)
$$\begin{aligned}&\theta ^{\mathrm {Min}}_t \le \theta ^I_{ts} \le \theta ^{\mathrm {Max}}_t \forall t \in \mathcal {T}, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall s \in \mathcal {S} \end{aligned}$$
(11)
$$\begin{aligned}&E^{AC}_{ts} \le E^{AC,Max} \forall t \in \mathcal {T}, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall s \in \mathcal {S} \end{aligned}$$
(12)
$$\begin{aligned}&SL_{ts} = SL_{t-1 s} + \eta _{\mathrm {in}} SIN_{ts} - \frac{SOUT_{ts}}{\eta _{\mathrm {out}}}\nonumber \\&\quad \forall t \in \mathcal {T}, \forall s \in \mathcal {S} \end{aligned}$$
(13)
$$\begin{aligned}&\varphi ^{LB} C \le SL_{ts} \le \varphi ^{UB} C \forall t \in \mathcal {T}, \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall s \in \mathcal {S} \end{aligned}$$
(14)
$$\begin{aligned}&\sum _{j=1}^J \sum _{t=l_j}^{u_j} \gamma _{jt} \le V^{SI} \end{aligned}$$
(15)
$$\begin{aligned}&\sum _{k=1}^K r_k |st_k - \sum _{t=l_k}^{u_k} t \delta _{k1t}| \le V^{SNI} \end{aligned}$$
(16)
$$\begin{aligned}&\sum _{s=1}^S \pi _s \sum _{t = 1}^T | \theta ^I_{ts} - \theta ^{rif}_t| \le V^{AC} \end{aligned}$$
(17)
$$\begin{aligned}&x_{ts}, y_{ts},\ E^{AC}_{ts}, \ \theta ^{I}_{ts}, \ SL_{ts}, \ SIN_{ts}, \ SOUT_{ts} \ge 0 \nonumber \\&\quad \forall t \in \mathcal {T}, \forall s \in \mathcal {S} \end{aligned}$$
(18)
$$\begin{aligned}&\delta _{kqt} \in \{0,1\} \nonumber \\&\quad \forall k \in \mathcal {K}, q=1,\ldots ,n_k, l_k \le t \le u_k \end{aligned}$$
(19)
$$\begin{aligned}&\gamma _{jt} \in \{0,1\} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall j \in \mathcal {J}, l_j \le t \le u_j \end{aligned}$$
(20)

The objective function (1) aims at minimizing the expected value of the difference between total cost of energy purchased and the revenue for energy selling. Constraint (2) represents the energy balance in each time step t under each scenario s, by pairing the overall demand with the energy procured from all the available sources. Conditions (3)–(5) ensure that the operation cycle of appliance k is performed in exactly \(n_k\) consecutive time steps. In particular, with (3) the following condition is modeled: if the appliance k is “on” at time t and stage q (\(< n_k\)), then it must be “on” at time \(t+1\) and stage \(q+1\). The execution of each stage q just once is guaranteed by (4), while Condition (5) imposes that the appliance must be activated within its time window. Constraints (6) impose that the load can be operating in at most one operation stage in each time period. Constraints (7) model the precedence relation and the eventual delay between two SNI loads, by imposing that if the operation cycle of k is conditioned by that of i (\(f_{ki}=1\)) then k can start at least \(g_{ki}\) time steps after i. Conditions (8) assure that the overall demand of the SI loads will be satisfied within the operating time window. By Condition (9) we impose upper and lower bounds (\(E^{\mathrm {Max}}_{j}, E^{\mathrm {Min}}_{j}\)) on the energy amount absorbed by a SI load if it is active.

Fig. 2
figure 2

Purchasing prices for the different seasons

Table 1 SNI devices parameters

Equation (10) models the indoor temperature dynamics, i.e., the value at the end of time t is a function of both indoor and outdoor temperatures at \(t-1\) and of the energy consumed by the AC operation. Parameters \(\alpha \) and \(\beta \) denote the thermal condition surrounding the AC system and its coefficient of performance (see also Antunes et al. 2020). The modeling of the temperature dynamics we are considering is suitable for both heating and cooling mode: the difference is in the value of parameter \(\beta \), which is negative when the AC operates for cooling and positive otherwise. Constraints (11) set the feasible range for the indoor temperature. By (12) we impose that the energy devoted to the AC operation cannot exceed the maximum value allowed for the system (\(E^{AC,Max}\)).

Conditions (13)–(14) model the technological constraints of the storage system. In particular, (13) states the energy level balance from one time step to the next one. We note that for \(t=1\), the state of charge at previous time is a known value. Constraint (14) bounds the energy level within its operative range defined as function of the nominal capacity. The regret limits for the different sets of flexible appliances are modeled by means of (15)–(17). By (15) we impose that the overall regret for the SI loads, measured in terms of number of activation time steps, cannot exceed a user-defined threshold \(V^{SI}\). Similarly, Condition (16) limits to the value \(V^{SNI}\) the overall regret due to the shifting of the start-up time of the SNI appliances from the preferred starting time. The regret related to the indoor temperature is modeled by (17), where the expected value of the temperature gap from the desired value for all the day is bounded by a threshold \(V^{AC}\). Finally, constraints (18)–(20) define the nature of decision variables.

Regret constraints (16) and (17) are clearly nonlinear, due to the presence of the absolute value operator, but they can be easily linearized by considering additional nonnegative variables, \(\varepsilon _k^+\) and \(\varepsilon _k^+\) for the SNI appliances and \(\vartheta ^{s+}_t\) and \(\vartheta ^{s-}_t\) for the AC system, and Conditions (21)-(26):

$$\begin{aligned}&\sum _{k = 1}^K r_k(\epsilon ^+_{k} + \epsilon ^-_{k}) \le V^{SNI} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \end{aligned}$$
(21)
$$\begin{aligned}&\epsilon ^+_{k} \ge st_k - \sum _{t = 1}^T t\delta _{kt} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall k \in \mathcal {K} \end{aligned}$$
(22)
$$\begin{aligned}&\epsilon ^-_{k} \ge \sum _{t =1}^T t\delta _{kt} - st_k \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall k \in \mathcal {K} \end{aligned}$$
(23)
$$\begin{aligned}&\sum _{s =1}^S \pi _s \sum _{t = 1}^T (\vartheta ^{s+}_t + \vartheta ^{s-}_t) \le V^{AC} \end{aligned}$$
(24)
$$\begin{aligned}&\vartheta ^{s+}_t \ge \theta ^{I,s}_t - \theta ^{rif}_t \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall s \in \mathcal {S}, \forall t \in \mathcal {T} \end{aligned}$$
(25)
$$\begin{aligned}&\vartheta ^{s-}_t \ge \theta ^{rif}_t - \theta ^{I,s}_t \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \forall s \in \mathcal {S}, \forall t \in \mathcal {T} \end{aligned}$$
(26)

The mathematical formulation belongs to the class of mixed-integer linear problems and depending on the number of considered scenarios the solution process can be computationally demanding. However, for the test cases considered hereafter, the use of off-of-the-shelf software is still possible and allows to obtain the optimal solution in a limited amount of time.

3 Computational experience

In this section, we report on the computational experiments carried out with the aim of evaluating the effectiveness of the proposed approach as tool to support the prosumager’s decisions. First, we introduce the case study and then we present and discuss the numerical results. The model has been implemented by integrating GAMS 24.7.1Footnote 2 as algebraic modeling language, with CPLEX 12.6.1Footnote 3 as solver for mixed-integer linear problems, and MATLAB R2015Footnote 4 for the scenario generation and parameter setup phases. All the test cases have been solved on a PC Intel Core I7 7700 HQ (2.80 GHz) with 16 GB of DDR4 RAM.

3.1 Experimental setting and data

The considered case study refers to a residential prosumager equipped with a system of PV panels of nominal power of 6 \(kW_p\) and a Li-Po battery with a nominal capacity of 10 kW. Other technical parameters of the BES referring to \(\eta _{\mathrm {in}}\), \(\eta _{\mathrm {out}}\), \(\phi ^{LB}\) and \(\phi ^{LB}\) are set to 0.89, 0.99, 0.2, 0.9, respectively.

Different test cases have been generated by considering seasonal variations, which have an impact on the expected baseline demand, the self-production, the external temperature and so on. In particular, for each season we have run the model for one reference day, then annual values of costs have been derived by aggregating and properly scaling the results. For the sake of simplicity, the elementary time step has been set to 1 h. However, a different time granularity can be considered as well.

The purchasing and selling prices are assumed to be known in advance and vary according to a Time of Use block structure. In the Italian market, taken as reference, the hours of each day are typically divided into three blocks (F1, F2 and F3), i.e., peak, intermediate and off-peak. Figure 2 shows the purchasing prices for the typical reference days.

We have considered 6 flexible appliances, 4 are classified as SNI loads and 2 as SI ones. Tables 1 and 2 report the main operation characteristics. We have considered one precedence constraint relating the first two SNI loads. In particular, the tumble dryer is required to start at least 2 h after the washing machine.

We have considered an AC system with a nominal power of 3 kW that can operate in both heating and cooling mode. The operating conditions for each season are reported in Table 3. Without any loss of generality, the values of parameters \(\theta ^{rif}\), \(\theta ^{\mathrm {Min}}\) and \(\theta ^{\mathrm {Max}}\) have been considered constant over the day in each season. From an analysis of expected values of external temperatures, we have assumed that just during summer days the AC system works in cooling mode, that is with a negative value of \(\beta \).

Table 2 SI devices parameters
Table 3 AC system operating conditions
Fig. 3
figure 3

Production, demand levels and external temperature in a summer day

The results reported in the following have been collected by considering regret thresholds equal to 7, 15 and 60 for the SNI, SI appliances and the AC system, respectively. These values have been set by considering an average discomfort for the end-user. For example, \(V^{SNI}=7\) means that for the 4 SNI appliances the overall deviation with respect to the default starting time cannot exceed 7 h. Similarly, the overall maximum charging time for the SI loads has been set to 1.5 times the minimum value. As regards the indoor temperature, we have allowed an average deviation of less than 3 degrees for each hour. An analysis of the results for different values of regret thresholds is reported in Sect. 3.2.

As in any stochastic programming formulation, scenario generation represents a critical issue that impacts the robustness of the solutions (Beraldi et al. 2010). In our model, the uncertain parameters refer to the baseline loads, the external temperature and the PV production. This latter is influenced, in turn, by the solar radiation and, thus, by the meteorological conditions (Algieri et al. 2021). Since the problem is solved on a daily basis, new scenario sets are iteratively generated by using each time updated and more reliable forecasts. In particular, for the solar radiation and external temperature, we have considered random variations in the range of \([\pm 5 \%]\) with respect to the forecast values. As for the base load, starting from the average values computed considering the hourly consumption of the last month, scenarios are generated by considering random variations of \([\pm 10\%]\). Figure 3 reports the values of the PV production, baseline demand and external temperature for each hour in a typical summer day. Starting from the original tree, the scenario reduction technique proposed in Beraldi and Bruni (2013) have been applied to reduce the cardinality of the scenario set. The results reported hereafter have been collected by considering for each test case a set of 500 scenarios.

3.2 Numerical results

The problem solution provides the prosumager with the optimal daily operation strategy by taking into account the flexibility of the controllable loads. Figure 4 reports the solution for a typical summer day under a given scenario. We may observe that, compatible with the time windows, flexible loads are scheduled during the central hours of the day when the solar supply is higher. The amount in excess to demand is either stored in the battery and used in the evening or fed back to the grid achieving a revenue that impacts on the daily procurement costs.

Fig. 4
figure 4

Operation plan for a summer day

At least for the summer day, the self-sufficient rate, computed as the ratio of energy produced over amount consumed, is very high, highlighting the advantage of the integrated energy procurement planning and flexible loads management.

To further investigate the benefits deriving from the load flexibility, we have compared the solutions provided by the proposed model (referred to as FF) with those obtained considering as controllable only the SNI loads, as proposed in Beraldi et al. (2019). In this case, both the SI loads and the AC system are included in the baseline loads. In particular, the load of the SI appliances is added to the hourly demand within the corresponding operation time windows and the indoor temperature has been set to the reference value \(\Theta ^{rif}\). We refer to this second model where the flexibility is only partially exploited as FP. Table 4 shows a comparison of the FF and FP models in terms of procurement daily costs for the different typical days. The last row reports the yearly cost considering the number of typical days in each season. As can be seen from the results, exploiting the flexibility of the load allows for significant savings. The advantage is more evident for spring and summer days when PV production is greater and the prosumer has a greater flexibility in energy allocation.

Table 4 Procurement cost [€] comparison: FP versus FF

Additional experiments have been carried out to investigate how the variation of the regret thresholds for the different categories of controllable appliances, impact the solution. Table 5 reports the procurement cost for the summer reference day obtained by varying one of the three regret thresholds at a time. Similar results have been obtained also for the other reference days.

Table 5 Solutions for different regret thresholds
Table 6 Value of stochastic solution (%)
Fig. 5
figure 5

Out-of-sample analysis

As expected, for each category of controllable appliances a less restrictive regret threshold allows to increase the economic benefit. For example, for the SNI loads, we recall that a value \(V^{SNI}=0\) states that appliances cannot be controlled and their starting time is fixed to the standard hour. As we increase the value of \(V^{SNI}\), a more flexible scheduling can be obtained achieving higher savings in terms of electricity procurement cost. The same behavior can be observed for the other regret thresholds. In particular, for the indoor temperature regret the greater procurement cost variability has been observed. This analysis outlines the need to find the best trade-off between economic benefit from the possibility to control various types of devices and the potential discomfort due to the scheduling and/or the operation conditions of these appliances. Under this respect, the proposed approach provides valuable support.

3.2.1 Impact of stochastic solution

Additional experiments have been carried out to evaluate the benefit deriving from the solution of the stochastic formulation with respect to a deterministic counterpart. To this aim, we have computed the value of the stochastic solution (VSS for short) (see, for example, Ruszczyński and Shapiro (2003)). This measure is defined as the difference between the objective function value of the stochastic model and the one obtained by solving the same stochastic problem with the first-stage variables fixed to the values of the optimal solution of the deterministic problem, which considers the expected values of the uncertain parameters. Table 6 reports the relative VSS expressed in percentage for the different reference days.

The results show the advantage of the stochastic formulation for each reference day and for the entire year. As expected, in spring and summer, when the solar production is higher and more flexibility is allowed, the VSS values are larger.

Table 7 Solution process statistics for the summer day instance
Fig. 6
figure 6

Solution time [s] and number of B&C nodes

The value of explicitly dealing with uncertainty is confirmed by a further analysis carried out on an out-of-sample basis. In particular, we have compared the solution provided by the proposed stochastic model with the respect to its deterministic counterpart. For each reference day, we have solved the stochastic and the deterministic model and implemented the first stage decisions. Then, on the basis of the real values observed for the uncertain parameters, an energy balance has been performed for each time step, by considering first the available storage system energy level and its residual capacity. If this adjustment was not feasible, because of some constraint violation, a second balancing has been performed by buying and selling energy from the grid. After the energy balancing, costs and eventual revenues related to implemented decisions have been economically evaluated. Figure 5 shows the comparison between the stochastic model and the deterministic one, in terms of overall procurement cost for each reference day.

Looking at the results, we may notice the clear advantage deriving from the adoption of the stochastic model over the deterministic counterpart.

We finally comment on the computational effort that typically represents the main concern limiting the application of stochastic formulations. We notice that in our case the computational burden is quite limited and that off-of-shelf solvers can be applied to get the optimal solution in a limited amount of time. In particular, in our experiments we have used CPLEX with default settings and just one thread. We point out that in the formulation first-stage linking variables refer to the scheduling of the flexible loads and are limited in number. In particular, their maximum number is \(T (n_k K +J)\), but the actual number is lower since outside the time windows the corresponding variables can be set to 0. Other reductions come from the eventual precedence relations. Overall, the number of variables and constraints before and after the preprocessing phase applied by CPLEX is reported in Table 7. The results refer to a typical winter day, but similar performance has been observed also for the other tested cases. Figure 6 shows the solution time (in seconds) for an increasing number of scenarios and the number of nodes explored during the application of the Branch & Cut algorithm. Looking at the results, we may appreciate the impact of a more faithful representation of the uncertainty on the computational time. The increase in the solution time for a higher number of scenarios is significant but not so relevant: for example, from 250 to 500 scenarios the growth is less than 300%, making the problem still affordable (less than 25 min). This is due to the fact that all the binary variables refer to first-stage decisions and are not related to the scenario number. Additionally, we outline how the integrality gap at the root node is quite low (about 20%) for all the reported instances. Finally, even for the largest test case a good in-sample stability has been observed.

4 Conclusions

The paper addresses the problem faced by a residential prosumager in the optimal operation of an integrated PV-BES system by exploiting the flexibility of the controllable loads. In particular, three main classes of loads have been considered: shiftable, interruptible and thermostatically controllable, each one with a specific representation of the energy consumption profile and a potential discomfort rate for the user. The proposed stochastic programming model allows to account for the inherent uncertainty affecting the main model parameters. The solution provides the prosumager with the optimal scheduling of the controllable loads and the operation of the BES that guarantee the minimum expected energy procurement cost, taking into account the overall comfort.

Preliminary computational experiments have been carried out by considering a real case study and different seasonal conditions have been evaluated. The results have shown that significant savings can be achieved when the flexibility of the controllable loads is exploited. Moreover, by varying the regret threshold values different solutions can be gained reflecting a different importance attributed to the user’s comfort. The value of the VSS and the out-of-sample analysis highlight the importance of explicitly taking into account uncertainty in model parameters.

An interesting line of research would consider the integration of other technologies that could be present at prosumager’s home. While the model only considers the electric load, it could be extended to also account for the thermal demand. In this case, the management of a boiler, eventually integrated with solar collectors, and a thermal energy storage system could be considered. The integrated configuration would lead to additional savings contributing in the direction of designing more sustainable energy solutions.