PV-battery microgrid: when to charge, when to discharge?
Cost-optimal management of solar generation and a home battery with a grid connection, under uncertain weather and demand.
Paul Honore Takam · Kessel Wilson Mbouche Nzali Manuscript in preparation
Choose the system
Choose a season, a battery size and a spread. All results are precomputed.
Impact of battery size and spread
Expected cost of one week. Tap a point to select that value.
The charging and discharging power grows with the size (20 kWh gives 20 kW). Every week starts with the battery at 70 % and is settled against that level at the end. A large battery loses more energy through self-discharge, so beyond some size the cost rises again. Investment costs of the battery are not included.
Over a year (study with one week per season at a spread of 0.15 €): 30 kWh has the lowest operating cost, about 2590 €, only about 27 € less than 20 kWh. At an illustrative price of 300 € per kWh and an annuity factor of 0.08, 10 more kWh cost about 240 € per year. With investment included, 10 kWh is therefore the most economical of the sizes studied (10 to 100 kWh).
Live simulation of one week
Drag the slider or tap the chart to jump to any hour.
Same week, three strategies
With a battery, the total cost includes the final settlement: a penalty below the reference level of 70 % and a credit above it. A negative cost means that sales exceed purchases.
Value function and optimal decision rule
Both follow the simulation in steps of three hours, at a typical cloudiness. Drag the surface to turn it, and move over the map to read a value. The dot marks the current state.
All strategies face the same random weeks; the battery starts at 70 %. The ± values are 95 % confidence intervals.
How to read this demo
Value function: the expected electricity cost from the selected hour to the end of the week, for each battery level and demand.
Optimal decision rule: what the battery should do in that situation. It can store solar surplus, cover demand, or wait and trade with the grid.
Self-consumption rule: always store the surplus and always cover the demand, as far as the battery allows.
No battery: the surplus is sold and the missing power is bought. This cost does not depend on the battery size.
Spread: with a small spread, feeding solar power into the grid pays almost as much as buying costs, so storing it is worth little. A large spread rewards using your own solar power.
Cite and license
Takam, P. H. and Mbouche Nzali, K. W. (2026). PV-battery microgrid connected to the grid: interactive demo. https://paulhonore.github.io/pv-microgrid-demo/. Companion to the manuscript “Optimal Quantization for the Cost-Optimal Control of a Photovoltaic-Based Microgrid under Uncertainty” (in preparation).
This page and its precomputed results are released under the Creative Commons Attribution 4.0 license (CC BY 4.0). The research code is not part of this repository.