Skip to content

SCHEDULED_CHARGE_DISCHARGE

Runs an explicit weekly timetable of charge/discharge actions.

Mode string SCHEDULED_CHARGE_DISCHARGE (EMS_OP_SCHEDULED_CHARGE_DISCHARGE)
Dispatcher ems_main.py → control_logic_updated.control_step_scheduled_charge_discharge
Config block functions.Scheduled_Charge_Discharge
Queue source tag control_logic (the writer's default)
Status Implemented

Purpose

A deterministic calendar driver. Instead of reacting to price or load, it applies the weekly timetable: for the current local time it finds the matching slot and applies that slot's action and powerSetpoint.

How it decides

  1. Resolve "now" in timezone.
  2. Look for a matching entry in specific_dates.entries first (date-specific overrides).
  3. Otherwise scan the weekly calendar groups — MonFri, Sat, Sun — for an enabled entry whose start/end contains the current time.
  4. Apply:
  5. action: "charge" → -powerSetpoint kW
  6. action: "discharge" → +powerSetpoint kW
  7. Conflict rule. If more than one slot matches, conflict_rule (discharge_overrides_charge) decides.
  8. On SOC-blocked PCS, a 0 kW command is forced rather than skipping the PCS.

Configuration

functions.Scheduled_Charge_Discharge

Key Live value Meaning
enabled false Master switch.
timezone Europe/Stockholm Timezone for all slot matching.
soc_limits {null, null} Fallback SOC bounds when a PCS has none.
power_limits.charge_power_limit_kw 30 Plant charge ceiling for slots.
power_limits.discharge_power_limit_kw 30 Plant discharge ceiling for slots.
response_time_ms null Recorded; not used.
conflict_rule discharge_overrides_charge Tie-break for overlapping slots.
validation.prevent_overlaps true Configuration-time validation intent.
validation.min_duration_minutes 5 Configuration-time validation intent.
validation.time_format HH:MM Slot time format.
weekly.MonFri[] 2 entries start, end, enabled, action, powerSetpoint.
weekly.Sat[] 1 entry Same shape.
weekly.Sun[] empty Same shape.
specific_dates {dates:"", entries:[]} Date-specific overrides; empty in the shipped file.

Shipped timetable: Mon–Fri charge 12:50–12:55 at 25 kW then discharge 12:58–13:05 at 25 kW; Saturday charge 01:00–04:00 at 25 kW; Sunday empty.

Safety

  • Returns when is_external_control_active(), when enabled is false, or with no active PCS.
  • SOC gating is direction-aware per slot action: charge against max_soc_pct, discharge against min_soc_pct. Blocked PCS receive an explicit 0 kW.
  • Per-slot power is clamped by the plant power_limits, the per-PCS rating, and the final clamp in _pcs_connect_and_set_power_kw.

Outputs

_pcs_connect_and_set_power_kw(cfg, pcs_id, ±kw) → queue action set_power_kw, source control_logic.

Implementation notes

  • Module-level state: _SCHED_LOG (a persistent debug log) and _SCHED_DUMPED, a one-shot flag used to dump the schedule once at startup.
  • dbg_once suppresses the repeated "active_slot" line so the log is not flooded at 2 Hz.