Layer 4: Coordination Engine
Available Features
Dispatch Engine
Converts Layer 3 OptimizationResult schedules into timed commands with lifecycle tracking and retry logic
State Machines
OCPP-aligned EV charger and battery state machines with transition guards and event publishing
Protocol Adapters
OCPP adapter for EV chargers, Modbus adapter for batteries, with an extensible registry pattern
Event Bus
Typed synchronous pub/sub system for real-time coordination events across all components
Quick Start
Installation
Dispatch an Optimization Schedule
Architecture
Core Components
Dispatch Engine
The central orchestration component. It reads anOptimizationResult.schedule DataFrame (from Layer 3) and produces timed Command objects:
- EV columns (
ev_{vehicle_id}_kw) becomeSET_CHARGE_RATEcommands - Battery columns (
battery_charge_kw,battery_discharge_kw) becomeSET_CHARGE_RATE/SET_DISCHARGE_RATEcommands - Only emits commands on value changes (avoids redundant setpoints)
- Tracks command lifecycle:
PENDING → DISPATCHED → COMPLETED(orFAILED/TIMED_OUT) - Automatic retry with configurable backoff
State Machines
Generic finite state machine with energy asset presets:- EV Charger
- Battery
OCPP-aligned lifecycle with 7 states:Triggers:
plug_in, start_charge, suspend, resume, complete, unplug, fault, reset, disable, enableProtocol Adapters
Translate abstract commands into device-specific payloads:- OCPP (EV Chargers)
- Modbus (Batteries)
Maps command types to OCPP 1.6/2.0 actions:
Generates complete OCPP JSON payloads including charging profiles with power limits in watts.
| Command Type | OCPP Action |
|---|---|
SET_CHARGE_RATE | SetChargingProfile |
START_CHARGING | RemoteStartTransaction |
STOP_CHARGING | RemoteStopTransaction |
CHANGE_AVAILABILITY | ChangeAvailability |
Event Bus
Typed synchronous pub/sub with 8 event types:COMMAND_CREATED, COMMAND_DISPATCHED, COMMAND_ACKNOWLEDGED, COMMAND_COMPLETED, COMMAND_FAILED, COMMAND_TIMED_OUT, STATE_CHANGED, SCHEDULE_RECEIVED
Integration with Qubit Stack
Receive Schedule
Layer 3 produces an
OptimizationResult with a schedule DataFrame containing per-asset power setpointsGenerate Commands
DispatchEngine.schedule_to_commands() parses the DataFrame columns and creates timed Command objectsValidate State
State machines are checked before dispatch — commands to faulted or unavailable assets are held
Translate Protocol
The
AdapterRegistry finds the correct protocol adapter and translates the command to device-specific formatNext Steps
Get Started
Install and dispatch your first schedule in 5 minutes
Dispatch Engine
Deep dive into schedule-to-command conversion and lifecycle management
State Machines
EV charger and battery state machine details
Protocol Adapters
OCPP, Modbus, and custom adapter development
GitHub Repository
Explore source code and contribute
Layer 4 Coordination Engine bridges optimization intelligence with physical energy assets, enabling real-time dispatch and control.