For kVA demand (common for utilities), measure voltage and current, then:
# Store in circular buffer self.buffer[self.index] = delta_kwh self.index = (self.index + 1) % self.num_blocks maximum demand electrical
+---------------------+------------------+ | 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 For kVA demand (common for utilities), measure voltage