Skip to main content

Peak Shaving Controller

The PeakShavingController optimizes battery storage dispatch to reduce peak electricity demand, minimizing demand charges and energy costs. It uses a two-pass algorithm — discharge during peaks, recharge in the cheapest off-peak slots.

How It Works

Two-Pass Algorithm

Pass 1 — Discharge: Walk forward through each time slot. Wherever the net load exceeds the peak target, discharge the battery to bring it down. Respects SOC minimum, max discharge rate, and round-trip efficiency. Pass 2 — Charge: Total up the energy discharged in Pass 1. Schedule recharging in the cheapest available slots (sorted by tariff price) that have headroom below the peak target. This avoids creating new peaks during charging.

Battery Specification

Battery Parameters

Configuration

Auto-Target Mode

If peak_target_kw=None, the controller automatically sets the target to the 80th percentile of the forecast load, shaving the top 20% of peak demand:

Running an Optimization

Result Structure

Schedule Columns

Constraint Enforcement

The battery SOC never drops below min_soc_percent or exceeds max_soc_percent. Both charge and discharge are clipped to stay within the usable energy window, accounting for round-trip efficiency losses.
Power is capped at max_charge_kw and max_discharge_kw at every time slot. The two-pass algorithm naturally respects these limits during both discharge (Pass 1) and charge (Pass 2) phases.
The controller aims to keep net load at or below the target. If the battery is too small to fully shave the peak, the result status is “feasible” rather than “optimal”, and the peak is reduced as much as possible.
During Pass 2 (charging), the algorithm only allocates power up to the headroom between current load and the peak target. This prevents charging from creating new demand peaks.

Solar Integration

When a solar forecast is provided, the controller works with net load (load - solar), which:
  • Reduces the effective peak that needs shaving
  • Creates more low-cost charging opportunities during solar hours
  • Naturally coordinates battery and solar for maximum benefit

Demand Charge Savings

The controller calculates demand charge savings when demand_charges are present in the tariff:
For example, reducing peak from 200 kW to 150 kW with a 15/kWdemandchargesaves15/kW demand charge saves 750/month.

Next Steps

EV Charging

Combine peak shaving with EV fleet scheduling

Getting Started

Full installation and quickstart guide