Skip to content

fix(solis): don't let an early-armed window cut off the one running in TOU V2 slot 1 (#6210) - #6213

Merged
springfall2008 merged 4 commits into
mainfrom
fix/solis-v2-slot1-direction-collision-6210
Nov 15, 2026
Merged

springfall2008 merged 4 commits into
mainfrom
fix/solis-v2-slot1-direction-collision-6210

Conversation

@springfall2008

@springfall2008 springfall2008 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Fixes #6210.

Problem

A Solis TOU V2 inverter keeps only one of a slot's charge and discharge enables on. Writing discharge slot 1 enable (CID 5922) turns charge slot 1 enable (CID 5916) off, and the reverse.

Predbat binds both its charge and export controls to slot 1 (charge_slot1_* / discharge_slot1_* in automatic_config()). execute.py arms the next window up to set_window_minutes (30 by default) before it starts, and SolisCloud has has_discharge_enable_time. So an export armed during a charge switched the charge off. A charge armed during an export would switch the export off in the same way.

Then the 5-minute in-window re-read made it worse. It refreshes the register cache but not the schedule Predbat asked for, so each re-read found the dropped enable and wrote it back. read_and_write_cid() verifies only the CID it wrote, so it never noticed the partner enable dropping. The two enables flipped every 5 minutes until one window was gone.

Fix

Pass 2 of the V2 path in write_time_windows_if_changed() now leaves one direction of a slot unwritten while Predbat asks for both:

  • A running window keeps the slot. Its end minute counts as over, although time_in_window() includes it, so the next window takes over on the hand-over minute.
  • Otherwise the window that starts first gets the slot, counting across midnight.
  • If both are running, the one that started later wins. That only happens when the plan has moved a window onto the other, so the other is what it left behind. The charge wins an exact tie.

The logic is in the new slot_direction_to_defer(), slot_window_wait() and minutes_after(), plus SolisAPI.defer_slot_direction(), which logs the hold-back once per change.

What stays the same

  • Predbat's view of both windows. The slot entities are published from charge_discharge_time_windows (what Predbat asked for), and the write works on a deep copy. So adjust_force_export() / adjust_charge_window() still see their own request and don't re-arm every cycle.
  • No new state. slot_direction_deferred only stops the log line repeating. A window moved while held back is written at its new times when it takes the slot. After a restart, the first decode shows the held-back window as off; Predbat re-arms it and it is held back again.
  • Other inverter paths. The V1 path (one CID 103 string) and the slot-enable switch handlers are unchanged. The switch handlers only edit the schedule, so every write still goes through Pass 2.

Cost

When one window hands over to the next, the incoming window's enable, time, SOC and current are written on the hand-over cycle rather than up to 30 minutes ahead. That adds about a minute of cloud writes to the start of that window.

Not in this PR

  • Moving the export to discharge slot 2, which would avoid the collision outright (Fox already keeps charge and discharge in separate scheduler groups). It is safe only if the exclusion is "one direction per slot index" in firmware. If instead SolisCloud rewrites a shared enable register (Modbus 43707, unverified), slot 2 would be knocked out too. It also means reworking several slot-1 assumptions: the current, slot1_active, is_holding_in_charge_slot and the in-window re-read. It needs a hardware test first.
  • A warning when the partner enable drops after a write, which the issue suggested. With the hold-back in place Predbat no longer causes the drop.

Tests

New tests in apps/predbat/tests/test_solis.py. Each is run twice: once with an export held back behind a running charge (the reported case), and once with a charge held back behind a running export.

Test What it checks
held_window_waits Nothing is written for the held-back window, and a second cycle writes nothing either. Both windows stay unchanged in the schedule and the published slot entities.
held_window_takes_slot_when_running_ends On the hand-over minute the held-back window takes the slot, and the ended window isn't written back.
held_window_waits_after_restart Decode from the registers, re-arm through the slot controls, held back again.
held_window_moves_later Keeps waiting, is logged at its new times, and is written at its new times.
held_window_moves_to_now Moved to start now, it takes the slot straight away, and nothing flips back.
held_window_removed Nothing is written and no hold-back state is left; re-armed, it is held back and logged again.

sooner_window_takes_slot covers the case where neither window is running, across midnight and in both directions.

test_run_v2_hold_back_through_re_reads (both directions) tests the whole loop. It drives run() once a minute, from the held-back window being armed until after the hand-over, against a simulated inverter that keeps only one of slot 1's enables on. The real write_time_windows_if_changed is used, and the 5-minute in-window re-reads and the hourly poll all read from the simulated inverter (7 slot polls in total). Every minute it checks two things: the running window is still on at the inverter, and the published slot entities, which Predbat reads its windows back from, still show both windows as Predbat asked. Without the hold-back it fails on the first cycle in both directions.

Mutation checks:

  • Removing the hold-back fails every new test.
  • "Charge wins a tie" fails the held-export version of moves_to_now, and "export wins a tie" fails the held-charge version.
  • Not clearing the hold-back state fails held_window_removed.

./run_all --test solis and pre-commit pass. ./run_all --quick passed on the core change, before the final tie-break and log edits.

Workaround until this ships

