S2 flexibility and external managers
Connect a manager, inspect an asset’s flexibility and follow an instruction through execution.
S2 is an energy flexibility protocol. A Resource Manager describes an asset and its capabilities. A Customer Energy Manager chooses a supported control type and sends instructions for that resource. A household might let an aggregator schedule battery use while retaining control over grid limits and local overrides.
The five control types
| Control type | What the manager can describe | Household example |
|---|---|---|
| FRBC · Fill Rate Based Control | A store’s fill level and the rates at which it can change | Battery or hot-water store |
| PEBC · Power Envelope Based Control | A permitted power range over time | Inverter curtailment or EV charging |
| OMBC · Operation Mode Based Control | A choice between discrete operating modes | SG Ready heat pump |
| PPBC · Power Profile Based Control | When a programme with a known power profile should start | Dishwasher |
| DDBC · Demand Driven Based Control | Actuators meeting a changing demand | Heat pump serving a reported demand |
What a site can describe depends on its measurements and installed assets. A charger with a known connected car and energy deadline has information that an empty charging port cannot supply. Read the offered control types and execution status for the particular resource.
Connect a manager
Enable the S2 surface with [s2] enabled = true in the gateway configuration. Create a named manager credential with the household credential. Use the gateway certificate verified during commissioning.
curl --cacert hems.pem -X PUT -H "Authorization: Bearer $HEMS_TOKEN" https://hems.local:8080/v1/managers/aggregator
Store the returned token in the manager. Use it to connect to wss://hems.local:8080/s2/{asset}, replacing {asset} with the configured asset ID. Each connection negotiates one resource. The household can list managers, rotate a named token or withdraw access. Credential and route reference.
Follow an instruction
The gateway offers S2 JSON v1.0.0 and 0.0.2-beta, and the manager chooses. The manager then selects the control type, receives the resource description and submits instructions. Every message is answered with a ReceptionStatus. A selection or instruction naming a control type, actuator or operation mode this resource did not offer is refused with INVALID_CONTENT and the rule it broke, for example S2-RMD-001; the manager may select again. A message before the handshake ends the session. A future execution time queues the request, up to 192 waiting instructions, and the gateway reports STARTED when it is due. A power envelope is read exactly: an element that is not whole watts, or whose lower limit is above its upper, is refused with INVALID_CONTENT. It is followed step by step, each element for its own duration, and bounds nothing after its last step. An instruction is believed for 15 minutes at most (instruction_for_secs), so a manager that stops talking stops deciding. ACCEPTED says the gateway will carry it out. Follow the later instruction status and device measurements to establish what happened.
The guard enforces site limits on each tick. A household override also has priority over the manager. A superseded or undeliverable instruction can report ABORTED; resuming requires a new instruction. For example, the virtual battery can report its current fill level while aborting a power request because its pack controls itself. A manager should record that outcome even if the original instruction was accepted.
The wire model comes from s2-kit. The interoperability check exercises a pinned, authenticated WebSocket session with the upstream S2 Analyzer, including a live battery fill reading and the outcome for an undriven asset. S2 Analyzer · Control authority.