Skip to content

Recorder

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

Recorder

ZenMaster learns almost everything about your home from the Home Assistant recorder: the base load, the house and tank models, the price shape, the solar factor, appliance cycles, battery wear and the phase of every device. The recorder is a hard dependency in the manifest; without its history the calibrations have nothing to learn from.

This page describes what ZenMaster reads, at which resolution, how often, and what it does to keep the load on the database and the event loop low.

Note

By default the recorder keeps raw states and 5-minute statistics for about 10 days (purge_keep_days). Hourly and daily statistics are kept for good. ZenMaster picks its windows with that in mind: everything that needs 5-minute or raw data reads at most about 10 days.

Resolutions

The recorder offers several kinds of data, and ZenMaster uses the coarsest one that does the job.

  • Hourly statistics (long-term statistics, LTS) for most models. They are small, kept forever, and an hour is fine for a weekly profile or a heat balance.
  • 5-minute statistics (short-term statistics) where the shape within an hour matters: the solar calibration and appliance cycles. Three 5-minute means are averaged into one quarter of an hour, the time step of the planner.
  • Daily statistics for the History tab of the panel and for the last day a Zendure battery was full.
  • Raw state history only where a statistic would hide what is needed: jumps in power, the night cooling of a tank, and the replay export.

What is read, resolution, period, how often

What Resolution Period How often
Base load profile: P1 per phase, roof solar, battery AC power, consumer meters hourly mean 28 days once a day at local midnight, first at start
House model: heat pump power, room temperature, solar meters hourly mean 365 days weekly, first at start
Tank RC model (electric boiler, pool) hourly mean 90 days weekly, first at start
Hot water heat pump night loss raw states, held per minute 11 days (10 nights) daily, first at start
Price shape model: ZenMaster's own buy and sell price sensors hourly mean 24 days at start and at each price refresh
Solar factor per production meter 5-minute mean, averaged to quarters 10 days daily, first at start
Appliance cycle profile 5-minute mean, three to a quarter 10 days weekly, first at start
Battery wear and round-trip efficiency (RTE) hourly mean and change 7 days daily, first at start
Phase detection raw states, filtered in SQL 10 days daily, first at start, and on the button
Zendure last full day daily max of the state of charge (SoC) 30 days once, when the device starts
Panel History tab daily sum, state, mean; hourly mean of today's savings 30 calendar days when the tab is opened
Panel past day 5-minute mean, hourly as fallback 1 day when a past day is opened
Replay export raw states 24 hours on the button

The price refresh runs at start and after the provider's daily publish time, again every quarter until tomorrow's prices are in. See Price model, House model, Solar, base load and phases, Appliances and EV and Battery model for what each model does with the data.

Past days in the panel

A past day in the Planning tab is first read from the 5-minute statistics. When those are already purged, the same query is repeated on the hourly statistics, and every hour mean is put on all four quarters of that hour. A day older than about 10 days therefore still shows, just coarser.

Filtering inside the database

Phase detection looks for moments where a power reading jumps by more than 50 W, for the P1 phases, the roof meters and every battery and consumer. Reading 10 days of raw states for all of them into Python would be a lot of rows. Instead ZenMaster runs one custom query on the states table:

  • a lag() window function per entity, ordered by time, gives each value next to its previous one;
  • unknown and unavailable are skipped;
  • only rows where abs(value - previous) > 50 come back.

So only the jumps leave the database, everything smaller stays there. The query runs in a read-only session, so it can never change the database. The matching of jumps to phases runs on the same worker, and only the result comes back to the event loop.

Off the event loop

Home Assistant runs on one event loop; a slow call there freezes the whole system. ZenMaster keeps every slow step away from it:

  • Recorder reads go through the recorder's own executor (get_instance(hass).async_add_executor_job), never directly on the loop.
  • The solver: the linear program (LP) is solved by HiGHS in an executor thread, with a time limit of 30 seconds.
  • File I/O: the tariff file, the replay export, the panel bundle's timestamp and the optional raw MQTT log are all read or written in an executor.

Most calibrations also run as background tasks, so a solve does not wait for them. The exceptions are the first base load, the first solar calibration and the first price refresh after a start: the first plan needs them.

One query for many entities

Where a model needs several entities, they go into one statistics_during_period call: the base load asks for all its P1, solar, battery and consumer meters at once, the house fit for its heat pump, room and solar meters, the price model for both price sensors, the panel for all its series. Battery wear asks once per battery, for its three sensors. Phase detection reads every entity in its single SQL query.

Learned, not recomputed

What a calibration learns is stored, so a restart does not have to wait for it:

  • the house model, the tank RC model, the hot water heat pump losses and the appliance cycle profile are saved under learned in the entry's config subentry; an entry without one uses the shared zenmaster_calibration store;
  • on start they are restored before the first plan, and the next calibration simply runs on its own schedule.

The base load profile, the solar factor and the price shape are not stored; they are rebuilt from the recorder at start, which is why their first read comes right away.

Plan history across restarts

The planner keeps 12 quarters of history next to its plan. Every 15 minutes, and when the integration unloads, that history is written into ZenMaster's own store (zenmaster.devices). After a restart it is restored, as long as the last run is not older than 12 quarters (3 hours), and the next run shifts it on. Nothing has to be read back from the recorder for it.

Writing less

Reading is half of it; ZenMaster also limits what it writes to the recorder.

  • No polling: every entity has polling off; states are pushed only when data arrives.
  • Only on change: a sensor state is written only when the new value differs from the current one.
  • Rounding: values are rounded to the sensor's display precision first, so noise below that precision causes no new state.
  • kWh counters: the energy counters integrate every telemetry report, but push their state to Home Assistant at most once every 60 seconds.
  • Setpoints: a new battery setpoint is published only outside a 10 W dead band around the current power and the last setpoint.

What it does not do

ZenMaster does not exclude any of its entities from the recorder, does not purge or change recorder data, and does not write long-term statistics of its own. Its kWh counters are normal total_increasing sensors, and the recorder builds their statistics itself. If you want less history of ZenMaster's sensors, use the recorder's own exclude settings, but keep in mind that the calibrations read several of them.

In the code: custom_components/zenmaster/distribution.py, custom_components/zenmaster/websocket.py, custom_components/zenmaster/solver/baseload.py, custom_components/zenmaster/solver/heating.py, custom_components/zenmaster/solver/boiler.py, custom_components/zenmaster/solver/dynamicprice.py, custom_components/zenmaster/solver/forecast.py, custom_components/zenmaster/solver/consumers/appliance.py, custom_components/zenmaster/solver/solver.py, custom_components/zenmaster/zendure/solarflow.py, custom_components/zenmaster/coordinator.py, custom_components/zenmaster/sensor.py, custom_components/zenmaster/entity.py

Clone this wiki locally