flexibility
Grid flexibility as exact, replayable arithmetic, in Rust. 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, with a digest both sides recompute.
- Limits and envelopes. Caps, floors and bands per quarter hour, combined strictly; every bound names who set it, and a § 14a minimum refuses any cap below it.
- Baselines. Named, versioned methods (
mbma@1,xofy@1, …) with required parameters, whose meaning never changes. - Settlement. Delivered flexibility and power deficiency exactly as UFTP 3.1 § 2.6 computes
them, with a canonical receipt and a
sha256:digest anyone can reproduce. - Protocols. UFTP, EEBUS, S2, OpenADR 3, CSIP-AUS, IEC 104 and CLS.EEDI in and out, each behind a feature, lossless or refusing.
Documentation · Getting started · API reference · Changelog
Status: 0.1, early. The API may change before 1.0; what a method id or a canonical text computes does not.
Install
# with converters, for example:
Rust 1.88 or later, for every feature. The default build depends on jiff
(time, with the zone database bundled) and sha2.
A cap, a plan, and who set the limit
use ;
use *;
let berlin = get?;
let grid = day?;
let noon = grid.local?;
// The grid operator caps consumption at 4.2 kW from 17:00 to 19:00, local time.
let evening = grid.window?;
let dso = new;
let envelope = unbounded.apply?;
// A car planned at 7.4 kW all evening breaks it in ISPs 69 to 76, and says who set the cap.
let plan = new;
let violations = plan.check?;
assert_eq!;
assert_eq!;
# Ok::
Settle an order, and prove it
use ;
use ;
use *;
let berlin = get?;
let grid = day?;
let evening = grid.window?;
let measured = new?;
// The DSO ordered 3 kW less; the contract names mbma@1 with n = 4, gap = 1. No defaults.
let base = mbma?;
let actual = measured.over?;
let ordered = filled;
let settlement = settle?;
assert_eq!;
// One hash the aggregator compares; `scripts/digest.sh` reproduces it from the canonical text.
println!;
# Ok::
Read what the other side sent, and find where you disagree
# use ;
# use ;
# use *;
# let berlin = get?;
# let grid = day?;
# let evening = grid.window?;
# let settle_with = ;
# let text = settle_with?.canonical;
# let ours = settle_with?;
// The DSO sent `text`, its settlement's canonical JSON. Edited or re-encoded bytes are refused.
let theirs = from_canonical?;
assert_eq!;
assert_eq!;
# Ok::
Protocols
| Feature | Protocol | What it maps |
|---|---|---|
uftp |
UFTP 3.1 (Shapeshifter) | FlexRequest → deviation envelope; offers and orders; the FlexOrderSettlement item; checking a received settlement |
eebus |
EEBUS LPC, LPP | active and failsafe power limits, both ways |
s2 |
S2 (EN 50491-12-2) | PEBC power envelopes both ways; PPBC power sequences as schedules |
openadr |
OpenADR 3 | import and export capacity limits; usage reports as power |
csip |
CSIP-AUS (IEEE 2030.5) | dynamic operating envelopes at the connection point |
iec104 |
IEC 60870-5-104 | active-power set points (types 48–50), both ways |
cls |
CLS.EEDI | control-box limits and failsafes, both ways |
metering |
German metering rules | the § 14a minimum as a guarantee; Lastgang energy as power |
Why you can trust the numbers
- Exact. Integers throughout; no floating-point arithmetic. A float on the wire is read once, as the decimal written. A remainder is refused unless you name a rounding.
- Pure. No clock, file, network, environment or randomness: the same inputs give the same bytes on every machine, so a settlement replays years later.
- One sign. Consumption is positive, feed-in negative, everywhere; converters change sign at the boundary and nowhere else.
- Refusal over invention. A missing quarter hour, an unknown unit or an ambiguous control is
an error that names the values and offers a
hint(), never a guess. - Checked. Unit and property tests, a snapshot per method id, the UFTP specification's own settlement table and each protocol's published examples, with every feature on the MSRV in CI.
Examples
Each asserts its own results.
| Command | Shows |
|---|---|
cargo run --example evening_cap |
a DSO cap, a connection limit and a § 14a guarantee; explain and headroom |
cargo run --example settle_an_order |
an mbma@1 baseline, a settlement, one digest, the rebound |
cargo run --example verify_a_receipt |
read the other side's settlement and diff it |
cargo run --example charge_by_seven |
an EV's departure energy, a pool and a split |
cargo run --features uftp --example check_a_settlement |
a FlexOrder to a settlement item uftp accepts |
cargo run --features eebus,metering --example control_box |
a § 14a control box: minimum, LPC limit, failsafe, Lastgang |
cargo run --features openadr,s2 --example curtail_pv |
a VTN's export cap sent to a PV inverter over S2 |
Licence
Licensed under either of Apache License, Version 2.0 or MIT licence at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work, as defined in the Apache-2.0 licence, shall be dual licensed as above, without any additional terms or conditions.