Skip to content

Solar Base Load and Phases

Jan Brandsma edited this page Dec 4, 2026 · 1 revision

Solar, base load and phases

Besides prices, the planner needs three things about the house: how much solar power will come in, how much the house uses on its own, and on which phase each device sits. ZenMaster learns all three from your Home Assistant recorder; there is nothing to enter by hand beyond the entities.

Solar forecast

Forecast per production meter

Each solar group you configure has a power entity (its production meter). The forecast comes from Open-Meteo (model icon_seamless) in 15-minute steps for 672 quarters (seven days): direct normal irradiance (DNI), diffuse irradiance (DHI, diffuse horizontal irradiance), global (shortwave) irradiance, temperature at 2 m and wind speed at 10 m.

For every meter and quarter:

power = max(0, a[q] x DNI + C x DHI)

q is the quarter of the day in UTC (0 to 95), a[q] a learned factor for the direct part per quarter of the day, and C one learned factor for the diffuse part, shared by all quarters. The house forecast is the sum over the meters.

Meters of panels that belong to a battery (not on the house's AC side) feed that battery in the plan; only the other meters count as free supply on the house. The global irradiance is kept separately as the solar gain of the house.

Calibration

Once a day ZenMaster recalibrates a and C for every meter. The first calibration after a start runs before the first plan; later ones run in the background.

  1. Irradiance: Open-Meteo's 15-minute DNI and DHI for the last 10 days.
  2. Power: the recorder's 5-minute mean statistics of the meter over the same 10 days, averaged per quarter and converted to kW from the meter's own unit.
  3. Fit: one least-squares fit over all quarters where both exist and DNI + DHI is above zero, with one DNI column per quarter of the day and one shared DHI column.

A meter needs at least 50 such quarters; a meter without enough history gets no forecast.

Base load per phase

The base load is what the house uses without the devices ZenMaster plans. It is computed per phase from 28 days of hourly mean statistics, once a day at local midnight (and at start).

For each phase, weekday and hour:

base = P1 + AC solar / 3 + battery net - metered consumers      (never below 0)
Term Meaning
P1 The grid meter (P1 port of the smart meter) on that phase, with its own sign
AC solar Roof solar on the house's AC side, split evenly over the three phases
Battery net Battery output minus input to the house: fully on the battery's phase, a third on each phase when the battery is on all phases or has no phase set
Metered consumers Every consumer with a power entity (also one ZenMaster does not manage): fully on its phase, a third on each when on all phases; the absolute value is used, so a reversed meter still subtracts

Weighting. The value for, say, Tuesday 18:00 is the mean over all seven weekdays at 18:00, with the Tuesday samples counted twice:

mean = (sum all weekdays + sum same weekday) / (count all weekdays + count same weekday)

The result is a profile of 3 phases x 7 weekdays x 24 hours. Each planning run fills the whole horizon from this profile; the consumers then add their own plans on top.

Phase detection

ZenMaster finds each battery's and consumer's phase by watching which phase of the grid meter jumps when the device's power jumps. It runs once a day and from a button on the distribution device.

flowchart TD
    A[Raw states, last 10 days] --> B[SQL with lag: jumps above 50 W]
    B --> C[Merge device jumps within 15 s<br/>into one event]
    C --> D{Clean event?<br/>at least 150 W, roof and<br/>unknown devices quiet}
    D -- yes --> E[P1 jump per phase<br/>in the event window]
    E --> F[Ratio per phase]
    F --> G{At least 5 events,<br/>one phase at most -0.9,<br/>next at least -0.3}
    G -- yes --> H[Phase found, device becomes known]
    H --> D
Loading

Reading the jumps

A custom SQL query on the recorder's states table uses the lag() window function to compare every state with the previous one of the same entity, over the last 10 days. Only changes of more than 50 W are returned; everything smaller stays in the database. The entities are the three P1 phases, the roof solar meters, each battery's output (+) and input (-) and each consumer's power (-, like a charging battery).

Events and clean events

Per device, jumps less than 15 s apart are merged into one event: the ramp of one command. Each device also gets a lag: the shortest gap between two of its updates, at most 60 s, so the P1 step is looked for that much earlier.

An event counts only when it is clean:

  • the device moved at least 150 W;
  • no roof solar jump and no jump of a device with an unknown phase falls in the window, from 2 s plus the lag plus a 5 s margin before the event to 10 s after it.

For a clean event the P1 jumps per phase in the window are summed. A device whose phase is already known and that moved in the window gets its jump added back on its own phase, so it does not disturb the match.

Correlation per phase

For each phase:

ratio = sum(device jump x P1 jump on that phase) / sum(device jump squared)

On the device's own phase the meter follows the device one to one in the opposite direction, so the ratio is near -1; on the other phases it is near 0. A phase is found when there are at least 5 clean events, the best phase has a ratio of -0.9 or lower and the second best -0.3 or higher.

The matching runs in rounds: a device found in one round joins the known devices, which makes more events clean for the others. Devices with a phase already set count as known from the start, but are still judged themselves. A consumer set to all phases starts as unknown.

A result is applied only with at least 10 clean events and only when it differs from the phase that is set. A change gives a notification.

The per-phase limit these phases are checked against is used by Appliances and EV and by The planner.

In the code: custom_components/zenmaster/solver/forecast.py, custom_components/zenmaster/solver/baseload.py, custom_components/zenmaster/distribution.py

Clone this wiki locally