Skip to content

[feat] Proposed: off-grid support — grid state, backup reserve and battery goal #2125

Backlog

Description

@Leitet

Status: proposed. I'm asking for a direction decision before any code PR. @frahlg, this is yours to decide.

Problem / motivation

Some households have a hybrid inverter with a backup switch, which keeps the whole house running on the battery during a grid outage. FTW can't support that well today:

  • No grid state. Core has no on-grid/off-grid state. A fresh site meter reading 0 W counts as healthy, so an outage looks like a quiet site. If the outage takes a P1/HAN meter down with the grid, the box shows site_meter_stale instead of saying what happened.
  • No backup reserve. On grid, FTW will plan and dispatch the battery down to soc_min. VISION.md separates "explicit backup needs" from operating limits and forecast caution, but no stated backup reserve exists yet.
  • No goal for the home battery. An external system that knows about a planned outage (a utility notice, Home Assistant, an agent) can't ask for "at least X % by time T". Deadline goals exist only for cars.
  • No defined behaviour while off-grid. During an outage the inverter runs its own backup logic. FTW keeps sending remote-control setpoints, and chargers keep drawing from the battery.

Desired result

FTW handles the fundamentals and stays out of why. Detecting or predicting outages stays outside FTW. I'm proposing three small, generic building blocks.

  1. Grid state from drivers. Add an optional grid_state: "on_grid" | "off_grid" field on the battery emit (host API; added in device-drivers).
    • A driver reports it only from an explicit vendor status it actually read. Frequency or voltage alone don't count, because an inverter in backup mode forms its own grid.
    • Core aggregates a site grid_state (on_grid / off_grid / unknown), with freshness and debounce, and exposes it in /api/status, the journal, the app and two push notifications: "off-grid" and "grid back".
    • Missing or stale data means unknown, which keeps today's behaviour exactly.
  2. Backup reserve. An optional durable setting, off by default, given either as a fixed % or as hours.
    • With hours, the reserve is the energy above soc_min needed for N hours. It's recomputed at each replan from the cautious net forecast that FTW already uses: load upside minus PV downside, counted as 0 in surplus slots. No second margin is added on top.
    • Without a cautious horizon, it falls back to point load with no PV, which errs on the safe side.
    • Effective floor = max(soc_min, reserve).
  3. Battery goal. "At least X % SoC by time T", received from the API, the app or an agent with owner approval, with no reason attached.
    • Only one goal is active, and a new one replaces it.
    • T can be at most 7 days ahead, and "full" means soc_max.
    • The goal ends at T. FTW does not hold the level afterwards; the caller sets a new goal if it needs more.
    • A goal it can't reach shows a shortfall, as car goals do. FTW never lowers the target silently.

Internally, 2 and 3 become one mechanism: a time-varying SoC floor, soc_floor(t), applied in:

  • Core DP: the per-slot MinEnergyWh replaces today's constant, and the default stays identical.
  • ValidatePlan.
  • Dispatch: the battery-boost reserve clamp, applyBatteryBoostReserve, generalised.
  • A no-plan fallback: the withDeadlineReserve pattern.

Energyplan gets a negotiated feature later, for example storage_min_energy_schedule. Until then, Core omits the field, rejects violating plans and uses Core DP. That's the same pattern as hourly_import_caps.

While off_grid:

  • Release the reserve, because this is what it's for.
  • Send the battery its driver_default_mode once, handing it to the inverter's own backup logic.
  • Mark the plan stale; no grid import/export is planned until the site is back on grid and stable.
  • Stop chargers and V2X at 0 W by default. A setting, stop | allow, changes that.

Alternatives considered

  • Infer the outage from 0 W, Hz or V, or from device_fault. Rejected. A quiet site reads 0 W, an islanded inverter supplies normal V/Hz, and device_fault takes the battery out of control.
  • Write the inverter's own backup-reserve registers. Rejected. FTW would become a second controller of a vendor setting. FTW may read and show them.
  • An outage-source integration in Core (a utility API). Rejected. It's site-specific and belongs to external automation.

Evidence and source material

  • FoxESS H3-Smart / 1K5 (foxess_h3_smart): the status block the driver already reads (39063, count 79) contains the off-grid flag. It isn't decoded today, so this needs no new Modbus reads and no writes.
    • FoxESS Modbus definition V1.05.04.00 puts it at "Status 3" 39065, bit 0.
    • fix: read the off-grid status bit from 39066 on H3 Smart nathanmarlor/foxess_modbus#1314 (merged 6 Nov 2026) measured a deliberate grid cut on the H3-Smart family. There 39066 bit 0 tracks the grid, and 39065 stays 0.
    • The same measurements show grid V/Hz reading 0 in a real outage, but normal during the inverter's own short disconnects.
    • OpenAmpere notes one spurious single reading, hence the debounce.
    • Which word applies on a 1K5-HI-10-V1 is still to be confirmed by a real grid cut.
  • Konja-261 SVK: already reads PCS 8063 (3 = off-grid) but only logs it.
  • Most other bundled inverter drivers expose grid Hz only. That's not enough on its own; those drivers stay unknown until a vendor status is verified on hardware.
  • Rules followed:
    • VISION.md, "Keep three concepts separate" and "durable user goals persist".
    • AGENTS.md: external automation expresses goals and Core validates; every clamp names its risk.
    • docs/safety.md.

