Control algorithms
Selling energy to the grid
Discharging the battery to the grid to sell stored energy when the injection price is high, an optional extension of cost optimization.
Under cost optimization the battery normally discharges to cover the site's own consumption, using stored energy instead of buying expensive grid energy. Selling energy to the grid (also called battery injection sales or discharge to grid) is an optional extension: when the injection (feed-in) price is high enough to be profitable, the algorithm discharges stored energy into the grid to earn revenue, on top of self-supply.

This is optional and off by default. See Enabling it below.
Enabling it
Selling energy to the grid is a per-project setting. Enable the Selling via battery injection toggle under Project settings.
- Disabled (default): the battery is never discharged just to feed the grid. Cost optimization only stores cheap/solar energy and releases it to cover the site's own deficits.
- Enabled: the algorithm additionally looks for profitable moments to inject stored energy into the grid, and plans extra discharge for them.
A second toggle, Grid charging for injection, additionally allows the algorithm to buy cheap grid energy purely to sell it back at the injection peaks (mode 3 below). It requires battery injection sales to be enabled and is likewise off by default.
Both only have an effect while the project runs cost optimization and no external signal partner is steering the installation.
Three ways to sell
Energy is always sold at the most profitable moments: the algorithm ranks the candidate slots by injection price and serves the highest price first. What differs between the modes is where the sold energy comes from.
| Mode | Source of the sold energy | When |
|---|---|---|
| 1. Selling surplus | Stored energy that is not needed for the upcoming consumption | Baseline behaviour once injection sales are enabled |
| 2. Selling beyond the surplus | Energy that would otherwise be kept for a later deficit | When the sale earns more than the later deficit costs |
| 3. Buying to sell | Grid energy bought at a cheap moment, purely to sell | Only with Grid charging for injection enabled |
1. Selling surplus
Part of what the battery stores is not needed for the site's upcoming consumption. That is the surplus, for example: more solar was stored during the day than the evening will use. The surplus is sold at the moment the injection price peaks.
2. Selling beyond the surplus
Energy that the plan would otherwise keep to cover a later deficit can also be sold, in two situations:
- The sale earns more than the deficit costs. The injection price now is more than the minimum price difference above that later consumption price. The algorithm sells the energy and covers the later need from the grid.
- The deficit can be refilled from a cheap window in between. Even when the later consumption price is higher than today's injection price, the sale still wins if cheap charging hours lie between the sale and the deficit. This lets the battery discharge at full power through an entire evening peak instead of holding energy back for the next day.
3. Buying to sell
With Grid charging for injection enabled, the algorithm buys grid energy at cheap moments purely to sell it back at the most profitable injection slots. It looks for earlier slots whose price clears the break-even after round-trip losses:
injection price ≥ charge price ÷ round-trip efficiency + minimum price difference
Round-trip efficiency is the share of the energy that remains after the charge and discharge losses. Each purchase is sized to deliver exactly the extra sale, so existing deficit coverage is unaffected. Purchases respect the battery capacity and the grid import limit. Nothing is bought when the sale can already be served by energy that is in the battery for free.
Stored energy and purchases are matched to the sales they serve best. Peaks before a cheap charging window are sold from storage, because nothing cheaper can reach them. Peaks after the window are funded by buying in the window, so equally priced sales on a later day never crowd out today's peak.
How it looks

Over a day the battery charges on cheap/solar energy (1: store surplus) and powers the site through the day (2: self-consumption). In the highest-price window it injects extra energy to the grid (3): the surplus always (mode 1), and, when the injection price beats the later consumption price by more than the minimum price difference, energy that would otherwise have been kept for later (mode 2).
When a slot qualifies
The amount available for selling is budgeted per recharge segment, roughly per PV cycle or day. A segment can offer the energy it starts with plus its expected PV surplus, minus the deficits it must still cover and any reserve. A segment never sells energy that belongs to another, which keeps multi-day plans stable.
Within that budget, a slot is only used to sell when all of these hold:
- the injection price is positive and clears the minimum price difference, so the sale covers round-trip losses and battery wear;
- the consumption price is not negative (a negative price means it is cheaper to charge);
- the slot is not already a charging slot (a battery cannot charge and discharge at once);
- the slot is not in the last four hours of the forecast (too uncertain to commit storage to);
- there is energy above the reserve (the effective minimum state of charge, including any peak shaving reserve), and the export stays within the grid connection's injection limit.
Safeguards
Selling to the grid is limited by these rules:
- Profit margin: the minimum price difference guarantees that every sale covers the round-trip losses and cycle wear. Arbitrage purchases (mode 3) only happen when the injection price beats the charge price after round-trip losses plus that margin.
- Consumption comes first: a sale never strands the site's own needs. Stored energy is only taken away from a later deficit when that deficit is either outbid by the sale or can be refilled from a cheap window in time. Otherwise the coverage stays.
- No pointless cycling: sales the battery would immediately recharge (from solar surplus right after) are suppressed unless the price clears the recharge cost. Stored energy is never sold toward moments that a cheap purchase can serve equally well, so the plan converges instead of repeatedly buying and selling across recalculations.
- Grid limit: battery injection and PV export share one injection budget, capped at the connection's injection limit. Purchases respect the grid import limit and the battery capacity.
See also
- Cost optimization: the overall price-based strategy this extends.
- Battery schedule: the forward plan, its event types and a worked example.