In my research, I focus on optimizing the scheduling of building photovoltaic (PV) storage systems, which is crucial for advancing new power systems. The inherent randomness and intermittency of PV generation, combined with the human-influenced variability of building loads, make accurate prediction extremely challenging. To address this dual uncertainty, I propose a stochastic optimization method based on multi-scenario sampling. I begin by constructing hourly prediction models for both building electricity consumption and PV generation using the eXtreme Gradient Boosting (XGBoost) algorithm. Then, I employ Latin hypercube sampling combined with simultaneous backward reduction to generate typical PV generation and load scenarios. Considering the actual control logic of residential types of solar inverter and equipment operational constraints, I formulate an objective function to minimize daily net electricity cost, which I solve using a genetic algorithm. My simulation results show that when prediction accuracy is high, the proposed stochastic strategy yields only marginal improvements over traditional deterministic optimization. However, when prediction accuracy is low, the stochastic strategy significantly outperforms the traditional one. Over a 7-day test period, the maximum daily net electricity cost reduction reaches 10.32% when net cost is positive, and profit increases by 36.69% when net cost is negative. Finally, I validate the strategy through experiments on a real PV-storage system, achieving a 16.49% reduction in net electricity cost compared to the inverter default control strategy.
1. Introduction
The integration of photovoltaic systems with building energy storage is a key measure to achieve carbon neutrality and transform the energy structure. However, the mismatch between PV generation and building load profiles poses significant challenges for energy scheduling. Many existing studies have developed optimization models for PV-storage systems, but they often rely on perfect forecasts and ignore the operational constraints of real types of solar inverter. Moreover, the uncertainty in both PV generation and load demand is frequently handled using robust optimization, which tends to be overly conservative. In contrast, scenario-based stochastic optimization can better capture the probabilistic nature of uncertainties. My work aims to fill these gaps by proposing a practical optimization strategy that explicitly considers the inverter’s control logic and various types of solar inverter operating modes, while also addressing source-load uncertainty through scenario generation.
2. Methodology
2.1 Prediction Model Construction
I use XGBoost to build hourly prediction models for building electricity consumption and PV generation. The input features for the load model include hour of day, workday indicator, outdoor temperature, and solar radiation. For PV generation, the inputs are hour of day, temperature, and solar radiation. I train the models using historical data from a real office building in Shenzhen and corresponding weather data. The prediction performance is evaluated using root mean square error (RMSE) and coefficient of determination (R²).
The formulas are:
$$RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^{n} (\hat{y}_i – y_i)^2}$$
$$R^2 = 1 – \frac{\sum_{i=1}^{n} (\hat{y}_i – \bar{y})^2}{\sum_{i=1}^{n} (y_i – \bar{y})^2}$$
2.2 Uncertainty Modeling and Scenario Generation
I derive the probability distributions of prediction errors for PV generation and load. For load, I separate workday and non-workday error distributions due to their distinct patterns. The cumulative distribution function (CDF) of the error e is:
$$F(e) = \frac{1}{n}\sum_{i=1}^{n} \mathbf{1}(e_i \le e)$$
Using Latin hypercube sampling, I generate a large set of scenarios from these distributions. Then, I apply simultaneous backward reduction to reduce the scenario set to 5 typical PV scenarios and 5 typical load scenarios while preserving their probabilities. The Euclidean distance between two scenarios xi and xj is:
$$D_k(x_i, x_j) = \sqrt{\sum_{t} (x_{i,t} – x_{j,t})^2}$$
I combine the PV and load scenarios to form 25 joint scenarios with associated probabilities.
2.3 Inverter Control Logic Modeling
I build an experimental platform consisting of a hybrid inverter, lithium iron phosphate battery, PV array simulator, and adjustable load box. The real inverter allows me to set three parameters per hour: operating mode, cutoff state-of-charge (SOC), and charge/discharge power. Through preliminary experiments, I find that optimizing the hourly operating mode and cutoff SOC (24×2 = 48 variables) is sufficient. The inverter supports three primary types of solar inverter operating modes: load priority, battery priority, and grid priority. Their control logics are described as follows:
- Load Priority: PV power first satisfies the load; excess PV charges the battery or feeds to the grid based on SOC.
- Battery Priority: PV power first charges the battery; only when the battery is full, PV supplies the load or grid.
- Grid Priority: PV power is preferentially fed to the grid; the battery can also discharge to the grid for profit.
I incorporate these logics into my optimization model as constraints.
3. Optimization Formulation
3.1 Objective Function
For deterministic optimization, the objective is to minimize the daily net electricity cost:
$$COST(d) = \sum_{t \in T} \left[ P_{\text{grid}}(t) \times C_e(t) – P_{\text{togrid}}(t) \times C_i(t) \right]$$
where Pgrid(t) is electricity purchased from the grid at hour t, Ce(t) is the purchase price, Ptogrid(t) is electricity sold to the grid, and Ci(t) is the feed-in tariff. The time-of-use prices are shown in Table 1.
| Period | Purchase price | Feed-in price |
|---|---|---|
| Valley (00:00-08:00) | 0.2894 | 0.2894 |
| Flat (08:00-10:00, 12:00-14:00, 19:00-24:00) | 1.0000 | 0.4000 |
| Peak (10:00-12:00, 14:00-19:00) | 1.3553 | 0.4000 |
For stochastic optimization, I minimize the expected cost over all scenarios:
$$COST(d) = \sum_{\omega \in \Omega} \text{prob}(\omega) \sum_{t \in T} \left[ P_{\text{grid}}(t,\omega) \times C_e(t) – P_{\text{togrid}}(t,\omega) \times C_i(t) \right]$$
3.2 Constraints
My constraints include energy balance and equipment limits. The energy flows are illustrated conceptually (without figure numbers), and I enforce:
PV generation allocation:
$$P_{pv}(t) = P_{pv,load}(t) + P_{pv,battery}(t) + P_{pv,grid}(t)$$
Grid purchase distribution:
$$P_{grid}(t) = P_{grid,load}(t) + P_{grid,battery}(t)$$
Grid feed-in sources:
$$P_{togrid}(t) = P_{pv,grid}(t) + P_{battery,grid}(t)$$
Battery charging:
$$P_{battery,charge}(t) = P_{pv,battery}(t) + P_{grid,battery}(t)$$
Battery discharging:
$$P_{battery,discharge}(t) = P_{battery,load}(t) + P_{battery,grid}(t)$$
Load balance:
$$P_{load}(t) = P_{pv,load}(t) + P_{grid,load}(t) + P_{battery,load}(t)$$
Equipment constraints include maximum PV input (9,280 W), battery charge/discharge power (≤5,120 W), and grid import/export power (≤6,080 W).
4. Simulation Case Study
4.1 Prediction Model Performance
I train the XGBoost model using data from April 18 to June 18, 2018, and validate it from June 19 to August 19, 2018. The prediction results show R² = 0.89 and RMSE = 0.69 kWh for PV generation, and R² = 0.90 and RMSE = 0.72 kWh for load. Table 2 lists the variance of prediction errors for each hour.
| Hour | PV σ² | Load (workday) σ² | Load (non-workday) σ² |
|---|---|---|---|
| 00:00 | 0.00 | 0.02 | 0.02 |
| 01:00 | 0.00 | 0.34 | 0.01 |
| 02:00 | 0.00 | 0.47 | 0.01 |
| … | … | … | … |
| 23:00 | 0.00 | 0.04 | 0.04 |
4.2 Scenario Reduction Results
I generate 5 typical PV scenarios and 5 typical load scenarios for both workdays and non-workdays. For example, on August 21 (workday), the combined 25 scenarios have probabilities as shown in Figure (not referenced). The stochastic optimization uses these scenarios to evaluate expected cost.
4.3 Performance Comparison under Different Prediction Accuracies
I compare the stochastic optimization strategy (considering uncertainty) with the traditional deterministic strategy at three prediction accuracy levels: R² = 0.90, 0.85, and 0.80. Tables 3–5 summarize the daily net electricity costs over 7 days (August 20–26). Negative values indicate profit.
| Date | Deterministic (CNY) | Stochastic (CNY) | Change |
|---|---|---|---|
| Aug 20 | 60.59 | 59.69 | -1.48% |
| Aug 21 | 43.09 | 41.97 | -2.60% |
| Aug 22 | 35.21 | 35.48 | +0.77% |
| Aug 23 | 55.88 | 56.22 | +0.61% |
| Aug 24 | 47.53 | 47.74 | +0.44% |
| Aug 25 | -15.24 | -14.30 | +6.17% |
| Aug 26 | -8.97 | -8.81 | +1.78% |
| Date | Deterministic (CNY) | Stochastic (CNY) | Change |
|---|---|---|---|
| Aug 20 | 62.55 | 58.77 | -6.04% |
| Aug 21 | 47.25 | 43.12 | -8.72% |
| Aug 22 | 37.95 | 35.23 | -7.17% |
| Aug 23 | 57.55 | 53.73 | -6.64% |
| Aug 24 | 54.86 | 51.65 | -5.85% |
| Aug 25 | -14.32 | -13.35 | +6.77% |
| Aug 26 | -9.14 | -8.98 | +1.75% |
| Date | Deterministic (CNY) | Stochastic (CNY) | Change |
|---|---|---|---|
| Aug 20 | 61.26 | 57.79 | -5.66% |
| Aug 21 | 46.97 | 42.38 | -9.77% |
| Aug 22 | 39.24 | 35.19 | -10.32% |
| Aug 23 | 55.49 | 51.59 | -7.21% |
| Aug 24 | 55.50 | 51.90 | -6.48% |
| Aug 25 | -13.35 | -13.43 | +0.06% |
| Aug 26 | -6.65 | -9.09 | -36.69% |
The results clearly show that when R² drops to 0.80, the stochastic strategy significantly reduces costs, especially when net cost is negative (profit increases by 36.69% on Aug 26). On most days with positive net cost, the maximum reduction is 10.32%.
5. Experimental Validation
To validate my approach in a real environment, I conducted experiments using the platform described earlier. I used a hybrid inverter that supports various types of solar inverter control modes. The experiment spanned three phases: first, I collected data from August 16 to September 15, 2024 to train a predictive model; second, I intentionally reduced the model accuracy to R² = 0.80 by tuning hyperparameters, simulating realistic imperfect forecasting; third, I tested the strategies on October 17, 2024.
I placed the image of the experimental setup here:

