Skip to content

fix(control): boot legacy planner modes into passive arbitrage - #1991

Merged
frahlg merged 2 commits into
masterfrom
fix/planner-legacy-modes
Nov 9, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/planner-legacy-modes

Conversation

@erikarenhill

@erikarenhill erikarenhill commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What

At boot, restoreStoredMode now treats the legacy planner modes planner_self and planner_cheap as no longer used. Like the removed priority and weighted modes, they are replaced and the replacement is saved:

Stored Planner enabled Planner off or missing
priority, weighted self_consumption self_consumption
planner_self, planner_cheap planner_passive_arbitrage self_consumption

Values FTW never had still keep the default mode and are left in place.

Battery export stays off

Neither legacy mode sold from the battery, and passive arbitrage doesn't either. When no battery_export answer is stored in SQLite or set in YAML, the replacement saves not_allowed. Without that, the self-consumption fallback would derive unknown, and the dashboard would ask the household to "allow selling to continue" for selling that never happened. A stored or configured answer is kept.

Behavior change to note

Passive arbitrage can charge the battery from the grid in cheap hours. planner_self never did. The changeset says so.

Not in this PR

  • AllModes/IsValidMode still accept the legacy keys on POST /api/mode, from Home Assistant and in the site test scenarios in go/test/site. Rejecting them there would break existing automations, so that should be a separate change.
  • A stored manual self_consumption ("Self (manual)") is a valid mode and stays as it is.

Tests

  • Renamed TestRestoreStoredModeReplacesRemovedAndLegacyModes.
  • New TestRestoreStoredModeLegacyPlannerModes: planner enabled, off or missing; the derived export is not_allowed; a stored allowed is kept.
  • go vet ./cmd/ftw and go test ./cmd/ftw pass.

Cross-audit

  • Codex: flagged that a stored allowed plus a later preference change remaps to active arbitrage. Not taken: master does the same for planner_self, because it is already a planner mode, and the household has answered "allowed".
  • Claude reviewer agent: behavior wording, planner off, test gaps. All fixed.

🤖 Generated with Claude Code

https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp

A stored planner_self or planner_cheap mode is replaced at restart by
planner_passive_arbitrage and saved, the same way removed modes are
replaced. Unknown stored values still keep the default mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp
With the planner off, a stored planner_self or planner_cheap now boots
into self_consumption instead of a planner mode with no plan. When no
battery-export answer is stored or configured, the replacement saves
not_allowed, so the household is not asked to allow selling that the
legacy mode never did. The changeset now says passive arbitrage can
grid-charge where planner_self did not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0124SQZZwXFRjnTEvh4SNrjp
@frahlg
frahlg merged commit 7350a3e into master Nov 9, 2026
23 checks passed
@frahlg
frahlg deleted the fix/planner-legacy-modes branch November 11, 2026 09:21
frahlg added a commit that referenced this pull request Nov 28, 2026
On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
… its first start (#2098)

* fix(web): Use the plan turns the planner on

On a box the setup guide made, the planner was off and "Use the plan"
was greyed out; the card sent the owner to Settings → Planner → Enabled
→ Save and a restart. The button now does that itself: it saves the
same setting through the Settings write, restarts FTW when the planner
has to start, hands the house to the plan and reads again every 3 s
until the plan shows. An error shows under the button.

The planning style, battery export and Manual… wait for the first plan,
and a home without a battery no longer reads about a battery. While
the forecast models still learn, the plan's forecast says "FTW learns
your home over the first days."

A box that never sold from the battery no longer asks whether selling
may continue. DeriveBatteryExport answers not_allowed for every mode
but active arbitrage, so a new box stores not_allowed. Turning the
planner on from off records not_allowed for a box that stored unknown.
An upgrade from active arbitrage is still asked, as #968 and
#1991 intended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* feat(planner): a new box plans from its first start

Planner on from the start now means the plan drives. A box with the
planner on in its config and no stored control mode starts in the
planner mode its battery-export answer maps to, and stores it like the
other first-boot values. A stored mode is kept.

The startup replan runs 2 s after start, often before the first
battery reading and prices, and failed. Only a planner mode retried a
missing plan, so any other box waited for the 15-minute replan. Core
now replans once as soon as prices and, for a site with a battery, a
fresh charge level are in. On a test box the first plan came 5 s after
the first start; master gave none in 90 s.

While the forecast models still learn, caution takes its margin from
priors, its alternative fails replay on a first plan and the box runs
the valid point plan. The card no longer shows that as "Plan without
extra forecast margin"; the learning line covers that time.

A home without a battery gets no planning style, battery export or
manual modes, and no "Why: Idle".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(planner): seed the planner mode only on a box's very first start

An existing box with the planner on in its config that never stored a
mode has run self_consumption all along. The seed would have handed it
to the planner on its next start without its owner choosing that.

The seed now needs a first start too. Core records a "startup" event at
every start and never prunes the event log, and the setup wizard writes
none, so an empty log read before this start records its own marks a
new box. A box that ran before, or was restored from a backup, has
events and keeps its mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(web): keep Manual… in a planner mode, and offer Restart FTW

Manual… is the only way off the planner on the Plan card. It waited for
a plan, so a battery home in a planner mode with no plan (no prices for
hours, or the battery offline) could not leave the planner from there.
It now shows in a planner mode with a battery, plan or not, and waits
only on a box that has never planned and runs the default mode. A
battery in the settings counts while its driver is offline.

When the restart after "Use the plan" fails, the planner setting and
the mode are already saved. The card says so in place and offers
"Restart FTW", which restarts and waits for the planner as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

* fix(planner): read the first battery charge through a health-gated accessor

The first-plan wait read battery readings straight from the telemetry
cache, which the telemetry-read check refuses. telemetry gains
FreshBatterySoCOnline: a charge level within BatterySoCMaxAge from a
driver that is online and not calibrating, the planner's own gates on
its starting charge. The wait uses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>

---------

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants