Skip to main content

Layer 4: Coordination Engine

Production Ready Python License: MIT Layer 4 bridges the gap between Layer 3’s optimization schedules and real-world energy assets. It converts time-indexed dispatch plans into device-specific commands, manages asset state lifecycles, and provides event-driven coordination across the system.

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 an OptimizationResult.schedule DataFrame (from Layer 3) and produces timed Command objects:
  • EV columns (ev_{vehicle_id}_kw) become SET_CHARGE_RATE commands
  • Battery columns (battery_charge_kw, battery_discharge_kw) become SET_CHARGE_RATE / SET_DISCHARGE_RATE commands
  • Only emits commands on value changes (avoids redundant setpoints)
  • Tracks command lifecycle: PENDING → DISPATCHED → COMPLETED (or FAILED / TIMED_OUT)
  • Automatic retry with configurable backoff

State Machines

Generic finite state machine with energy asset presets:
OCPP-aligned lifecycle with 7 states:
Triggers: plug_in, start_charge, suspend, resume, complete, unplug, fault, reset, disable, enable

Protocol Adapters

Translate abstract commands into device-specific payloads:
Maps command types to OCPP 1.6/2.0 actions:Generates complete OCPP JSON payloads including charging profiles with power limits in watts.

Event Bus

Typed synchronous pub/sub with 8 event types:
Event types: COMMAND_CREATED, COMMAND_DISPATCHED, COMMAND_ACKNOWLEDGED, COMMAND_COMPLETED, COMMAND_FAILED, COMMAND_TIMED_OUT, STATE_CHANGED, SCHEDULE_RECEIVED

Integration with Qubit Stack

1

Receive Schedule

Layer 3 produces an OptimizationResult with a schedule DataFrame containing per-asset power setpoints
2

Generate Commands

DispatchEngine.schedule_to_commands() parses the DataFrame columns and creates timed Command objects
3

Validate State

State machines are checked before dispatch — commands to faulted or unavailable assets are held
4

Translate Protocol

The AdapterRegistry finds the correct protocol adapter and translates the command to device-specific format
5

Dispatch & Track

Commands are sent to assets, responses tracked, and events published for monitoring and re-optimization triggers

Next 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.