Open-source Rust library · MIT OR Apache-2.0

Grid flexibility as exact, replayable arithmetic.

The limits a grid operator sets, the plan an aggregator makes, the baseline both agree on, and the settlement of what was delivered — in whole watts, one sign convention, and a receipt both sides hash to the same digest.

Get started Read the docs GitHub

cargo add flexibility
  • Integer watts no floating-point arithmetic
  • Pure no clock, I/O or randomness
  • UFTP-exact reproduces § 2.6 to the watt
  • 8 protocols behind features

Four questions, one set of numbers

Does this plan fit?

Caps from the grid operator, the connection limit and a § 14a minimum combine into one envelope. A schedule is checked per quarter hour, and every violation names who set the bound.

Limits and envelopes →

What would the site have done?

Baseline methods with stable ids — dprognosis@1, schedule@1, mbma@1, xofy@1 — each with required parameters and a published card.

Baselines →

How much was delivered?

Delivered flexibility and power deficiency per quarter hour, exactly as UFTP 3.1 § 2.6 computes them; the specification's own table is a test.

Settlement →

Do we agree?

Every settlement has a canonical JSON text and a sha256: digest. The other side recomputes it — in Rust, a shell script or any RFC 8785 library — and compares one hash.

Verifying a settlement →

Read like the domain, run like a test

A grid of quarter hours in its own time zone, a cap in kilowatts, a plan, and a check whose every message names the quarter hour, the values and who set the bound. This is the README's example; it runs in the crate's test suite.

Walk through it →

use flexibility::jiff::{civil::{date, time}, tz::TimeZone};
use flexibility::*;

let berlin = TimeZone::get("Europe/Berlin")?;
let grid = Grid::day(date(2026, 12, 1), &berlin, IspDuration::FIFTEEN_MINUTES)?;
let noon = grid.local(time(12, 0, 0, 0))?;

// The grid operator caps consumption at 4.2 kW from 17:00 to 19:00, local time.
let evening = grid.window(time(17, 0, 0, 0), time(19, 0, 0, 0))?;
let dso = Provenance::new("dso.example", "order-42", noon);
let envelope = Envelope::unbounded(grid.clone()).apply(&Limit::consumption_cap(evening, kw!(4.2), dso))?;

// A car planned at 7.4 kW all evening breaks it in ISPs 69 to 76, and says who set the cap.
let plan = Schedule::new(Series::filled(grid, kw!(7.4)), Provenance::new("agr.example", "plan-7", noon));
let violations = plan.check(&envelope)?;
assert_eq!(
    violations[0].to_string(),
    "ISP 69 (17:00–17:15 +01:00): planned 7.4 kW above max 4.2 kW set by dso.example order-42"
);

Who it is for

Grid operators (DSO)

Cap a feeder's sites per quarter hour, keep the § 14a minimum, and settle the flexibility you bought, with a receipt the aggregator can check.

Start here →

Aggregators and flexibility providers

Plan a pool inside every limit, prove what you delivered against the agreed baseline, and catch a wrong settlement before you sign it.

Start here →

Energy managers (HEMS, CEM)

Turn LPC, S2, OpenADR or CSIP-AUS limits into one envelope, check a heat pump's or a car's plan against it, and send each device what it must keep.

Start here →

Auditors and regulators

Recompute any settlement from its canonical text, with a shell script or any RFC 8785 library, and find the first quarter hour two parties disagree on.

Start here →

Speaks the grid's protocols

Each converter is a Cargo feature, off by default. It changes the sign at the boundary and nowhere else, and refuses what it cannot carry exactly.

How the converters work →

Why you can trust the numbers

Questions

What is grid flexibility?

Changing when or how much power a site draws or feeds in, because the grid needs it: less consumption on a congested evening, more feed-in when demand peaks. A grid operator (DSO) buys it from an aggregator, who moves heat pumps, cars, batteries and plants, and both have to agree afterwards on how much was delivered.

What is a baseline, and why does it need a method id?

The power a site would have drawn without the activation. Delivered flexibility is measured against it, so the method decides the money. flexibility names each method with a version (mbma@1, xofy@1) whose computation never changes, so a settlement can be recomputed years later and give the same watts.

How do two parties prove they settled the same thing?

Every baseline and settlement has a canonical JSON text (RFC 8785) and a sha256: digest. Both sides compute it from their own inputs and compare one hash; if they differ, Settlement::diff names the first quarter hour, field or input where they part.

Why no floating point?

Because 0.1 kW is not representable in binary, and a settlement that depends on the rounding of a float is not reproducible. Power is whole watts in an i64, energy whole watt-seconds; a remainder is refused unless you name a rounding. Floats on the wire (S2, IEC 104) are read once, as the decimal written.

Does it talk to devices or the network?

No. It is pure arithmetic: no clock, file, network or environment. Protocol crates parse and send messages; flexibility turns their values into limits, schedules and settlements and back, so an integration gets the same numbers in a test, a replay and production.

Which markets and rules does it follow?

Settlement follows UFTP 3.1 § 2.6 exactly, and the crate reproduces the specification's own table. Signs follow UFTP § 4.2.1 (consumption positive). It models the German § 14a EnWG minimum, records the measurement point the EU network code on demand response asks for, and maps the protocols listed above.

The terms, in one page →

Settle your first order in five minutes

cargo add flexibility, follow the getting-started guide, and compare your digest with the one in the docs.

Get started API reference