Turn off switch.predbat_inverter_set_charge_before. That sets set_window_minutes to 0, so windows are armed only once they start. The cost is a later start for every window, on every inverter.

🤖 Generated with Claude Code

…n TOU V2 slot 1 (#6210)

A TOU V2 inverter keeps only one of a slot's charge and discharge enables
on: writing one turns the other off. Predbat binds both its charge and its
export controls to slot 1 and arms the next window set_window_minutes
before it starts, so an export armed during a charge (or a charge armed
during an export) switched the running window off. The 5-minute in-window
re-read then found the dropped enable and wrote it back, and the two
flipped every five minutes until one window was gone.

Pass 2 of the V2 write now leaves a slot's other direction unwritten while
both are asked for. The slot goes to the running window (its end minute
counts as over, so the next one takes over on the hand-over minute), else
to the one that starts first; when both are running, the one that started
later wins. The hold-back keeps no state: the schedule Predbat sees is
unchanged, a window moved while held back is written at its new times,
and after a restart Predbat re-arms it and it is held back again.

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

Runs run() every minute from the held-back window being armed until after
the hand-over, against a simulated inverter that keeps only one of slot 1's
enables on, with the 5-minute in-window re-read and the hourly poll reading
from it. Checks every minute that the running window stays on at the
inverter and that the published slot entities Predbat reads its windows back
from still show both windows as it asked. Run for a held-back export and a
held-back charge; without the hold-back both fail on the first cycle.

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

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

Reviewed at 4728320 (PR head). 1 finding inline, 1 in this body.

The core change holds up. The deferral sits in the one Pass 2 path every TOU V2 slot-enable write goes through, and Predbat's own schedule is left alone: decode_time_windows_v2() only runs on the first cycle or after a TOU-mode change, so the 5-minute in-window re-read refreshes the register cache without overwriting the ask, which is what stops execute re-arming the held-back window every cycle. now_utc_exact really is local time (ComponentBase returns datetime.now(self.local_tz)), matching the slot times. The four new module-level helpers are pure and the end-to-end run() test drives the real write path against a simulated inverter with the reported exclusion, so the flip-flop is covered where it actually happened.

Also checked and clean: the V1 branch and the slot switch handlers keep their own paths and every V2 enable write still funnels through Pass 2; the read-only handover disables enables through write_read_only_reset_cid, so the deferral cannot block it; reset_charge_windows_if_needed() only clears slots 2-6, so slot 1 is the only slot that normally sees both directions enabled; the new tuple-keyed slot_direction_deferred lives on the component, which DEBUG_EXCLUDE_LIST keeps out of the debug dump; the new tests pin the wall clock, so they are not time-of-day flaky; and no existing test pairs both V2 enables with a live window, so nothing else becomes clock-dependent.

docs/components.md:1534 - "Important notes (solis)" has no note on this

The "Important notes (solis)" list already records quirks of exactly this shape (the firmware note and the timezone note just below it), and this change is visible to users in two ways. An export or charge that used to be programmed on the inverter up to set_window_minutes (30 by default) early is now programmed on the hand-over cycle instead, so the inverter dashboard no longer shows the next window ahead of time while a window is running in that slot; and the new Solis API: Holding back ... log line will be pasted into support threads. One short paragraph saying TOU V2 keeps only one of a slot's charge and discharge enables, that Predbat therefore gives slot 1 to the window that is running (or starts first) and programmes the other when the running one ends, and what the Holding back line means, would close the gap - and would stop the later arming being reported as a regression.

Comment thread apps/predbat/solis.py Resolved
@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Nov 15, 2026
CI and others added 2 commits November 15, 2026 19:41
… invariant (#6210)

Review feedback on #6213. The components docs now say that TOU V2 keeps
one direction per slot, that the next window is programmed on the
hand-over while one is running in slot 1, and what the "Holding back" log
line means. slot_direction_to_defer() now states the invariant its
both-running branch relies on (the plan gives each slot of time a single
action; the state is only seen mid-execute, when a charge moved to now is
armed just before the export it replaces is withdrawn) instead of implying
it is checked.

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

Copy link
Copy Markdown
Owner Author

Reply from Claude Code, working with the maintainer.

On the review's body finding (docs/components.md, "Important notes (solis)" has no note on this): added in f11d219. A new bullet, One direction per slot on V2 firmware, explains four things:

  • A V2 inverter keeps only one of a slot's charge and discharge enables on.
  • While a window is running in slot 1, the next one is programmed on the hand-over rather than up to 30 minutes early, at the cost of about a minute of cloud writes.
  • Otherwise slot 1 goes to whichever window starts first.
  • The Solis API: Holding back ... log line is expected, and the plan and slot controls still show both windows.

The same push merges origin/main, which brings in the v9.8.0 version bump. Pre-commit and ./run_all --test solis pass.

@springfall2008
springfall2008 enabled auto-merge (squash) November 15, 2026 19:43
@springfall2008
springfall2008 merged commit 1a732e0 into main Nov 15, 2026
6 checks passed
@springfall2008
springfall2008 deleted the fix/solis-v2-slot1-direction-collision-6210 branch November 15, 2026 19:51
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.

Solis Cloud TOU V2: arming the next export in discharge slot 1 turns off the active charge slot 1, so the battery discharges mid-charge

1 participant