Skip to content

Schedule Control

Documents the scheduled charge/discharge controller and the schedule JSON it reads from emsConfig/ems/ems_control_setting.json.

The controller is ems_schedule_control.py::scheduled_charge_discharge_step(). control_logic_updated.py::control_step_scheduled_charge_discharge() calls it every control cycle and applies the returned setpoint to eligible PCS.

JSON location

ems_control_setting.json
└── functions
    └── Scheduled_Charge_Discharge

Top-level fields:

Key Meaning
enabled Master switch for the whole function.
power_limits.charge_power_limit_kw Ceiling for every charge slot, and the default power when a charge slot has no setpoint.
power_limits.discharge_power_limit_kw Ceiling for every discharge slot, and the default power when a discharge slot has no setpoint.
conflict_rule How overlapping slots are resolved (see below).
weekly.MonFri / weekly.Sat / weekly.Sun Per-weekday-bucket slot lists.
specific_dates Date-specific overrides (highest priority). Three shapes: a per-entry date, a shared dates list, or an entries map keyed by ISO date.

Slot format

Each entry in a weekly or specific_dates list:

{
  "start": "00:10",
  "end": "03:00",
  "enabled": true,
  "action": "charge",
  "powerSetpoint": 50
}
Key Meaning
start / end HH:MM window. Start inclusive, end exclusive. Cross-midnight is supported (22:00 -> 06:00).
enabled Optional, default true. Disabled slots are ignored.
action charge or discharge (aliases chg/c, dis/d). Falls back to operationType, then to mode.
powerSetpoint Canonical power value in kW (always positive; the sign is implied by the direction). Falls back to power.

Variants that are also accepted, so slots written by older tools and by the UI all work:

{"start": "22:02", "end": "12:00", "enabled": true, "operationType": "charge", "powerSetpoint": 25}
{"start": "22:02", "end": "12:00", "enabled": true, "operationType": "charge", "power": 25}

Keys and fallbacks

Two pairs of keys decide what a slot does, and each pair has a fallback:

Meaning Preferred key Fallback Last resort
Direction action operationType mode
Power (kW) powerSetpoint power power_limits.*

The direction is read as action or operationType or mode, so an empty string in the preferred key still falls through to the next one. The first key that yields a valid direction wins; the conflict rule below decides between overlapping slots, never key order.

The power value is always positive: the sign is implied by the direction. If neither power key is present, the slot uses power_limits.charge_power_limit_kw or power_limits.discharge_power_limit_kw according to its direction. A power of 0 makes the slot inactive.

Whichever key supplies it, the resolved power is capped at that direction's power_limits value: a slot may request less than the limit, but never more, so charge and discharge can never exceed the configured limit. A limit of 0 (or a missing key) disables the cap, so a slot that carries its own powerSetpoint still runs.

The result object always reports the resolved power under slot.powerSetpoint, whichever input key supplied it, so downstream code has a single field to read.

Conflict rule

When several slots overlap, one wins:

Value Behavior
discharge_overrides_charge Discharge wins (default).
charge_overrides_discharge Charge wins.
first_match First slot in the list wins.

Priority

  1. specific_dates (date-specific slots matching today).
  2. weekly (the current weekday bucket).

Result object

scheduled_charge_discharge_step() does not write Modbus itself. It returns:

{
  "mode": "SCHEDULED_CHARGE_DISCHARGE",
  "active": true,
  "reason": "slot_active",
  "action": "charge",
  "charge_kw": 50.0,
  "discharge_kw": 0.0,
  "slot": { "start": "00:10", "end": "03:00", "source": "weekly.MonFri", "powerSetpoint": 50.0 }
}

charge_kw and discharge_kw are always positive. The caller translates them to the PCS sign convention (in this project -kW = charge, +kW = discharge).