Boundaries, failure behaviour and proof

  • Out of scope: outage detection or prediction, Home Assistant automations, per-battery goals, and writing inverter reserve registers.
  • Failure behaviour: with no driver reporting grid_state, nothing changes. With no reserve or goal set, plans are identical. Golden tests in Core DP will prove this.
  • Proof needed:
    • Unit tests for the floor in DP, validation and dispatch, and for goal expiry and replacement.
    • Site-rig scenarios with new grid_off / grid_on house events.
    • Driver fixture tests.
    • Before any off-grid behaviour merges: a hardware run on a FoxESS 1K5 with a planned grid cut, observing only, with model, firmware and readings reported.
    • A browser review for the UI.
  • Suggested order of small PRs:
    1. Per-slot floor refactor, with no behaviour change.
    2. Battery goal.
    3. Reserve as a %.
    4. Reserve as hours.
    5. FoxESS decode, in device-drivers.
    6. Grid state, status and notifications only.
    7. Off-grid behaviour.
    8. App, iPhone and Android paired.
    9. Energyplan feature.

Questions for the owner

  1. Is this direction OK: three building blocks on one time-varying SoC floor?
  2. Is grid_state on the battery emit the right host-API place, with a new extra field ID in appwire for the app?
  3. Should Core DP be the fallback until Energyplan negotiates the floor feature, or should the feature land in Energyplan first?

Area: MPC / planner, Control / dispatch, HTTP API, Driver, Web UI.

Activity

  1. added
    enhancement
    on Nov 29, 2026
  2. frahlg commented on Nov 29, 2026

    @frahlg
    Member

    Decision: yes. Let's take this all the way and test it on real hardware. I checked the evidence against the code and it holds: no grid state in Core, the FoxESS status block (39063, count 79) already covers 39065/39066, Konja reads PCS 8063 and only logs it, and applyBatteryBoostReserve, withDeadlineReserve and the hourly_import_caps pattern are where you say.

    The direction is approved: three building blocks on one time-varying SoC floor. Decisions on top of the proposal:

    Backup reserve

    • Both % and hours. Hours give a floor per slot: the energy above soc_min for the next N hours of the cautious net forecast (load upside minus PV downside, 0 in surplus slots), divided by the discharge efficiency. Without a cautious horizon, point load and no PV.
    • Show what the reserve costs. The planner prices the plan with and without the reserve and shows the difference. The reserve stays a hard floor; weighing it against price can come later.
    • Below the reserve (just set, or after an outage), FTW does not discharge further. It refills at the cheapest price, and reaches the reserve at the latest 12 h after the shortfall began. That uses the battery-goal mechanism. The reserve cannot reuse today's handling of a start below soc_min: clampParamsIntoOperatingBand lifts the starting SoC onto the floor, so the planner would believe the reserve is already full.
    • Dispatch applies the reserve in every mode through the existing owner floor (PowerLimits.SoCMin).

    Grid state

    • Report it on the inverter stream rather than the battery emit. That stream is the inverter's AC stage, which is what islands, and Konja already sends it. Core maps it to the same driver's battery for the default-mode hand-off.
    • Site aggregation: off_grid when any fresh, debounced report says off-grid; on_grid only when every reporting inverter says on-grid; otherwise unknown. The PR states the debounce times.

    Energyplan gets the floor together with the reserve, not last. It is the default engine on beta and stable, so with Core DP only, every site with a reserve would plan on the fallback. The feature is storage_min_energy_schedule: a per-slot min_energy_wh for each storage. Core splits the site floor over the batteries by capacity, so both planners plan the same floor. The worker already plans from a start below its floor without going lower; the feature makes that floor per slot. Until a worker announces it, Core follows the hourly_import_caps pattern: it rejects a worker plan that breaks the floor and uses Core DP, and the planner diagnostics say so.

    Order, in two tracks

    • Planning: (1) per-slot floor in Core DP, ValidatePlan and the worker wire, no behaviour change; (1b) the Energyplan feature and bundle; (2) backup reserve in % and hours, with refill; (3) reserve cost; (4) battery goal.
    • Grid: (5) FoxESS and Konja report grid_state in device-drivers. This comes early, so an observe-only grid cut on your 1K5 can settle 39065 against 39066. (6) Grid state in status, journal and notifications. (7) Off-grid behaviour, after that hardware run.
    • Then the web UI and app (iPhone and Android paired).

    The planning track builds on #2072, which plans each battery within its learned limits and changes the same DP loop. Work on (1) starts now; the PRs will link here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions