Scenarios¶
A scenario is a YAML file that drives the simulated chargers through timed steps and checks how the CSMS reacts: plug in, authorize, wait two hours, unplug, and assert that the CSMS accepted the transaction. It runs headless for CI (verdict JSON, optional JUnit XML, exit code) or in the running app (HTTP API, MCP).
- A scenario is a separate file (
format: ocppsim-scenario/1). It names chargers of the running config by id; it does not contain chargers or CSMS settings itself. One scenario runs at a time. - Times follow the simulation clock:
after,waitandatspeed up withtime_scaleand stop while the simulation is paused. Withclock: {time_scale: 3600}a two-hour session takes two wall seconds. The OCPP timestamps on the wire stay wall-clock time (the CSMS sees a shortened session, the energy follows sim time). - Assertions wait in wall seconds (
within, default 30 s): how fast a CSMS answers does not depend on the speed-up.within_simwaits in sim time instead.
Examples ship in the scenarios/ folder of the repository; they run against configs/mini-csms-demo.yaml:
sme-ocpp-sim scenario run scenarios/plug-charge-unplug.yaml -c configs/mini-csms-demo.yaml --out verdict.json
File format¶
format: ocppsim-scenario/1
name: plug-charge-unplug
seed: 7 # recorded in the verdict
clock: {start_at: "2026-12-01T07:55:00+09:00", time_scale: 3600} # both optional
params: {tag: "TAG001"} # ${tag} in any string below
tracks:
- name: session
charger: DEMO-16
steps:
- expect: {state: {online: true}}
within: 30s
- {at: "08:00", do: plug, connector: 1}
- {after: 1m, do: swipe, connector: 1, id_tag: "${tag}"}
- expect:
frame: {dir: tx, action: StartTransaction}
then: {message_type: CALLRESULT, payload: {idTagInfo.status: Accepted}}
within: 10s
- {do: wait, duration: 2h}
- {do: unplug, connector: 1}
- expect: {frame: {dir: tx, action: StopTransaction}}
until: "+4h" # optional hard end (sim time)
| Key | Meaning |
|---|---|
tracks |
Run in parallel; the steps of a track run in order on its charger |
for_each: {chargers: [A, B]} |
Instead of charger: one track per charger ("*" = every charger); ${charger} / ${i} are its id / 0-based index |
repeat: n |
Run the track's steps n times (${round} = 0-based round; step ids get #1, #2 ...) |
clock.start_at |
Restart the sim clock at this date-time for the run (it anchors at: "HH:MM") |
clock.time_scale |
Sim speed for this run (restored afterwards); --time-scale of the CLI overrides it |
until |
End of the run: a step still running then fails, steps not started are skipped (the event log says how many) |
Every key is checked (a typo is an error with its position, e.g. tracks.0.steps.2.do); charger ids and
${...} names are checked against the running config before anything runs. A whole-string "${n}" keeps the
parameter's type (number, bool). Quote clock times ("08:00"): YAML reads an unquoted one as a number, which is rejected.
Timing¶
after: <duration>: wait this long (sim) after the previous step, then run.at: "HH:MM[:SS]": the next such sim clock time at or after the scenario start;at: "+90m": sim time after the start; an ISO date-time is also accepted.- A duration is a number of seconds or text:
500ms,30s,5m,2h,1h30m,1d.
Actions (do:)¶
| Action | Parameters | Effect (the same as the web UI button / HTTP route) |
|---|---|---|
plug / unplug |
connector (default 1) |
EV cable in / out (unplug ends a transaction) |
swipe |
connector, id_tag |
Present an id tag (start or stop) |
master_pass |
connector, id_tag |
OCPP 2.0.1 / 2.1 C16 with a UI: present the master pass token id_tag and stop only connector's transaction (StopAuthorized / MasterPass); the token's group must be AuthCtrlr.MasterPassGroupId |
start |
connector, id_tag (default: the charger's first) |
plug + swipe |
stop |
connector |
Stop the transaction locally |
fault / clear_fault |
connector, error_code |
Connector fault on / off |
connect / disconnect |
security_profile (connect only: 0 - 3 or previous) |
Connection loop on / held off; security_profile connects with an earlier security profile of the charger for this connection run only (previous = the one before the last SecurityProfile upgrade) |
drop |
mode (abort / close), reconnect_after_s |
Drop the connection now |
impair |
impairments (the whole block) |
Replace the charger's impairments live |
send |
action + payload or raw, validate, timeout |
Inject a CALL / raw frame |
set_ev |
connector, ev_model, initial_soc, target_soc |
The EV of the connector's next transaction (once) |
set_variable |
component, variable, value, instance |
The charger's own setting, as a tester configures a test station (no message is sent): a 2.0.1 / 2.1 Device Model variable, also ReadOnly ones such as TxCtrlr.TxStartPoint; or a 1.6 configuration key (variable = the key, e.g. ConnectionTimeOut; component is ignored) |
set_monitor |
component, evse, variable, instance, type, value, severity, transaction |
OCPP 2.0.1 / 2.1: install a variable monitor at the station, as a tester pre-configures a test station (no message is sent), for cases where the CSMS does not send SetVariableMonitoring itself. type is UpperThreshold, LowerThreshold, Delta, Periodic or PeriodicClockAligned; severity defaults to 0; evse selects an EVSE component, instance the variable instance. The SetVariableMonitoring checks apply (MonitoringCtrlr.Enabled aside); the monitor is a CustomMonitor and the step's result is its id |
cache_token |
id_tag, status |
OCPP 2.0.1 / 2.1: put id_tag into the station's Authorization Cache with status (default Accepted), as a tester pre-configures a test station (no message is sent; the cache is looked up only while AuthCacheCtrlr.Enabled is true) |
power_loss |
reconnect_after_s |
OCPP 1.6: cut the charger's power: the connection drops and the charger reboots after reconnect_after_s (default impairments.down_s); running transactions end with reason PowerLoss, their StopTransaction goes out after the new BootNotification and StatusNotifications (Finishing while plugged) |
external_limit |
connector (0 = the station), limit_w |
OCPP 2.0.1 / 2.1: set (limit_w in W) or release (no limit_w) an external (EMS) charging limit, as the station's external control system would; the station sends NotifyChargingLimit / ClearedChargingLimit. Needs SmartChargingCtrlr.ExternalControlSignalsEnabled true (e.g. via set_variable) |
set_frequency |
hz (required, 40 - 70, or null for the config value), charger |
OCPP 2.1: set the simulated grid frequency. charger (a charger id) limits it to that charger, which must be OCPP 2.1; omitted, it applies to every OCPP 2.1 charger of the run (the frequency is a grid property, so it does not default to the track's charger). No message is sent; LocalFrequency transactions adjust their power. The step fails when no OCPP 2.1 charger is affected. Example: - do: set_frequency with hz: 49.8 |
set_voltage |
v (required, > 0 and <= 1000 V, or null for the config value), charger |
OCPP 2.1: set the simulated grid voltage (in the terms of voltage_v). charger as for set_frequency (omitted = every OCPP 2.1 charger of the run). No message is sent; the DER VoltWatt / VoltVar controls act on it and the meter Voltage follows it. The step fails when no OCPP 2.1 charger is affected. Example: - do: set_voltage with v: 241.5 |
wait |
duration |
Wait (sim time) |
log |
message |
Write to the event log |
A rejected action (unknown connector, no transaction to stop ...) is a step error.
Assertions¶
- expect: {frame: {dir: tx, action: MeterValues, payload: {meterValue.0.sampledValue.0.value: {gt: 0}}}}
- expect: {state: {connector: 1, status: Charging, power_w: {ge: 3000}, has_transaction: true}}
within_sim: 10m
- expect_not: {dir: tx, action: StartTransaction} # passes when no such frame shows up in the window
within: 20s
- await_csms: {action: RemoteStartTransaction, prompt: "Start charging on CP001 from the CSMS"}
within: 5m
expect.frame:dir(tx= sent by the charger,rx= received),action,message_type(CALL/CALLRESULT/CALLERROR),payloadmatchers.then:checks the answer to the matched CALL (same message id):message_typeandpayload(a CALLERROR's payload iserrorCode/errorDescription/errorDetails).expect.state:connector,status,has_transaction,power_w,soc_pct,meter_wh,online,connected,connect_failure(the kind of the last failed connection attempt of the charger's current run:unauthorized= HTTP 401,forbidden/bad_request/not_found/http_error,subprotocol,client_cert_rejected/client_cert_required,network,timeout,tls_verify, ...; absent after a successful handshake, soexists: false). It tells a CSMS that refused the handshake from one that could not be reached.expect_not: a frame filter; the step fails as soon as a match appears in the window.await_csms: waits for a CALL from the CSMS (an operator action on the CSMS side);promptis shown in the status and the event log while it waits.- Each track has a frame cursor: it starts at the scenario start; a passing
expect.frame/await_csmsmoves it to the matched frame (withthen: the answer); an action step moves it to the newest frame when the action started (so an answer that came before the assertion started is still found).expect_notandexpect.stateleave it. A frame assertion searches after the cursor by default, so twoexpects of the same action need two frames.from: actionsearches from the start of the previous action instead,from: scenario_startfrom the scenario start. await_csmswaits 30 wall seconds like any assertion unless it setswithin: give an operator more time.on_fail: stop(default) ends the whole scenario at a failed or rejected step;continuegoes on.
Run-time references (v0.4). ${param} is replaced when the scenario is loaded; two references are
replaced only when their step runs, in the payload of do: send and in the payload matchers of expect /
expect_not / await_csms:
- expect: {frame: {dir: tx, action: GetInstalledCertificateIds, message_type: CALLRESULT}}
save: {serial: payload.certificateHashDataChain.0.certificateHashData.serialNumber}
- await_csms: {action: DeleteCertificate, payload: {certificateHashData.serialNumber: "${saved.serial}"}}
- do: send
action: SecurityEventNotification
payload: {type: InvalidFirmwareSigningCertificate, timestamp: "${now}"}
save: {NAME: path}on a frame assertion (expect.frame/await_csms) keeps a value of the matched frame:payload.<path>is the frame,reply.<path>the answerthen:matched. A path that is not there fails the step.${saved.NAME}uses it in a later step of the same track (an unknown name is a load error); a string that is exactly the reference keeps the value's type.${now}is the charger's wire clock (the clock of its own timestamps, also after a CSMS set it) as ISO-8601 UTC (2026-11-30T12:00:00Z);${now+30s}/${now-1h30m}add or subtract a duration.
Matchers (Q6: built in, no JSONPath, no code): a path is dotted, integer parts index lists
(meterValue.0.sampledValue.0.value). The value is a literal (equality) or operators that must all hold:
in: [...], gt / ge / lt / le: n (numeric strings compare as numbers), re: "regex" (search),
exists: true|false.
Verdict¶
{"format": "ocppsim-verdict/1", "scenario": "plug-charge-unplug", "result": "pass", "error": null, "seed": 7,
"started": "2026-11-28T17:12:16+09:00", "wall_s": 2.1, "sim_s": 7423.0, "tool_version": "0.5.1",
"trace": null, "steps": [{"id": "4", "track": "session", "kind": "expect", "status": "pass",
"t_wall": 0.02, "t_sim": 60.0, "message": "StartTransaction: seq 7, answer seq 8", "evidence": [7, 8]}]}
result: pass, fail (an assertion failed), error (an action was rejected, or the scenario could not
start), aborted (stopped from outside). Step status: pass / fail / no_operator / error / skipped / aborted; result incomplete: see below.
evidence are frame sequence numbers (the frame log / --trace file).
Command line¶
sme-ocpp-sim scenario run FILE [-c CONFIG] [--param NAME=VALUE] [--out verdict.json] [--junit junit.xml]
[--trace trace.jsonl] [--time-scale N] [-v] [--log-format json]
[--operator-exec CMD] [--operator-url URL] [--operator-timeout S]
sme-ocpp-sim scenario run --suite cert/1.6 [--profile core] [--param cp=ID] [-c CONFIG] [--out ...] [--junit ...]
[--operator-exec CMD] [--operator-url URL] [--operator-timeout S]
sme-ocpp-sim scenario validate FILE [-c CONFIG] [--param NAME=VALUE]
sme-ocpp-sim scenario validate --suite cert/1.6 [--profile core] [--param cp=ID] [-c CONFIG]
sme-ocpp-sim scenario diagram FILE | --suite cert/1.6 [--format mermaid|json|html] [--out PATH]
--operator-* set the operator hook; diagram draws a scenario or a
suite as sequence diagrams, see Sequence diagrams.
run starts the engine (and the Mini CSMS if the config enables it) without the web UI, runs the scenario,
writes the verdict (stdout without --out) and exits 0 pass, 1 fail, 2 error / aborted / invalid
scenario or config. --junit writes one test case per assertion (and per failed action); --trace writes the
frames of the scenario's chargers as JSON lines (an ocppsim-trace/1 file, see Trace recording and analysis).
No operator, exit code 3, operator hook¶
An await_csms step whose window ends without any CSMS CALL of its action (the payload is not looked at)
is no_operator, not fail; a CALL of that action with a payload that does not match stays fail. A scenario
with a no_operator step and no failed / error step has the result incomplete (precedence: aborted > error >
fail > incomplete > pass) and scenario run exits 3. JUnit reports such a step as skipped (no operator: ...).
no_operator follows on_fail like a failure. An operator hook (config operator_hook:, flags --operator-exec
/ --operator-url / --operator-timeout) is called when an await_csms step starts and can trigger the command
in the CSMS, or answer {"skip": "reason"}: see Certification pre-check.
Built-in scenarios¶
The examples of the repository's scenarios/ folder ship with every build (wheel, Windows exe, Docker image)
and are referenced as builtin:<name>:
sme-ocpp-sim scenario run builtin:plug-charge-unplug -c configs/mini-csms-demo.yaml --out verdict.json
| Name | What it does |
|---|---|
plug-charge-unplug |
One OCPP 1.6 session on DEMO-16 of configs/mini-csms-demo.yaml (2 h sim in about 2 s) |
remote-start-no-tx |
DEMO-16 with remote_start: accept_no_tx: send a RemoteStartTransaction from the CSMS while it waits; it is accepted but no transaction starts |
both-versions |
The same session on every charger of the config (for_each), OCPP 1.6 and 2.0.1 in parallel |
Over HTTP: GET /api/scenarios/builtin lists them, POST /api/scenarios/builtin/{name}/run (or the body
builtin:<name> for POST /api/scenarios/run) starts one; MCP: list_builtin_scenarios, then run_scenario
with body: "builtin:<name>". The chargers they name must exist in the running config.

HTTP API and MCP¶
| Method | Path | MCP tool | Meaning |
|---|---|---|---|
| POST | /api/scenarios/run |
run_scenario |
Body: the scenario YAML (or JSON) text; starts it (409 while one runs) |
| GET | /api/scenarios/current |
get_scenario_status |
state (idle / running / done), track progress, step counts, prompts |
| POST | /api/scenarios/abort |
abort_scenario |
Stop it (result aborted) |
| GET | /api/scenarios/builtin |
list_builtin_scenarios |
The built-in scenarios (name, title, description); run one with the body builtin:<name> or POST /api/scenarios/builtin/{name}/run |
| GET | /api/scenarios/result?format=json\|junit |
get_scenario_result |
Verdict of the finished scenario |
| POST | /api/frames/expect |
expect_frame |
One-shot: wait up to within s for a matching frame after since |
In the web UI, Simulation → Scenario… opens the scenario panel: choose a built-in scenario or open a file
(the YAML lands in the editor, where it can be changed), Run / Abort, a live table of the steps (pending,
running, pass, fail, error, skipped, aborted) with their sim time and message, the operator prompts of
await_csms steps, and Verdict JSON / JUnit XML downloads once the run is done. The scenario's log
lines and its start / result also go to the event log.
Limits¶
- Generator tracks (
generate:instead ofsteps, needsuntil): see Traffic generator;seedseeds them. sendinjects charger → CSMS CALLs; CSMS-side steps areawait_csms(or the Mini CSMS API).--tracewrites anocppsim-trace/1file while the run goes (see Trace recording and analysis).repeat(at most 1000 rounds):at: "+dur"counts from the start of the round; clock / date-timeatis not allowed there.clock.time_scaleis restored after the run unless the speed was changed meanwhile;clock.start_atrestarts the engine's sim clock, which stays where the run left it.- The runner keeps at most 200 000 frames per charger; an assertion that needs a dropped frame fails with "frame buffer overflowed".
POST /api/frames/expect: to catch a frame caused by your own action, pass thelast_seqof the action's answer (every charger action returns it: the frame-log seq before the action) assince; the answer hasoldest_seqand awarningwhensinceis older than the frame log.