Ingest the facility's 15-minute or hourly interval load profile for the billing period and identify the utility tariff's demand charge structure (peak kW window, coincident vs. non-coincident, ratchet clauses).
Formulate a linear programming (LP) optimization: decision variables are battery charge power P_charge(t) and discharge power P_discharge(t) per interval; the objective minimizes the maximum net load (peak demand) subject to battery energy balance, state-of-charge bounds (SoC_min to SoC_max), and power limits (P_max charge/discharge).
Add the battery round-trip efficiency term to the energy balance constraint: SoC(t+1) = SoC(t) + P_charge(t)*eta_charge*dt - P_discharge(t)/eta_discharge*dt, where eta values are typically 0.95–0.97 for modern Li-ion systems.
Solve the LP using an open-source solver (e.g., CVXPY with GLPK or SCS backend, or PuLP) for day-ahead planning; for real-time operation, implement a rolling-horizon model predictive control (MPC) that re-solves every 15 minutes with an updated load forecast.
Post-process the dispatch schedule: apply a demand charge threshold target (set slightly below the current monthly peak to add margin), and verify that the schedule does not violate any time-based restrictions in the tariff (e.g., no discharge during on-peak generation hours).
Log actual SoC telemetry versus planned SoC at each interval to detect forecast error accumulation and trigger re-planning when deviation exceeds a defined tolerance.
Known gotchas
Demand charges are often assessed on 15-minute interval peaks; if the load profile granularity is hourly, demand charge savings will be overestimated — always use the finest available interval resolution matching the tariff's demand measurement window.
Ratchet clauses (e.g., 'billed demand is the greater of current month peak or 80% of the prior 11-month maximum') fundamentally change the optimization objective; ignoring ratchets can produce a dispatch plan that appears optimal for the current month but does not reduce the billed demand.
Battery degradation caused by aggressive cycling is an economic cost not captured by a pure demand-charge LP; add a cycle-count penalty term or SoC swing constraint to the objective function for long-term economic accuracy.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp