Repository navigation
Real Time Control
The planner decides per quarter of an hour. Between two plans the house changes every second: a kettle switches on, a cloud passes. Real-time control follows the P1 meter (the smart electricity meter) on every reading and turns the fleet's target into a power setpoint for each battery.
With the optimize switch on, every solve sets the fleet mode from the plan for the current quarter:
| Plan for this quarter | Mode |
|---|---|
| batteries charge, grid buy planned | Individual |
| batteries charge, no grid buy | Smart charging |
| batteries discharge, grid sell planned | Individual |
| batteries discharge, no grid sell | Smart discharging |
| nothing | Off (every battery held at 0 W) |
In Individual mode each battery gets its own planned AC setpoint for the quarter. In the smart modes the fleet follows the meter, limited to one direction. The plan also hands over its own ranking of the batteries (see below).
On every P1 reading the demand is what the meter shows plus what the fleet delivers now (plus an optional setpoint_correction). Positive means the house needs power (discharge), negative means there is a surplus (charge). The mode then shapes it:
| Mode | Setpoint |
|---|---|
| Manual | the manual_power knob |
| Smart discharging | demand, never below 0 |
| Smart charging | demand, never above 0 |
| Store solar | charging only, and only while the panels produce |
The battery delivery cap max_output (for example 800 W in Germany) is applied to every mode. A setpoint of 50 W or less holds the fleet at 0.
Flipping between charging and discharging costs a stop and a cold start, so the fleet does not follow every short swing. When the demand points the other way, the fleet holds at 0 W while a budget of 3000 watt-seconds of opposite demand counts down. Only when it is used up does the direction flip.
Flipping back to charging shortly after the last switch to charging costs more: the budget is multiplied by 5 - minutes since that switch, at least 1. A flip back within the first minute needs five times as much opposite demand.
Every 10 minutes, and at once when a battery joins or drops out, the batteries are ranked per direction. A battery is left out when it is full (for charging) or empty (for discharging), by its own report or by its SoC, when it has no pack, or when it is not under ZenMaster's control. The score is:
score = headroom^2 * fit / (1 + 0.6 * wear / fleet mean wear)
| Factor | Meaning |
|---|---|
| headroom | the share of its SoC window still free in this direction; the SoC (state of charge) is rounded down to 10 % steps so the ranking only moves on a real difference |
| fit | how well the expected demand matches the battery's efficient band (30 % to 95 % of its rated power): min(1, demand / band low, band high / demand); the demand is a moving average over about 15 minutes |
| wear | equivalent full cycles over the last 7 days, see Battery model |
On an equal SoC step the current leader keeps its place: a swap for a small fit or wear difference would cost a stop and a start.
With optimize on, the plan's own order wins: first the batteries planned for this quarter (largest first), then those planned later (earliest first), then the rest in score order.
The setpoint is shared over the batteries that already run in this direction. A battery running the other way is stopped.
share = setpoint * weight / sum of weights
weight = rated power * (100 - SoC) when charging
weight = rated power * SoC when discharging
So the emptiest pack takes the most when charging and the fullest when discharging, and the SoC values drift together. No battery gets more than its rating.
Start rule. Each battery has a minimum power: 8 % of its rating for charging, 7.5 % for discharging, never under 50 W. When the demand is more than twice the running set's optimal power (a quarter of their combined rating), a standing battery starts at its minimum. Batteries start one by one until the excess is covered, in the plan's order with optimize on, otherwise the emptiest first when charging and the fullest first when discharging.
Stop rule. The first running battery (fullest when charging, emptiest when discharging) stops when its share stays under twice its minimum (once its minimum when it runs alone) for long enough: the shortfall is summed per reading until it passes 4 times its rated power when charging, 3 times when discharging. A started battery runs at least 150 seconds before this rule may stop it.
flowchart TD
P[P1 reading] --> S[Fleet setpoint from mode, cap and hysteresis]
S --> G{Every phase under its limit?}
G -- yes --> D[Split over running batteries, start and stop rules]
G -- no --> PG[Phase guard: per phase share by room]
PG --> D
D --> B[Setpoint per battery]
The connection limit per phase is max_kw / 3. Normally the whole fleet shares one setpoint. The phase guard takes over when a phase reads over its limit, or when the total demand would not fit with a margin of 230 W (1 A at 230 V) per phase.
- Room per phase: the limit minus 230 W minus the house load on that phase (the meter plus what the batteries on it deliver now).
- A phase over its limit is limited: its own batteries deliver (or stop charging) to bring it 1 A under the limit, as far as they can. If that is not enough, the three-phase batteries help, a third of their power landing on each phase.
- A limited phase stays limited until it reads 2 A (460 W) under its limit. In that band its batteries keep what they do.
- The free phases share the rest of the setpoint in proportion to their room, never past it.
In Individual mode every battery follows its own planned setpoint, and the phase guard still steps in: on a phase over its limit all its batteries land it 1 A under, and a free phase whose batteries together would charge past its room is held at that room.
In the code: custom_components/zenmaster/distribution.py, custom_components/zenmaster/solver/battery.py, custom_components/zenmaster/device.py
ZenMaster on GitHub · Releases · Issues · Licensed under GPL-3.0
Getting started
Devices
How it calculates
- The planner
- Battery model
- Real-time control
- House model
- Hot water tank
- Price model
- Solar, base load and phases
- Appliances and EV
- Recorder
More