S2 and OpenADR

S2 power envelopes and sequences, OpenADR 3 capacity limits both ways, and usage reports, as exact limits and schedules in Rust.

On this page

A site energy manager hears from two directions. A grid operator's VTN sends capacity limits over OpenADR 3; the devices on site speak S2, and either take a power envelope or offer power sequences to choose from. Two features bring both into this crate's shapes, where the limits combine with every other one and a plan is checked against all of them.

flexibility = { version = "0.4", features = ["s2", "openadr"] }

cargo run --features openadr,s2 --example curtail_pv runs the whole path: a VTN's export cap, the array's own range, and the S2 instruction sent to the inverter.

S2 power envelopes (s2)#

S2 counts power as this crate does: "consumption is positive and production negative, always as seen at the grid". Nothing is negated at the boundary. A PEBC instruction's power envelope is a list of steps; s2::limits makes each step a limit, the first from the instruction's execution time, each after the one before. This is the S2 specification's own PV example, a curtailable array that may feed in at most 2 kW on L1 for an hour:

use flexibility::s2::{self, wire};
use wire::types::CommodityQuantity;

let wire::Message::PebcInstruction(instruction) = wire::decode(pv_instruction_json)? else {
    return Err("not a PEBC.Instruction".into());
};
let limits = s2::limits(&instruction, CommodityQuantity::ElectricPowerL1, &cem)?;
// one limit: min -2 kW, max 0 W, 15:00 to 16:00 UTC

The other way, s2::power_envelope(&envelope, id, quantity) writes an envelope as one element per run of ISPs with equal bounds, ready for an instruction whose execution_time is the grid's start. An S2 element bounds both sides, so an ISP with an open side is refused rather than sent as something else. What both sides can carry round-trips, and a property test holds it.

s2::schedule(&sequence, read, start, &grid, rounding, provenance), where read is a CommodityQuantity or s2::Read::ElectricTotal, places a PPBC power sequence at the start you choose (S2 leaves it to the CEM) and gives a Schedule on the ISPs it covers. Every element must start and end on an ISP boundary. A container's sequences are alternatives: convert each and check each against the envelope.

Numbers#

S2 numbers are JSON numbers, held as f64. s2-kit guarantees that a decimal of at most 15 significant digits comes back equal to what the peer wrote, so the converter reads each value once, through its shortest decimal, and computes in integers from there:

  • A limit must be whole watts. -4000.5 is refused, and so are infinities and NaN: rounding a cap either way changes what was set.
  • A sequence's power may be rounded, if you name the rounding: 1500.5 is refused with Rounding::Exact and is 1501 W with Rounding::HalfAwayFromZero.

What it does not do#

  • Phases. Each function reads the commodity quantity you name. ELECTRIC.POWER.3_PHASE_SYMMETRIC is the total over three phases (S2's structured documentation; the JSON schema leaves it out). For a power sequence, Read::ElectricTotal is the symmetric value alone, or L1, L2 and L3 summed as the exact decimals written (1000.1 + 2000.2 + 3000.3 is 6000.6, rounded once as you name). A set that mixes both, or repeats a phase, is refused.
  • FRBC fill levels. An FRBC store fills at fill_rate per operation mode, with leakage, in a unit S2 does not name. An EnergyEnvelope's level is the lossless integral of grid power. Mapping one onto the other would claim an exactness it does not have, so FRBC is not converted.
  • PEBC power constraints bound which envelope a CEM may choose, not the device's power. The instruction is the limit.

Reading OpenADR capacity limits (openadr)#

openadr::limits(&event, program, window, received, &provenance) reads an event's IMPORT_CAPACITY_LIMIT intervals as consumption caps and its EXPORT_CAPACITY_LIMIT intervals as feed-in caps, each over its own interval. The openadr crate's IntervalExpander places them in time: inherited periods, payloads with several values split into sub-intervals, an event's duration looping and truncating. received is what StartTime::Now means.

use flexibility::openadr;

let caps = openadr::limits(&event.content, None, day, received, &vtn)?;
let envelope = caps.iter().try_fold(Envelope::unbounded(grid), |e, l| e.apply(l))?;

The limits keep their exact windows. Applied to an envelope, an hour-long cap constrains all four of its quarters, and a cap that covers part of an ISP constrains the whole ISP: the strict reading, so nothing allowed by the envelope breaks the VTN's cap.

  • The unit is required. The payload definitions say "meaning is indicated by units in associated eventPayloadDescriptor", so there is no default, and this crate does not guess. The unit comes from the event's descriptor or, where it has none for that type, from its programme's (pass Some(&program); User Guide §7.6). A limit without KW is refused.
  • Exact magnitudes. 7.56 kW is 7 560 W; 7.5605 kW is refused, and so is a negative or non-numeric value.
  • Time is held strictly. An interval with randomizeStart holds its cap until its end plus the randomization, the latest any VEN may still apply it. An open-ended interval (P9999Y) lasts until the window you asked for ends.
  • Only limits. Prices, subscriptions, reservations and available capacity are left alone.
  • Bounded work. An event that repeats every second forever exceeds the expander's limit of 10 000 intervals and is refused.

Publishing caps from a VTN#

openadr::event(program, &caps) is the inverse: the event a VTN publishes, which limits reads back as the same caps, through JSON too.

let event = openadr::event(ObjectId::new("site-caps")?, &[cap])?;
let json = serde_json::to_string(&event)?; // "values":[250.001], "duration":"PT1H"
  • Exact kW. 250 001 W is 250.001; a whole number of kW is a JSON integer. A fraction of a kW at 10¹⁵ W or more is refused: that is more digits than a JSON number is sure to carry.
  • Caps only. A consumption cap is an IMPORT_CAPACITY_LIMIT, a feed-in cap an EXPORT_CAPACITY_LIMIT of its magnitude, each with a KW descriptor. A band, a floor or a negative cap is refused rather than sent in part.
  • Time as a VTN writes it. Caps that follow one another, all of one length, share the event's period (PT15M, PT1H); others carry their own. Targets, the event name and report descriptors are yours to set on the result.

OpenADR usage reports#

openadr::usage(&report, "meter-1", Some(&event), &grid, rounding) turns a resource's USAGE readings (energy per interval, KWH) into average power per ISP, ready for settle or accuracy. Pass the event when the readings carry only its interval ids.

Every reading must be exactly one ISP of the grid, and every ISP must have exactly one reading. A missing quarter is refused, never filled; so is a reading read twice. On an hourly grid, 0.0005 kWh is 0.5 W: refused with Rounding::Exact, 1 W rounded half away from zero.

Applied to one envelope, these limits combine with every other: see Limits and envelopes.