5.1 Default Load Priority Strategy
In the default load priority mode, the inverter charges the battery when PV exceeds load and discharges when load exceeds PV, until SOC reaches 10%. The net electricity cost for that day was 40.52 CNY.
5.2 Proposed Stochastic Optimization Strategy
I applied the stochastic optimization to determine the inverter settings for each hour. Table 6 shows the optimal operating mode and cutoff SOC for each hour (modes: 1=load priority, 2=battery priority, 3=grid priority).
| Hour | Mode | Cutoff SOC | Hour | Mode | Cutoff SOC |
|---|---|---|---|---|---|
| 00:00 | 2 | 51% | 12:00 | 1 | 72% |
| 01:00 | 2 | 87% | 13:00 | 2 | 87% |
| 02:00 | 2 | 87% | 14:00 | 1 | 37% |
| 03:00 | 2 | 95% | 15:00 | 1 | 32% |
| 04:00 | 2 | 87% | 16:00 | 1 | 45% |
| 05:00 | 2 | 100% | 17:00 | 1 | 10% |
| 06:00 | 2 | 65% | 18:00 | 1 | 10% |
| 07:00 | 2 | 63% | 19:00 | 1 | 10% |
| 08:00 | 1 | 59% | 20:00 | 1 | 10% |
| 09:00 | 1 | 59% | 21:00 | 1 | 10% |
| 10:00 | 1 | 86% | 22:00 | 1 | 10% |
| 11:00 | 1 | 68% | 23:00 | 3 | 10% |
The battery charges fully during valley hours (00:00–08:00) using grid power at low price, partially discharges during flat hours, charges again from excess PV, and then deep discharges during peak hours to 10% SOC. The resulting net electricity cost was 33.84 CNY, a 16.49% improvement over the default strategy. The computational time for each hourly optimization was approximately 30 seconds, meeting real-time requirements.
6. Conclusion
In this work, I have developed a stochastic optimization scheduling strategy for building PV-storage systems that accounts for source-load uncertainty and respects the operational logic of various types of solar inverter. My simulation study demonstrates that when prediction accuracy is low (R² = 0.80), the proposed method reduces daily net electricity cost by up to 10.32% for positive costs and increases profit by 36.69% for negative costs. The experimental validation on a real system confirms a 16.49% cost reduction compared to the default inverter control. These results highlight the practical value of my approach, especially in scenarios where forecasting performance is limited. By explicitly modeling different types of solar inverter operating modes, the strategy can be easily adapted to real-world hardware. Future work will explore the integration of battery degradation costs and more advanced scenario generation techniques.
