# 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.

Source: https://voltmasters.io/en/docs/control-algorithms/cost-optimization/selling-energy-to-the-grid/

Under [cost optimization](https://voltmasters.io/en/docs/control-algorithms/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 EMS discharges stored energy **into the grid** to earn revenue, on top of self-supply.

![The day-ahead price curve over 24 hours, marking the cheap hours where the battery charges from the grid and the peak hours where it sells at the injection price.](https://voltmasters.io/assets/docs/image-90.webp)

> **Warning**
>
> This is **optional and off by default**. The battery only ever discharges purely to sell when you explicitly enable it (see below). With it disabled, the battery still discharges, but only to cover your own consumption.

## Enabling it

Selling energy to the grid is a per-project setting. Enable the **Selling via battery injection** toggle under [Project settings](https://voltmasters.io/en/docs/voltmasters-platform/project-settings/general-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 cost-optimization planner 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 planner 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**](https://voltmasters.io/en/docs/external-signal/) **partner is steering** the installation.

## Three ways to sell

Energy is always sold at the **most profitable moments**: the planner 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*.

### 1\. Selling surplus energy

Part of what the battery stores is **not needed** for the site's upcoming consumption; that is **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**. This is the baseline behaviour whenever injection sales are enabled.

### 2\. Selling beyond the surplus: price arbitrage on stored energy

Energy that the plan would otherwise **keep** to cover a later deficit (so it can avoid buying at the future consumption price) can be sold **too**, in two situations:

-   **The sale simply outbids the deficit**: the injection price now is more than the minimum price difference above that later consumption price. The kilowatt-hour earns more sold now than it would save later, so the planner exports it and meets the later need from the grid instead.
-   **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. The planner then sells the stored energy at the peak and covers the deficit by recharging in that window, earning the sale on top of the (cheaply refilled) deficit coverage. This is what 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: grid charging for injection

With the **Grid charging for injection** setting enabled (a separate toggle, alongside battery injection sales), the planner also **buys grid energy at cheap moments purely to sell it back** at the most profitable injection slots. For every attractive injection slot whose discharge capacity is not yet filled by stored or solar energy, it looks for earlier slots whose price clears the round-trip break-even:

> injection price ≥ charge price ÷ round-trip efficiency + minimum price difference

Each purchase is sized to exactly deliver the extra sale, so existing deficit coverage and the rest of the plan are unaffected. Purchases respect the battery capacity along the way (including solar that will flow in anyway) and the grid import limit, and nothing is bought when the sale can already be served by energy that is (or will be) 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** (nothing cheaper can reach them), while 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

![Selling energy to the grid: market price, battery state of charge and energy destinations over a day](https://voltmasters.io/assets/docs/selling-energy-to-the-grid.webp)

*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/day): each 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](https://voltmasters.io/en/docs/control-algorithms/peak-shaving-reserve/)), and the export stays **within the grid connection's injection limit**.

## Safeguards

Selling to the grid never runs away with your battery or your money:

-   **Profit margin**: the minimum price difference guarantees every sale clears the round-trip loss and cycle wear. Arbitrage purchases (mode 3) additionally only happen when the injection price beats the charge price **after round-trip losses** plus that margin.
-   **Reserve & minimum SoC**: discharging stops at the effective minimum; reserves (such as a [peak shaving reserve](https://voltmasters.io/en/docs/control-algorithms/peak-shaving-reserve/)) are off-limits.
-   **Consumption comes first**: a sale never strands the site's own needs. Stored energy is only sold 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, and stored energy is never sold toward moments a cheap purchase can serve equally well, so the plan converges instead of repeatedly buying and selling across regenerations.
-   **Forecast tail exclusion**: no injection is planned in the final four hours of the horizon.
-   **Grid export limit**: battery injection and PV export share one export budget, capped at the connection's injection limit. Purchases respect the grid import limit and the battery capacity.
-   **Self-supply first**: energy is only sold when selling beats self-use; covering your own consumption otherwise takes priority.

## See also

-   [Cost optimization](https://voltmasters.io/en/docs/control-algorithms/cost-optimization/): the overall price-based strategy this extends.
-   [Battery schedule](https://voltmasters.io/en/docs/control-algorithms/cost-optimization/battery-schedule/): the forward plan, its event types and a worked example.
