Skip to content

Predbat-led EV charger control: shared mixin, Octopus Intelligent rule and guest charging for GE, Ohme and Zappi (folds #5284 + #5311) - #5448

Merged
springfall2008 merged 47 commits into
mainfrom
feat/charger-control
Oct 12, 2026
Merged

springfall2008 merged 47 commits into
mainfrom
feat/charger-control

Conversation

@chalfontchubby

@chalfontchubby chalfontchubby commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Posted by Claude on behalf of @chalfontchubby.

Folds the former stack #5284 (shared charger-control mixin) and #5311 (control on automatically, Octopus Intelligent, guest charging) into one PR for a single final review, as Trefor suggested on #5284. It supersedes both, which will be closed once this is open. All their review threads were already answered and resolved; their commit history is kept as it was, so earlier review comments still map to commits.

Rebased onto main (8 Oct). One commit dropped: the gateway commit that moved its car plan parsing onto the shared parser, which main now has from #5120. Ohme's New Year tests from #5120 are ported to the shared control API. A local /code-review high before pushing found two small bugs in the existing code, fixed in the last commit: a dispatch time with no UTC offset raised a TypeError when compared with the clock (now read as UTC), and an is_charger of unknown/unavailable was read as "not the charger" instead of "cannot tell".

A later local review fixed one more (9c59c22): the Octopus/Kraken discovery wait is now timed per car, so a car whose driver is known no longer restarts another car's 15-minute wait. Before, in a multi-car setup, a wired car reset the shared timer every cycle, so a car still waiting on discovery never reached "cannot tell" and its charger was held as it was indefinitely.

Known and not changed here (from the same review): the Ohme charger is keyed by serial or the literal "ohme", which would orphan held state if the serial arrives late; the guest switch republishes on the next poll rather than immediately.

Update, 12 Oct: control stays opt-in (91f9f97)

Review changes from Trefor, pushed to this branch. Where the text below disagrees with this section, this section is current.

  • Charger control no longer turns on automatically. ge_cloud_evc_control and myenergi_zappi_control default to false again, as on main, so nobody's charger behaves differently on upgrade unless they had already set its control setting to true. ohme_control was already opt-in. MyEnergiAPI.automatic_set_by_user() is removed.
  • A Zappi's own mode survives a restart. The mode a Zappi was in before Predbat took over is saved to storage (myenergi / control_saved_modes) and loaded on the first run. A restart used to lose it, and the next snapshot was Predbat's own Stopped. Modes left in storage are dropped if control is off at startup.
  • A saved Stopped is restored like any other mode. This replaces 150f4f1, which released to Eco+ instead of Stopped to work around the lost snapshot. The hand-over to Octopus restores Stopped too; it still uses Eco+ in place of Fast.
  • Checked with: the car_charger_control, ge_cloud, myenergi, ohme, car_charging_smart and components test groups, and pre-commit on the changed files. The full suite was not run locally for this commit.

Two consequences of control only ever running with true:

  • The mixin's "unset" behaviour - leaving a charger alone when it cannot tell whether Octopus drives it, the 15-minute wait for Octopus or Kraken discovery, and their warnings - is no longer reached by any component. The code and its tests are still here.
  • One case 150f4f1 covered is open again: a Stop that timed out but was applied, followed by a release and a later take-back, snapshots that Stopped as the Zappi's own mode.

Part 1: shared mixin (was #5284)

Summary

Predbat-led EV charger control (start/stop the charger from the car charging plan) was implemented three times, once each in gecloud.py (GivEnergy EV charger), myenergi.py (Zappi) and ohme.py, with a fourth window parser in gateway.py. This PR moves the shared loop into one mixin, CarChargerControl (car_charger_control.py), before we add more chargers (Hypervolt, Wallbox).

The mixin owns:

  • reading each car's plan from binary_sensor.predbat_car_charging_slot[_N]
  • on inside a window, off outside one, sending only on a change
  • re-applying when the charger has been changed elsewhere (drift)
  • releasing on read only mode or when the control switch is turned off, and resuming afterwards
  • persisting the control switch across restarts

Each component keeps only what is specific to its charger: which chargers exist and in which order, whether a car is connected, how drift is detected, and the on/off/release commands. Log wording for those commands is unchanged.

One commit per step; each passes the quick suite on its own:

  1. Add the mixin, with its own tests
  2. GivEnergy EVC onto it
  3. Zappi onto it
  4. Ohme onto it
  5. Gateway: shared window parser only
  6. Review fixes: release a charger whose car has gone, and retry refused GivEnergy commands
  7. Later review fixes: one charger refusing no longer blocks the others, and a released Zappi forgets its saved mode

Behaviour changes

Intended to be a refactor, with these exceptions:

  • New Year fix (Ohme, gateway). Their inline parsers missed this case: read just after midnight on 1 January, a window that started on 31 December parsed as the following December, so a charge running across midnight was paused/stopped. Both now use the shared parse_car_plan_windows(). The gateway copy also moved any window starting more than 23 hours ago a year forward; a finished window now stays finished.
  • Chargers with no car to follow. If there are more chargers than num_cars (briefly true while auto-config's num_cars reaches the base), an extra Zappi is now left alone instead of Stopped, matching what GivEnergy EVC already did. A charger Predbat was already holding when its car drops out of num_cars is released back to its own mode rather than left in the state Predbat last set.
  • Ohme release retry. A release Ohme refuses is now retried on the next control cycle rather than attempted once, so one failed call can't strand a paused car. Ohme's control tick is now wrapped like myenergi's: a refused command logs a warning instead of failing the whole run, which would otherwise repeat every minute while read only is on.
  • GE EVC refused commands retried. async_send_evc_command() reports a refusal by returning None, so a refused start, stop or release used to be recorded as sent and never retried; a refused release could strand a stopped charger. GE charger control now raises EVCCommandFailed on a refusal, so nothing is recorded and the command is tried again next cycle. GE's run loop catches it as a warning, as Ohme's and myenergi's do.
  • GE EVC read only fallback. When base.set_read_only is unset, the EVC loop now falls back to the set_read_only arg like the other chargers, not the switch entity. Predbat sets the attribute at startup (predbat.py), so this only affects test doubles. GECloudDirect.read_only_now() is kept for the inverter code that uses it.
  • Each charger handled on its own. Releasing and driving used to run as one loop, so the first charger to refuse a command stopped every charger after it, every cycle - with two Zappis held Stopped and read only on, a refusing Zappi 1 left Zappi 2 Stopped for good. Each charger is now handled on its own; the first failure is still raised afterwards for the run loop to log, and only the charger that refused is retried.
  • Zappi saved mode. A Zappi released because its car dropped out of num_cars kept its saved mode, so taking it back later restored that stale mode on the next release. The saved mode is now dropped once that Zappi's release goes through.
  • Some generic log lines (release, resume, drift) now share one wording.

Gateway control is not moved onto the mixin here: that would add release on read only, which is a behaviour change. It belongs in a follow-up.

Testing

  • New tests/test_car_charger_control.py covers the mixin against a fake component.
  • Existing GE, myenergi, Ohme and gateway control tests: internal names updated, assertions unchanged. Exceptions:
    • The gateway year-boundary test pinned the old "older than 23 hours means next year" heuristic. It is replaced by the two real New Year cases on a fixed clock, plus a finished-window case.
    • Ohme's New Year test gains the after-midnight case.
    • Two new myenergi tests cover a failed release being retried with the saved mode intact, and a mode saved ahead of a refused command being forgotten on release. A cold review found both issues; the retry test fails without the fix.
    • A new Ohme test covers a refused release being retried without failing run(), and a new mixin test covers a release that fails part-way through several chargers. Both come from an adversarial review; the Ohme test fails without the fix.
  • Review fixes: a mixin test covers a held charger whose car drops out of num_cars being released, and GE control tests 11 and 12 cover a refused stop and a refused release being retried rather than recorded.
  • Later review fixes: a mixin test covers a refusing charger not blocking the others (and the existing part-way release test now expects only the refusing charger to be retried), and a myenergi test covers a released Zappi snapshotting its mode afresh when taken back.
  • tools/debug-journal.md's myenergi entry is updated for the renamed methods.
  • Rebased onto main on 5 Oct. Main's Ohme changes in feat(ohme): take the car plan from Ohme's own schedule when Predbat is not controlling the charger #5401 and fix(ohme): leave the Intelligent car slots to Octopus when the Intelligent device is the car #5405 re-decide control on every poll and hand the charger back when Octopus Intelligent takes over. That hand-back now goes through the mixin (charger_control_state / charger_control_release()), with the same retry until it succeeds, and feat(ohme): take the car plan from Ohme's own schedule when Predbat is not controlling the charger #5401's tests are updated for the new state names.
  • Every commit passes pre-commit and the full suite on its own.
  • A hand-back that Ohme refuses in that new fix(ohme): leave the Intelligent car slots to Octopus when the Intelligent device is the car #5405 path used to raise out of the poll, as it did on main, while the control tick caught the same refusal as a warning. It is now a warning too, and the charger stays held so the next poll retries (13ab132).

Part 2: Octopus Intelligent rule and guest charging (was #5311)

What this does

Stage 2 of Predbat-led EV charger control. Control stays opt-in for every charger, as on main:

Setting Unset or false true
ge_cloud_evc_control off on; needs ge_cloud_automatic_evc, and warns if it is missing
ohme_control off: Ohme's own schedule is the car plan (#5401) on; needs ohme_automatic
myenergi_zappi_control off on; needs myenergi_automatic, myenergi_automatic_zappi and myenergi_enable_controls, and warns if one is missing

For chargers under control it adds three things, each described below:

  • a per-car rule for Octopus Intelligent;
  • a guest charging switch;
  • a few fixes found while reviewing it.

Behaviour change on upgrade

Users who have not set a control setting to true see no change to their charger.

Users who already had *_control: true get the new Octopus rule and the guest switch. Two parts of the Octopus rule change things for them:

  • Where Octopus drives the charger, Predbat now hands it over and leaves it alone, where before it drove the charger to its plan.
  • Where Octopus drives the car itself, Predbat now releases the charger and leaves it alone unless switch.predbat_octopus_intelligent_charger_follows_car is on, where before it drove the charger to its plan.

A charger Predbat drives is also switched on while a dispatch on the car's dispatch sensor is running, as well as inside its plan.

For homes with more than one car, each car's binary_sensor.predbat_car_charging_slot_N now carries only that car's windows (7fac8d5), which also changes what the Wallbox component and any user automation read from it.

The docs cover this in car-charging.md, in the section "Predbat starting and stopping your charger". The Octopus rule probably wants a line in the release notes.

Decisions, and the options rejected

  1. Control is opt-in for every charger (91f9f97, replacing fa7c9f6). An earlier version turned GE control on with ge_cloud_automatic_evc, and Zappi control on when the user had written myenergi_automatic or myenergi_automatic_zappi into apps.yaml. Both are withdrawn in review: an upgrade should not start Predbat driving a charger, and a Zappi Predbat controls is Stopped between windows, so it stops diverting solar in Eco/Eco+.
  2. Ohme stays opt-in (e631a2c, replacing 7a35d85). Since feat(ohme): take the car plan from Ohme's own schedule when Predbat is not controlling the charger #5401, an Ohme that Predbat does not control already has its own schedule taken as the car plan, so the default user gets a plan that matches what the charger does. Turning control on by default would override that schedule, which the user may have set up deliberately, with max charge, which also overrides the Ohme app's target.
  3. Octopus Intelligent is judged per car (067f637, d3663f6, 3f6422c). You agreed this on refactor(car): share Predbat-led EV charger control across Ohme, Zappi and GivEnergy #5284. Predbat reads is_charger from the car's own dispatch sensor in octopus_intelligent_slot. Both the Octopus and Kraken components publish it, so E.ON/EDF SmartFlex is covered, and a car can't be paired with another car's device. What Predbat does depends on which device Octopus drives:
    • Octopus drives the charger: Predbat leaves the charger alone, whatever switch.predbat_octopus_intelligent_charging says. That switch only changes Predbat's own planning; Octopus keeps switching the charger either way, so driving it would fight Octopus.
    • Octopus drives the car: by default Predbat leaves the charger alone; a charger it was holding is released as usual, since nobody else drives it (5fa79fb, 0ab856d). A new expert-mode switch, switch.predbat_octopus_intelligent_charger_follows_car (default off), has Predbat drive the charger instead: on during dispatches and off otherwise, so the car cannot charge on its own timers. It follows the plan and also the dispatch times on the sensor, judged against the clock, so it picks up a new dispatch without waiting for the 5-minute plan and stops the charger when the dispatch ends. With octopus_intelligent_charging off, Predbat plans the car itself and the charger follows that plan, whatever the new switch says. The Ohme follows the same rules (bbbfb3f), so with the switch on ohme_control: true can run where fix(ohme): leave the Intelligent car slots to Octopus when the Intelligent device is the car #5405 would otherwise stand it down.
    • Can't tell (for example the Octopus Energy HA integration's sensor, or the Octopus or Kraken component has not wired its devices yet): Predbat drives the charger, as on main. Control only runs with *_control: true, which is the user saying their charger is not the Octopus device. The mixin can instead leave such a charger alone, with a warning and a 15-minute wait for discovery (6cec384), but only for a component that passes its control setting as unset, and none does now.
  4. Handing a charger to Octopus never starts a charge (d3663f6). A normal release undoes a stop, so that read only mode never leaves a car unable to charge. Octopus deciding when to charge is different, so the hand-over does this instead:
    • GE: sends nothing.
    • Ohme: turns max charge off, then resumes into its smart schedule.
    • Zappi: goes back to its own mode, with Eco+ in place of Fast.
  5. Guest charging switch (b6d30e4, 8032b55, ec86180). While Predbat drives a charger it holds it off outside the plan, so a visitor's car can't charge. The switch lets them:
    • The entities: switch.predbat_gecloud_guest_charging, switch.predbat_myenergi_guest_charging and switch.predbat_ohme_guest_charging.
    • What it does: releases the charger, as read only mode does. How the guest charges (boost, solar only) is chosen on the charger itself; Predbat never picks a mode.
    • When it ends: when a car plugged in after the switch went on is unplugged, using the plug state of all three chargers. Unplugging the owner's car to make way for the guest doesn't end it. It also ends after 12 hours.
    • Restarts: it isn't remembered across a restart.

Fixes found in review before opening

  • Octopus discovery: with octopus_automatic off, Predbat waited for Octopus discovery that never came, so control never turned on.
  • Setting values: a quoted "false" or a 0 read as on, because removing the defaults also skipped get_arg()'s boolean conversion. parse_control_setting() now normalises them.
  • Dispatch end: following the dispatch sensor's on/off state ran the charger up to about 3 minutes past the end of a dispatch.
  • GE status blip: an offline or unavailable status on a GE charger ended guest charging.

Found by a further /code-review after opening:

Merged with main (12 Oct)

Main is merged in (ace254e), not rebased, as the PR is under review. It brought #5443, under which Octopus provides an Ohme's completed Intelligent dispatches and the Ohme provides the planned ones. The one conflict, in OhmeAPI.__init__, is between independent state: #5443's slot_source and this PR's follows_car. Both are kept, and the rest of update_slot_mode() merged cleanly with both sides intact.

Two follow-ups from that merge:

Known and not changed: when an Ohme shares a home with a second charger, which car each charger follows still depends on the order of Octopus's device ids. The claim always covers car 0, and the Ohme's own dispatch sensor may sort to index 1. The same ordering affects #5443's choice of sensor on main.

Rebased onto main (5 Oct)

The stack is rebased onto main, which meanwhile changed the Ohme component in #5401 and #5405. How the two fit:

Found by review after the rebase:

  • Can't tell stranded a GE charger: it was let go without being started, as if Octopus were taking over, so a charger Predbat had stopped stayed stopped with nobody in charge (5394c56).
  • Discovery waited for good: a Kraken component whose first run never succeeds left every unwired car's charger alone indefinitely. Now bounded at 15 minutes, and a held charger is left as it is while waiting rather than released, so a component restart does not start a charge (5394c56, 6405d2e, c8278fd).
  • A false warning on restart: the apps.yaml default's literal re: string, before its regex matches, was read as a dispatch sensor (5394c56).

Found in review on this PR (11 Oct)

  • One car's plan published before another's (Copilot, 27cecbb, 3d616b3): control waited only until any car's slot sensor had a plan. With car 0's published and car 1's not yet, car 1 read as an empty plan and its charger was stopped. A car with no published plan is now unknown: its charger is left as it is until its plan appears or an Octopus dispatch says to charge. A charger Predbat already holds is still driven, so one a dispatch started is stopped when the dispatch ends.
  • A plan that goes missing for a cycle (a6b9e17): a held charger whose slot sensor briefly lost its planned attribute was driven from an empty plan and stopped mid-window. The windows are absolute times, so the last ones read are kept.
  • Every car's slot sensor carried every car's windows (7fac8d5): publish_car_plan() in output.py built one plan list and handed the same list to every car's sensor, so with two or more cars each sensor's planned held all of them. This is on main too, but this PR drives charger N from car N's planned, so a charger would start in another car's window. The fix is one line: the list is created per car.
  • Ohme hand-back refused (13ab132): see the testing note above.
  • Zappi released back to Stopped (150f4f1, superseded by 91f9f97 - see the update at the top): after a restart, or a Stop that timed out but was applied, the first snapshot of the Zappi's mode is Predbat's own Stopped. Release and the hand-over to Octopus now treat a saved Stopped like no saved mode and use Eco+, so a release never leaves the car unable to charge. An attempt to snapshot only after the command went through (3ff61b7) made this case more likely, and is reverted (cf2f77c).
  • Debug journal (Copilot, 1ddffc0): the Sunsynk/Deye sentence had been caught by the myenergi rename; those components persist control_active, not charger_control_active.

Each behaviour fix has a test that fails without it. These commits were checked at the tip with the quick suite and pre-commit, not one by one.

Not in this PR (known and deferred)

  • Empty Zappi or Ohme: Predbat still sends commands to one with no car plugged in. Only GE skips an empty charger today. Using the plug state there is a separate change, because a car plugged into a Zappi left in Fast could charge for up to a minute before the next tick.
  • Guest energy: the guest's charging is still counted as the owner's car's.
  • GE size and limit: whether GE needs the same size/limit guard as the Ohme.
  • Ohme ohme_automatic_octopus_intelligent: has the same quoted-"false" problem, from before this PR.
  • No cars: with num_cars at 0 there is no plan to read, so control does nothing that cycle, including releasing a charger it holds. This comes from refactor(car): share Predbat-led EV charger control across Ohme, Zappi and GivEnergy #5284 and is unchanged.
  • Discovery wait with true: an explicit true skips the wait for Octopus or Kraken discovery, so for a cycle or two after a restart a charger Octopus drives can be commanded before its dispatch sensor is wired. This was already the case for true users; it now applies to everyone under control.
  • Saved mode and target after guest charging: when guest charging ends, Predbat takes the charger back and snapshots whatever mode (Zappi) or target (Ohme) the guest left, and restores that at the next release.
  • Hardware: not tested on real chargers. In particular it is unverified that an Ohme resumed into its smart schedule doesn't start charging outside a dispatch.

Testing

  • New tests: for each decision above, in test_car_charger_control.py, test_ge_cloud.py, test_ohme.py and test_myenergi.py.
  • Checks: every commit passes pre-commit and the full suite on its own.
  • Reviews: two rounds before opening and four after the rebase, each a cold subagent review plus a local /code-review high. Their findings are the fixes listed above.

🤖 Generated with Claude Code

chalfontchubby and others added 28 commits October 8, 2026 18:51
Ohme, myenergi and GivEnergy EVC each carry their own copy of the same
control loop. CarChargerControl owns it once: read the per-car plan,
charge inside a window and stop outside one, re-apply on drift, and
release on read only or when the control switch is turned off, with
the switch persisted across restarts. Components supply only the
charger-specific send, release, connected and drift checks.

Nothing uses it yet; the components move onto it in following commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GivEnergy EVC control moves onto CarChargerControl. The component keeps
what is GivEnergy's own: which chargers exist and in what order, whether
a car is connected, and the start-charge / stop-charge commands.

Behaviour is unchanged: the switch keeps its storage key, chargers
without a car are still left alone, and release still only restarts a
charger Predbat had stopped. The EVC read only check now falls back to
the set_read_only arg, like the other chargers, rather than the switch
entity; the fallback only applies before Predbat sets the attribute at
startup. The test double's get_arg answers set_read_only from the same
flag as its switch, as Predbat does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Zappi control moves onto CarChargerControl. The component keeps what is
myenergi's own: Fast inside a window and Stopped outside one, drift
detected from the polled mode, and release back to the saved mode or
Eco+.

One deliberate change: a Zappi with no car to follow (more Zappis than
num_cars, briefly true while auto-config's num_cars reaches the base) is
now left alone rather than Stopped, matching what GivEnergy EVC control
already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ohme control moves onto CarChargerControl. The component keeps what is
Ohme's own: max charge inside a window and pause outside one, drift
detected from the session mode, and release back to Ohme's smart
schedule with the user's target percent restored. Ohme has no control
switch, so read only stays the only release.

Its inline plan parser goes too, in favour of the shared one. That
fixes a New Year case the copy missed: read just after midnight on
1 January, a window that started on 31 December parsed as the following
December, so a charge running across midnight was paused.

A release Ohme refuses is now retried on the next control cycle rather
than attempted once, so a paused car is not stranded by one failed
call. The control tick is wrapped the way myenergi's already is: a
refused command logs a warning instead of failing the whole run, which
would otherwise repeat every minute while read only stays on.

The mixin now checks for a switch before touching storage, so a
component with no switch never needs a storage attribute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… retry refused GE commands

- A charger Predbat holds that falls beyond the cars it follows (num_cars
  dropped) was never commanded again, left charging or stopped with
  nobody in control. apply() now releases it.
- GivEnergy's async_send_evc_command() reports a refusal by returning
  None, so a refused release was taken as done and a stopped charger
  stranded - the failure the Ohme and myenergi retries already close.
  GE charger control now raises EVCCommandFailed on a refusal, so the
  command is not recorded and is tried again next cycle; GE's run loop
  catches it as a warning, as Ohme's and myenergi's already do. A
  refused start or stop is retried the same way rather than recorded as
  sent.
- Docstring for a nested test helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eased Zappi forgets its mode

Found by a later review, in code from this PR:

- Releasing, releasing a charger whose car has gone, and driving from the plan ran as
  one loop, so the first charger to refuse a command stopped every charger after it -
  and each cycle retried in the same order, so they stayed blocked. With two Zappis
  held Stopped and read only on, a refusing Zappi 1 left Zappi 2 Stopped for good. Each
  charger is now handled on its own; the first failure is still raised after the rest
  have had their turn, for the run loop to log and retry. A charger is forgotten as
  soon as its own release goes through, so a retry re-sends only to the one that
  refused.
- A Zappi released on its own (its car gone when num_cars dropped) kept its saved
  mode, so taking it back later saved nothing new and the next release restored the
  stale mode. The saved mode is now dropped once that Zappi's release goes through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arger

Charger control now decides per car whether Octopus Intelligent is in
charge of the charger. Where Octopus delivers its dispatches by driving
the charger itself, Predbat leaves it alone - releasing it if it was
holding it - so the two never fight. Where Octopus drives the car, or
there is no Intelligent car, Predbat drives the charger from the car
slot sensor, which then carries the Octopus dispatches, so the car
cannot charge outside them on its own timers.

Octopus car N is the Nth wired Intelligent device, and the Octopus
component already records whether each is a charge point. When that
cannot be told - slots from outside the Octopus component, or before
it has discovered its devices - the charger is left alone, unless the
component's control setting is explicitly true.

Nothing turns control on by default yet; that follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ge_cloud_evc_control no longer defaults to false. Left unset, control follows
ge_cloud_automatic_evc: setting that is the user asking Predbat to plan for the car,
and it is what maps each charger to its car. An explicit false keeps control off,
and only an explicit true warns when a prerequisite is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ohme_control no longer defaults to false. Left unset, control follows ohme_automatic,
which registers the car. Where the Intelligent slots come from the Ohme, Octopus
drives the charger and Predbat still leaves it alone - logged as Info for an unset
control, and as a warning only when ohme_control was explicitly set true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tomatic

myenergi_zappi_control no longer defaults to false. Left unset, control turns on
only when the user wrote myenergi_automatic or myenergi_automatic_zappi into
apps.yaml themselves. Both default on, so following their values alone - the rule
GE and Ohme use - would switch every Zappi user to Predbat control on upgrade, and a
Zappi held off between windows can no longer divert solar in Eco/Eco+. The options
considered are recorded in enable_control()'s docstring for review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Intelligent

A new "Predbat starting and stopping your charger" section in car-charging.md sets
out when each charger's control turns on while its setting is unset, the upgrade
change for existing automatic users, and what happens on Octopus Intelligent
depending on whether Octopus drives the charger or the car. The per-setting entries
in apps-yaml.md and components.md now describe the unset default instead of false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er start a charge handing over

Found by review before opening the stage 2 PR:

- Read is_charger from the car's own wired octopus_intelligent_slot sensor instead of
  pairing car N with the Nth sorted Octopus device. Both the Octopus and Kraken
  components publish it there, so E.ON/EDF SmartFlex users are covered and a slot list
  in a different order can no longer pair a car with another car's device.
- Only wait for Octopus discovery when the Octopus component runs its automatic setup.
  With octopus_automatic off it never wires the slots, so control never turned on.
  "Cannot tell yet" also gets its own log line rather than claiming the car is on IOG.
- Handing a charger to Octopus no longer starts it. A normal release undoes a stop so
  a car is never stranded, but here Octopus decides when to charge: a GE charger
  Predbat stopped is left for Octopus, an Ohme has max charge turned off before it is
  resumed into its smart schedule, and a Zappi returns to its own mode, Eco+ in place
  of Fast.
- The control settings have no default, which also skipped get_arg()'s boolean
  conversion, so a quoted "false" or a 0 read as set. parse_control_setting()
  normalises them to None, True or False in each component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imit are set

Predbat drives an Ohme with max charge, which overrides the target set in the Ohme
app, so car_charging_battery_size and car_charging_limit are all that stop a charge.
Left at their defaults (100 kWh, 100%) the car would be charged to full. Unset
ohme_control now waits for both to be in apps.yaml and logs why; an explicit
ohme_control: true is still the user's call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…opus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pus drives follows its dispatch sensor

- switch.predbat_octopus_intelligent_charging only changes Predbat's own planning:
  Octopus goes on switching a charger that is its Intelligent device whatever the
  switch says. The device is now judged first, so turning the switch off no longer
  has Predbat fight Octopus for that charger. For a car Octopus drives, the switch
  still decides whether the charger follows the dispatches or Predbat's own plan.
- Where Octopus drives the car, the charger also runs while the car's dispatch sensor
  is on. The plan carries the dispatches but is only republished every 5 minutes and
  leaves out a dispatch Octopus has not given any energy yet, so the charger held the
  car off for the first minutes of a new dispatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While Predbat drives a charger it holds it off outside the planned windows, so a
visitor's car could not charge - and stage 2 turns control on by default. Each
component (GE, myenergi, Ohme) now publishes switch.predbat_<component>_guest_charging
beside its control. On, Predbat releases the charger as it does for read only mode, so
it runs on its own settings; how the guest charges is chosen on the charger itself.

It turns itself off when a connected car is unplugged, on chargers that can tell
(GE), and otherwise after GUEST_CHARGING_MAX_HOURS (12). It is deliberately not
persisted, so a restart puts Predbat back in charge. The guest's charging is still
counted as the car's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or Ohme

Both report whether a car is plugged in - the Zappi's plug status, the Ohme's
UNPLUGGED status - so guest charging now ends on unplug for every charger, not just
GE. A new charger_control_car_plugged() hook carries it, separate from
charger_control_connected(), so how Predbat drives an empty Zappi or Ohme is
unchanged. An unknown plug state reads as plugged in, leaving the 12 hour limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ends are judged by the clock

Found by review before opening the stage 2 PR:

- Guest charging ended on any unplug, including the owner's car being unplugged to make
  way for the guest. Only a car plugged in after the switch went on now ends it
  (empty, plugged in, empty again); a guest who plugged in first is left to the 12 hour
  limit or a manual off.
- A GE status blip (offline, unavailable, unknown) read as an unplug and ended guest
  charging. Only "available" and "idle" count as empty now, as the Zappi and Ohme
  already treat unknown states as plugged in.
- The charger followed the dispatch sensor's on/off state, which only refreshes every
  couple of minutes and so ran the charger past the end of a dispatch. The dispatch
  times on the sensor are now judged against the clock, in both the Octopus and the
  Kraken formats, falling back to the state for a sensor with no times.
- A toggle on the guest switch now flips it rather than turning it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rger

A dispatch sensor that does not say which device Octopus drives (the Octopus Energy
integration, for one) leaves the charger uncontrolled for good, and was only an Info
line. It is now a warning naming the component's own setting to set true. Waiting for
the Octopus component to discover its devices, which normally clears within a cycle
or two, stays Info. Each reason is logged once, and again only when it changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g a charger (#5311 review)

Only the Octopus component was waited for. After a restart a Kraken (E.ON/EDF
SmartFlex) user's charger could be driven before Kraken had wired
octopus_intelligent_slot - stopping a GE charger mid-dispatch, which the hand-over on
the next cycle then left stopped. Kraken wires its devices in its first successful run,
from cache or fresh discovery, so until it has started the charger is left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it, and stop waiting on discovery after 15 minutes (#5311 review)

- Cannot tell whether Octopus drives a charger: a charger Predbat had stopped
  was let go without being started, as if Octopus were taking it over. With
  nobody known to take it over, a GE charger was left stopped indefinitely.
  It is now released as usual; the non-starting hand-over is kept for a
  charger Octopus is known to drive.
- Waiting for Octopus or Kraken discovery is bounded at 15 minutes. A Kraken
  component whose first run never succeeds (a failed login) otherwise left
  every unwired car's charger uncontrolled for good. The log line now names
  both components.
- The apps.yaml default's literal "re:" string, before its regex matches, is
  no longer read as a dispatch sensor - which on every restart warned users
  with no Intelligent sensor to set a control override they do not need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at a discovery that never finishes as cannot tell (#5311 review)

Releasing during discovery started a charge Predbat had stopped whenever the
Octopus or Kraken component restarted, and driving the charger once the wait
ran out could fight Kraken if it was the one driving it. While discovery is
under way the charger is now left as it is and still held, so it is settled
either way once discovery finishes. After 15 minutes Predbat still cannot
tell, so it warns once and hands back a charger it holds, as for a dispatch
sensor that does not say.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r is known (#5311 review)

The wait's start was only cleared when discovery was asked about with nothing
discovering, which stops happening once every car's driver is known. A later
component restart could then find the old start and count the wait as
already over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its own schedule stays the car plan otherwise

Main's #5401 now takes the car plan from Ohme's own schedule when Predbat is
not controlling the charger, so a default user already gets a plan that matches
what the charger will do. Turning control on by default would override that
schedule - one the user may have set up deliberately - with max charge, which
also overrides the Ohme app's target. ohme_control goes back to a false default;
GE and Zappi keep their automatic defaults. The size and limit guard for an
unset ohme_control goes, as there is no unset default any more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alone when Octopus drives the car, unless asked to follow it

When the car itself is the Octopus Intelligent device, the car starts and stops
its own charge. Predbat now leaves the charger alone by default, handing over a
charger it held without starting a charge, as it does when Octopus drives the
charger. The new expert-mode switch, default off, has Predbat drive the charger
to the car's dispatches instead, so the car cannot also charge on its own
timers.

The Ohme follows the same switch: with it on, ohme_control can run while
Octopus drives the car, where #5405 otherwise stands it down. A change of the
switch is picked up on the next Ohme poll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llowing Predbat's own plan with Intelligent charging off, and log only real Ohme changes (#5311 review)

- Octopus driving the car means nobody drives the charger, so a charger
  Predbat had stopped is released as usual (GE started, Zappi back to its own
  mode including Fast) rather than handed over without starting, which left it
  stopped through every dispatch.
- With switch.predbat_octopus_intelligent_charging off Predbat plans the car
  itself, so it still drives the charger to that plan whatever the new switch
  says.
- An Ohme poll that sees only the new switch change logs that change, and only
  re-decides control while Octopus drives another device - not the Octopus
  tariff change it used to report.
- The log points at expert mode for the switch, and the class docstring says
  the charger is left alone by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ging off while Octopus drives the car (#5311 review)

The shared charger rule drives a charger for a car Octopus drives when
switch.predbat_octopus_intelligent_charging is off, as Predbat then plans the
car itself; the Ohme stood control down there regardless. It now follows the
same rule, and re-decides when either switch changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…harger value as cannot tell (local review)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@chalfontchubby chalfontchubby added enhancement New feature or request refactor labels Oct 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Ohme’s live Intelligent handoff uses the unsafe release order, and persistence failures can be silently ignored.

2 open findings
What changed in this PR

Introduces shared Predbat-led EV charger control for GivEnergy, Ohme, and myenergi, including automatic activation, Intelligent dispatch handling, and guest charging.

Changes:

  • Adds the shared CarChargerControl mixin.
  • Migrates three charger integrations and adds extensive tests.
  • Updates configuration and user documentation.
File Description
apps/​predbat/​car_charger_control.py Adds shared charger-control logic.
apps/​predbat/​gecloud.py Migrates GivEnergy charger control.
apps/​predbat/​myenergi.py Migrates Zappi charger control.
apps/​predbat/​ohme.py Migrates Ohme control and Intelligent handling.
apps/​predbat/​components.py Adds tri-state control configuration.
apps/​predbat/​config.py Adds the follows-car switch.
apps/​predbat/​unit_test.py Registers shared-control tests.
apps/​predbat/​tests/​test_car_charger_control.py Tests the shared mixin.
apps/​predbat/​tests/​test_ge_cloud.py Expands GivEnergy control tests.
apps/​predbat/​tests/​test_myenergi.py Expands Zappi control tests.
apps/​predbat/​tests/​test_ohme.py Expands Ohme control tests.
docs/​apps-yaml.md Documents automatic-control settings.
docs/​car-charging.md Documents Intelligent and guest charging.
docs/​components.md Updates component configuration guidance.
tools/​debug-journal.md Updates myenergi diagnostic notes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/predbat/car_charger_control.py Outdated
Comment thread apps/predbat/ohme.py Outdated
chalfontchubby and others added 4 commits October 8, 2026 19:50
… when Storage refuses to save the control switch (#5448 review)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…charge Predbat started (#5448 review)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…l review)

The discovery wait was one clock shared by every car, and drive_one reset it
whenever any car's driver was known. With two cars - one wired, one still
waiting on a Kraken login that keeps failing - the wired car reset the clock
every cycle, so the waiting car never reached "cannot tell" and its charger
was held as it was indefinitely, with no warning. The clock is now kept per
car, and still cleared for every car once discovery has finished.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A partially available multi-car plan can incorrectly stop a charger whose plan has not been published.

2 open findings
2 resolved since last review

🧠 Review effort: Balanced

Comment thread apps/predbat/car_charger_control.py
Comment thread tools/debug-journal.md Outdated
chalfontchubby and others added 15 commits October 11, 2026 12:31
…istence clause (#5448 review)

The myenergi rename to charger_control_active caught the Sunsynk/Deye
sentence too; those components still persist control_active.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed (#5448 review)

charger_control_refresh_windows() only waited for any car's plan, so with
car 0's slot sensor published and car 1's not, car 1 read as an empty plan
and its charger was stopped. A car missing from charger_control_windows is
now unknown: its charger is left as it is until its plan appears or an
Octopus dispatch says to charge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (local review)

The unknown-plan skip came before the drift and last-state checks, so a
charger a dispatch had started for a car with no published plan was frozen
on once the dispatch ended. The skip now applies only to a charger Predbat
does not hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t (local review)

A held charger whose car's planned attribute went missing for a cycle was
driven from an empty window list and stopped mid-charge. The windows are
absolute times, so the last ones read are carried forward instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…review)

update_slot_mode() handed the charger back outside any handler, so an
ApiException from Ohme skipped the session fetch, publish and slot wiring
for every poll until Ohme accepted the command. It is now a warning, as in
the control tick; the charger stays held and the next poll retries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne through (local review)

The mode was snapshotted ahead of set_mode, so a refused command left a
snapshot for a Zappi Predbat never held. Release paths only run for held
Zappis, so it could outlive the moment and be restored much later in place
of what the user had set by then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
publish_car_plan() built one plan list for every car, and handed the same
list object to each slot sensor, so with two or more cars every sensor's
'planned' attribute held the windows of all of them. Pre-existing on main,
but the shared charger control drives charger N from car N's 'planned', so
a charger would start in another car's window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d has gone through (local review)"

This reverts commit 3ff61b7. Snapshotting after set_mode traded one hazard
for a worse one: a command that timed out but was applied is retried with
the Zappi already Stopped, and Stopped was then saved as the user's mode, so
a later release left the car unable to charge. Saving ahead of the command
gets the mode the user really had; a snapshot left by a refused command is
the lesser risk, and a full release still clears it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cal review)

A saved Stopped is most likely Predbat's own hold: after a restart, or a
Stop that timed out but was applied, the first snapshot is taken with the
Zappi already Stopped. Restoring it left the car unable to charge, the very
outcome a release exists to prevent. It now falls back to Eco+, as for no
saved mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict in apps/predbat/ohme.py (OhmeAPI.__init__): main's #5443 added
slot_source/slot_source_applied (Octopus dispatch sensor read beside Ohme's
planned slots); this branch added follows_car (Predbat drives the charger
while Octopus drives the car). Independent state - kept both. The rest of
update_slot_mode() and run() auto-merged with both changes intact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests

The tests main added in #5443 read OhmeAPI.control_active, which this branch
renamed to charger_control_active when control moved into the shared
CarChargerControl mixin. Only the attribute name changes; the assertions
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… an Ohme claim

Since #5443 the Octopus component keeps wiring its whole dispatch-sensor list
into octopus_intelligent_slot while Ohme holds car_slot_owner (the claim now
covers only the ready time and charge limit). The car_slot_owner shortcut in
charger_control_octopus_drives_charger()/_drives_car() predates that and
applied to every car, so with an Ohme on car 0 and a second car whose
Intelligent device is the car itself, a Zappi or GE EVC on car 1 was left to
Octopus: follows_car ignored, and a held charger handed over stopped.

The sensor's own is_charger now decides; the claim only stands in when the
sensor does not say (the Ohme's own slot sensor). drives_car no longer reads
an "unknown" is_charger as "the car". Regression test fails on the merge
without this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he merge

The previous commit let car 0's own dispatch sensor override an Ohme
car_slot_owner claim. That changed behaviour the merge never touched: with
ohme_automatic_octopus_intelligent forced on, or Octopus's device ids sorting
the car's sensor first, a charger on car 0 that used to be left to Octopus
would be released or driven. Car 0 goes back to the claim alone; only cars
after it, which had no slot at all under the claim before #5443, are judged
on their own sensor - and one whose sensor has lost its value is "cannot
tell" rather than handed to Octopus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e survives a restart

Review changes from Trefor on #5448.

ge_cloud_evc_control and myenergi_zappi_control default to false again, so an
upgrade never starts Predbat driving a charger nobody asked it to drive. Control
runs only with an explicit true, and still stands down where Octopus Intelligent
drives the charger or the car. MyEnergiAPI.automatic_set_by_user() is removed.

The mode a Zappi had before Predbat took over is now saved to storage and
restored on startup, so a restart no longer snapshots Predbat's own Stopped as
the mode to release to. With that fixed, a saved Stopped is restored like any
other mode, on release and on the hand-over to Octopus (which still never uses
Fast). Modes left in storage are dropped when control is off at startup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008 springfall2008 changed the title Predbat-led EV charger control: shared mixin, and on automatically for GE, Ohme and Zappi (folds #5284 + #5311) Predbat-led EV charger control: shared mixin, Octopus Intelligent rule and guest charging for GE, Ohme and Zappi (folds #5284 + #5311) Oct 12, 2026
@springfall2008
springfall2008 merged commit c000b53 into main Oct 12, 2026
2 checks passed
@springfall2008
springfall2008 deleted the feat/charger-control branch October 12, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants