Pin result, conversion, plan and visualization of golden runs. Drive GENETIC through the optimizer interface and registry. Move GENETIC into one directory with role-named modules. Prepare every run input once, run from the parameters. Fall back instead of cancelling the optimization run. Simulate battery, EV and inverter from frozen dataclasses. Simulate the home appliance from frozen dataclasses. Convert and visualize from the parameters and result only. Serve GENETIC from its own router. Return a frozen result, build responses in the API. Echo the request as sent, not with an invented time window. Additional changes - Pin that the result does not depend on the number of evaluation workers. - Run the golden module in UTC: until the request date-times are held in UTC they render in the host time zone. - Add Optimizer.run_clock(), so the EMS gets slot length and time zone without GENETIC settings. - Rename ConfigOptimizationRequest, RuntimeForecasts and GeneticCommonSettings as ADR 0010 asks. - Correct the request example in ADR 0010. - Record the renamed OpenAPI schemas in CHANGELOG.md and the upgrade guide. - Add replay files that reproduce each golden result from its parameters. - Drop OptimizationBase from the algorithm. - Give the replay and worker tests own review files against xdist races. - Handle a failing preparation in the EMS like a failing run, no separate cancel path. - Record the fallbacks in CHANGELOG.md and the upgrade guide. - Without an inverter, buy the whole load from the grid instead of planning it at no cost. - Do not charge from the grid without any known price. - Treat an infinite value after the control horizon as a gap. - Correct the documentation that said missing forecasts cancel the run. - Copy the efficiency helpers and the self-consumption table evaluation into GENETIC. - Add CycleTimeWindowSequence, ConsumerScheduleMode and ConsumerDeadlinePolicy as contract names. - Hold the date-times of battery, EV and home appliance requests in UTC, so they render the same on every host. - Drop the UTC pin of the GENETIC golden module; the request date-times no longer depend on the host. - Copy the time window logic GENETIC needs into genetictimewindow.py. - Add ValueTimeWindow as a contract name. - Move the settings' to_genetic_*() converters into the preparation. - Drop the conversion's prediction reads and configuration fallbacks, which runs never reached. - Make the moved docstrings valid reST. - Remove the generic optimization solution route; each optimizer serves its own path. - Import the GENETIC settings from the package. - Record the removed route in CHANGELOG.md and the upgrade guide. - Make the terminal and tail value models frozen dataclasses. - Move the response models into geneticapi; remove geneticsolution and geneticabc. - Remove the legacy appliance start arrays and API, which read the wall clock. - Remove the time window helpers only they used. - Echo a start_solution without start_solution_datetime as sent. - Carry the previous solution's start in the run parameters. - Plan the home appliance cycles that fit, or leave the appliance out, instead of failing. - Move the appliance layout rules into geneticappliancelayout for the preparation. - Leave out a DAILY home appliance whose open windows leave no room for a run, with an error log, instead of silently. - Name the reason of the SoC fallback instead of Python's exception text. - Answer a solution request for an unknown algorithm with a 404 problem response. - Record the fixes in CHANGELOG.md and the upgrade guide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
11 KiB
Upgrading to the new energy planner
This guide covers the unreleased GENETIC and configuration update. It is intended for existing installations, especially Home Assistant, Node-RED and custom API integrations. It describes the intended combined update, not a new capability of the last tagged release.
What changes for you?
EOS can plan energy use in 15-minute or hourly steps. The new GENETIC planner can reuse a previous plan with its timestamps, charge an EV before a deadline, schedule flexible household appliances and optionally export stored battery energy to the grid. Battery export requires explicit opt-in; configuring export rates alone does not enable it.
The planner can also look beyond the period it will control, so it does not treat the last stored kWh as worthless merely because the plan ends. This remaining-energy value is separate from battery wear costs. Only the configured control period produces commands.
New measurement APIs report energy, household balance, coverage and quality. Missing measurements are not automatically zero consumption. Battery-capacity estimates help assess the battery but do not automatically replace its configured capacity. The Akkudoktor PV provider offers an optional local model with calibration; local modelling still needs weather data, and the existing remote backend remains the default.
Where can existing integrations break?
1. Device IDs replace list positions
Device collections now use stable names. For example, devices.batteries.0 becomes
devices.batteries.storage when that battery's ID is storage. Use the actual ID in
your migrated configuration; do not assume the example name. An explicit device_id
must match its map key, and the inverter must refer to the correct battery ID.
Supported old device lists migrate automatically. External configuration paths in
automations and scripts do not. Check those paths and the saved configuration after
migration. Battery wear cost is named levelized_cost_of_storage_amt_kwh.
The new GENETIC currently supports one inverter, one stationary battery, one EV and multiple household appliances. Surplus devices and a battery not linked to the inverter are left out of the run, and each is logged as an error; without a usable inverter the run plans grid energy only. Check the log after migrating your devices.
2. The two optimizer endpoints have different contracts
| Integration | What to use |
|---|---|
| Existing legacy optimization request | POST /optimize, which continues to run GENETIC0 |
| New configuration-driven GENETIC request | POST /v1/optimize |
| Automatic optimization | Explicitly select optimization.algorithm and its settings |
Keep algorithm settings under optimization.genetic or optimization.genetic0.
The default algorithm is GENETIC. If your automatic integration still requires the
legacy algorithm, select GENETIC0 explicitly; the legacy /optimize endpoint already does so.
For the new GENETIC, interval_sec is 900 or 3600. Supported flat settings from
the old feature branch migrate into the GENETIC section; explicit nested settings win.
The new request accepts soc, forecasts, start_solution and
start_solution_datetime. Hardware, device limits and schedules belong in configuration.
An empty JSON object uses configured providers and measured or assumed initial SoC. Hardware overrides
in the body and query-string overrides are rejected. Do not migrate by changing only the URL.
The legacy endpoint remains available, but the surrounding configuration has changed. That is not a promise that every old script works unchanged.
3. Missing SoC measurements and forecasts get logged fallbacks
Request SoC values are integer percentages from 0 to 100, keyed by device ID. Automatic
measurement lookup instead reads a factor from 0 to 1 using the configured measurement
key, by default <device_id>-soc-factor. For example, 50% is 50 in the request and
0.5 in that measurement channel.
Explicit request SoC values take precedence over measurements. Without an override, EOS uses the latest valid fresh measurement. If the measurement is missing, future, invalid or stale, the run assumes 0% initial SoC for that battery or EV and continues. The fallback is logged as an assumption and is never written as a measurement or a configuration change. SoC updates are therefore optional for planning.
The default measurement freshness limit is 300 seconds, controlled by
optimization.genetic.measurement_max_age_seconds. This limit determines whether a
measurement can be used; it does not require an update before every run.
Missing or invalid forecasts within the control period do not stop the run either. A forecast value that is missing, NaN or infinite within the control horizon gets a fallback: PV 0, an even load of 3000 kWh per year, a price or feed-in tariff carried forward (else the next known value, else 0); a negative PV or load value becomes 0. Each fallback is logged as an error: check the log after setting up your forecasts. A shorter forecast continuation is allowed and reported. Failed calls return an error; they no longer look like a successful new run by returning an older result. Existing automations should handle errors and verify the timestamp of any separately retrieved stored plan.
A charging target may equal the configured maximum SoC. For example,
devices.electric_vehicles.car.min_soc_percentage = 100 is valid when
max_soc_percentage = 100. A target above the maximum remains invalid.
The target is a planning objective; the achievable SoC also depends on the available
time, charging power and supported charge rates.
4. Check units, timestamps and result consumers
- Runtime forecast arrays start at local midnight and use the configured slot interval. Energy is Wh per slot, not W or kWh. A constant 1,000 W load uses 250 Wh in 15 minutes.
- A run within a slot plans the first slot only for the time left in it, given as
first_slot_fractionin the GENETIC result (0.25 for a run at 10:45 with hourly slots). The energies, costs and SoC change of that slot cover only that part, and its charge/discharge factors are the power for the remaining time. A run on a slot boundary plans a full first slot (first_slot_fraction1.0). - Executors of household appliances should report a started run: write its start (UNIX
seconds) to
<device_id>.run_started_atwhen switching the appliance on, and0when the device reports it finished. Without it, a re-plan may move or stop a running appliance. - Runtime purchase and sale prices are currency per Wh: 0.30 EUR/kWh is 0.00030 EUR/Wh. Provider power forecasts are converted by EOS; do not convert them a second time.
- Read returned timestamps and interval information instead of assuming 24 hourly values or a fixed number of slots on daylight-saving transition days. Automatic GENETIC runs use the site's timezone derived from its configured coordinates.
- Pass the previous plan's timestamp with a warmstart so it can be aligned to the new run. Recheck custom parsers of GENETIC results; its native result and report are not the legacy GENETIC0 response format.
- The OpenAPI schema names of the optimizers follow one scheme; fields and paths are unchanged:
GENETIC0's
Genetic0OptimizationParametersisGenetic0Request, its device and forecast models areGenetic0<Thing>RequestandGenetic0CommonSettingsisGenetic0Settings; GENETIC'sConfigOptimizationRequestisGeneticRequest,RuntimeForecastsisGeneticForecastsRequest, its device and forecast models areGenetic<Thing>Request(e.g.SolarPanelBatteryParametersisGeneticBatteryRequest) andGeneticCommonSettingsisGeneticSettings. Clients generated fromopenapi.jsonmust follow the new names. - The
parametersechoed in a GENETIC result are the request as sent: a home appliance without time windows showstime_windows: null, no placeholder window.
The new report endpoint is
GET /v1/energy-management/optimization/solution/GENETIC/pdf. It renders the stored
GENETIC result and returns 404 if none exists. The legacy PDF endpoint remains separate.
The stored GENETIC result itself is GET /v1/energy-management/optimization/solution/GENETIC
(GENETIC0: .../solution/GENETIC0). The generic route .../solution/{algorithm} is gone; use
the algorithm's own path. Any other algorithm name gets a 404 problem response (formerly 422).
5. Costs and schedules may change even with the same forecasts
Imported sale prices remain authoritative, including constant, zero and negative values. They are not replaced by purchase prices. Corrected slot power limits, inverter losses and battery wear costs can therefore produce different schedules and financial totals. The planner's AUTO/FIXED remaining-energy valuation is separate from those wear costs.
For upgrades from older releases, also check the electricity-fee framework. The old
elecprice.charges_kwh and elecprice.vat_rate fields are removed during migration,
not automatically translated into a complete fee setup. Configure the selected
elecfee provider and compare the resulting purchase/sale prices with your contract.
For the fixed provider, consumption fees use consumption_amt_kwh and
consumption_percent_amt under elecfee.elecfeefixed; the latter is a percentage,
for example 19 for 19%, not the old multiplier 1.19. These fields use time windows.
6. Configuration updates now take effect consistently
Explicit runtime updates take priority over environment and configuration-file values. Command-line settings still have higher priority. Environment values remain effective for keys not overridden at runtime. If an integration relied on an environment value silently overriding a later API update, its behaviour changes. Verify persistence after a restart according to your configured save mode.
Custom Python integrations must also follow the current asynchronous measurement and storage interfaces: await those methods. HTTP clients continue to exchange JSON.
A short upgrade check
- Back up configuration and stored measurement/database data, and record the currently installed version or image. Keep the backup for rollback; migrated data/configuration should not be assumed to work with an older executable.
- Inspect the migrated device IDs, inverter/battery links, algorithm settings and fees. Update external paths and request bodies where needed.
- Check fresh battery state and provider data. Run 60- and 15-minute GENETIC plans and compare units, timestamps, expected energy flows and costs before applying commands.
- Try an EV deadline and a household-appliance window if you use them. Check the stored result, execution plan and PDF agree. Test the legacy endpoint if you still rely on it.
- Test one missing-forecast or stale-measurement case. Confirm the run reports its fallback in the log, and that your automation handles failed calls and does not execute an old plan as a new one.
Automated tests cover the model and API contracts. They do not replace checking your actual Home Assistant entities, Node-RED flows, forecast sources and connected devices.