Skip to content

Playground

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

Playground

The playground answers "what if" questions about the plan. What would the next days cost without the batteries? With a worse round trip? With every price a few cents higher? It runs a second solver on bare copies of the live objects and shows its plan next to the real one. It never writes to a device and never changes the live plan.

Important

A playground run is never applied. The live solver keeps running every quarter as usual and is the only one that steers your devices.

In the panel

The playground lives in the Planning tab, as the scenario switch in the header of the Controls card.

  1. Turn the switch on. A popup opens with three knobs:
    • Batteries on or off. Off gives every battery of the fleet a capacity of 0 kWh, so the plan runs without storage.
    • RTE, the round-trip efficiency in percent: of what a battery takes in over AC, this share comes back out. Empty means the live value.
    • Price in cents. Every buy and sell price of the last live plan, from the current quarter on, is shifted by this amount.
  2. The chart now draws the scenario instead of the real plan. Each lane is split in two halves: the real plan ("now") above the hairline, the scenario below it.
  3. The popup shows the scenario amount and the difference against now.
  4. While the switch is on, the fields that write to the real installation (mode, manual power, maximum grid power, correction) are disabled.

The switch is off for a past day, which always shows as it really went.

The amount

The amount of a run is the grid cost over the horizon minus the value of what the batteries hold more at the end than at the start, at the value the plan gives the end level. Without that correction a scenario that simply empties the batteries would look cheap.

To compare fairly, the panel always runs two plans: a reference run without any knob and the scenario run with the knobs. The difference between the two is shown as "vs now". Both come from the same copies and the same series, so the difference is the effect of the knobs alone.

When it runs

  • When the switch is turned on: the reference and the scenario.
  • When a knob changes: the scenario again.
  • When a new live plan arrives (every quarter, or after a settings change): the reference and the scenario again.

The runs are queued one after the other. A failed run shows its error in the popup and keeps the last result. Without a price provider the planner is off, and so is the playground.

How it works

flowchart LR
    A[Live entries] -->|bare copies, no entities, no hass| B[Copies]
    K[Knobs: values and series] --> B
    H[Series of the last live run] --> C[Second solver]
    B --> C
    C -->|one run, no apply| D[Scenario plan to the panel]
Loading
  1. Under the solve lock. A playground run waits for a running live solve and holds the lock itself, so it never reads the live objects halfway through a run.
  2. Bare copies. Each solver entry (prices, forecast, base load, battery fleet, managed consumers) gets a new object of the same class. Only plain data is copied: numbers, text, enums, dates, numpy arrays, and lists and dicts of those, each as a deep copy. References to anything real (Home Assistant, entities, devices, drivers) stay behind, and the copy gets an empty entity list, so a change of status publishes nothing.
  3. Stand-ins for the fleet. The distribution and every battery are replaced by small stand-ins that carry only what the plan reads of them: capacity, SoC (state of charge), SoC limits, power limits, phase, state, wear and a due calibration. Their update methods do nothing.
  4. The knobs last. The values the caller wants different are set on top of the copies; the changed series are written into the copies from the current quarter on.
  5. What the live run already knew. The second solver starts from the series of the last live run. The base load profile, the solar forecast per meter and the point where the real prices end are taken over from the live objects. A heating heat pump computes with the setpoint the live run had this quarter.
  6. One run. The second solver has no Home Assistant attached, so its entries skip every recorder read, calibration and web fetch, and its entity tracking is a no-op. It solves once and returns the plan in the same shape as the live plan. Nothing is applied.

Because the copies are separate objects, the live entries and the live series are exactly the same before and after a playground run; the tests in tests/playground check this, and that no call goes out to Home Assistant.

Beyond the panel

The panel uses the websocket command zenmaster/play (admin only). It takes two optional fields:

Field Meaning Example
values per entry id, battery device id or distribution: attributes to set on the copy {"solver": {"ac_in": 0.8}}
series per series id: values from the current quarter on {"temp": [-5.0, -5.0, ...]}

The panel only sets battery capacity, ac_in on the battery entry and the two price series, but the command accepts any plain attribute and any series of the plan, such as solar, temp or price_sell, or net metering on the price entry. Without values and series it returns the live plan's series unchanged. See The planner for the series and Battery model for ac_in.

In the code: custom_components/zenmaster/playground/solve.py, custom_components/zenmaster/playground/bare.py, custom_components/zenmaster/playground/fleet.py, custom_components/zenmaster/coordinator.py, custom_components/zenmaster/websocket.py, ui/src/zm-app.ts, ui/src/components/zm-overview.ts

Clone this wiki locally