Electrical: Maximum Demand

Two‑stage shedding + restoration.

"timestamp": "2026-04-14T10:15:00Z", "demand_kw": 134.7, "limit_kw": 150.0, "demand_percent": 89.8, "peak_kw": 148.2, "peak_timestamp": "2026-04-13T18:30:00Z", "warning_level": "none", "shedding_active": false

CREATE TABLE md_log ( id INTEGER PRIMARY KEY, timestamp DATETIME, demand_kw REAL, peak_flag BOOLEAN ); CREATE TABLE md_config ( param TEXT PRIMARY KEY, value REAL ); -- e.g., ('limit_kw', 150.0), ('warning_pct', 80.0), ('window_min', 15) maximum demand electrical

# Update peak if demand_kw > self.peak_demand_kw: self.peak_demand_kw = demand_kw self.peak_timestamp = now_timestamp

+---------------------+------------------+ | Period | Peak Demand (kW) | +---------------------+------------------+ | 2026-04-01 to 07 | 142.3 | | 2026-03-25 to 31 | 138.9 | +---------------------+------------------+ | Condition | Handling | |-----------|----------| | Power loss | Persist buffer & peak to EEPROM. On restart, wait for full window before reliable demand. | | Incomplete window at startup | Use partial window average with a flag. | | Meter rollover | Detect by comparing readings; adjust delta with max meter reading. | | Communication delay | Timestamp each reading; interpolate if needed. | 9. Sample API / Interface (for system integration) // GET /api/max_demand/current Two‑stage shedding + restoration

Demand = (kWh_last_15min) / 0.25 To avoid storing raw energy every second, break window into N sub‑intervals.

// POST /api/max_demand/config

return demand_kw When demand approaches limit, shed non‑critical loads.