Skip to content

fix(axle): decide axle_control read-only from the event window, not the lagging sensor state - #6525

Draft
springfall2008 wants to merge 2 commits into
mainfrom
fix/axle-read-only-from-event-window-6522
Draft

springfall2008 wants to merge 2 commits into
mainfrom
fix/axle-read-only-from-event-window-6522

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

This is an automated draft PR generated from issue #6522 — a maintainer should review it before merging.

Fixes #6522

Summary

With axle_control: true, fetch_config_options() decides read-only from fetch_axle_active(). Until now that function read the on/off state of binary_sensor.predbat_axle_event. Only the Axle component's own 60-second loop republishes that state, and the loop is not aligned to the plan cycle. So the cycle that runs at an event's start read off and wrote its own charge/export commands while Axle was taking over the inverter. On SolaX, a retried Disabled from those writes cancelled Axle's export. The cycle at the end had the opposite problem: it stayed Read-Only (Axle) for one cycle too many.

fetch_axle_active() now compares the window in the sensor's event_current attribute with now_utc. Those times are published well before the event starts. The comparison uses a new helper, axle_event_in_window(), which publish_axle_event() now uses as well, so the two cannot disagree about what "active" means. The on/off state is now only a fallback, used when the sensor has no event_current list or its times can't be parsed (for example a hand-configured axle_session sensor).

now_utc is the plan cycle's clock, rounded down to the 5-minute step. So the cycle at the event's start time is read-only, and the cycle at its end time is not. Sigenergy's _axle_has_control() calls the same helper and gets the same change. Its answer can now only flip earlier than before, never later, because publish_axle_event() was already judging against that same now_utc.

I also added a line to the Axle notes in docs/components.md saying read-only follows the event times.

Testing

  • tools/triage_test.sh axle with axle.py stashed (git stash push -u; confirmed only the test and docs were left modified): fails. 38 passed, 2 failed. The two new sub-tests report:
    • fetch_axle_active should be True at the event start even though the published state is still 'off'
    • ... should be False at the event end even though the published state is still 'on'
    • the plan cycle at the event start should be read-only, got set_read_only False ...
    • the plan cycle at the event end should not be read-only, got set_read_only True ...
  • With the fix restored: passes, 40/40.
  • New sub-tests:
    • active_from_event_window publishes the sensor through the real publish_axle_event() one minute before the start and one minute before the end, then moves the clock to the boundary. It also covers the state fallback, both with no event_current and with unparseable times.
    • read_only_at_event_start drives the real fetch_config_options() on a PredBat instance and checks set_read_only / set_read_only_axle at the start and end cycles. This closes the gap the triage noted: nothing exercised that branch before.
  • tools/triage_test.sh sigenergy: passes, covering the other caller.
  • ./run_pre_commit: all hooks pass, quick suite passes in 4 workers.
  • Not replayed: the triage noted that triage_replay.py recalculates plans and does not exercise control writes, which is what this changes.

Notes

  • Blast radius: GitNexus impact rates fetch_axle_active HIGH. It has two direct callers: fetch_config_options(), on the main timed plan loop, and Sigenergy's _axle_has_control(). The signature is unchanged; only when the answer flips moves to the boundary. publish_axle_event rates LOW (one caller, run()). Its behaviour is unchanged, including the parse-failure warning.
  • Managed mode: event_current is the half-hour price-curve slot active at the last fetch. The window rule is the same one publish_axle_event() already applied, so read-only in managed mode follows the same slots as before, without the publish lag.
  • Not done, needs a maintainer decision: the reporter's suggestion to go read-only a minute or two before start_time (a lead-in). With this change, the cycle at the start is already read-only. A lead-in would also cover a cycle that starts a few seconds early or writes slowly, but it changes behaviour, so I left it out as the triage recommended.
  • Docs points from the issue, left out: both are outside this fix.
    • The SolaX scripts in docs/inverter-setup.md set autorepeat_duration 28800 on Disabled too.
    • docs/energy-rates.md still lists Axle as Fox/GivEnergy/SigEnergy only. Axle's current SolaX support can't be verified from this repo.
  • The GitNexus index was at ccc7f2be (current main) when the impact checks ran.

🤖 Generated with Claude Code

…he lagging sensor state

fetch_axle_active() read binary_sensor.predbat_axle_event's on/off state, which only the
Axle component's own 60-second loop republishes. That loop is not aligned to the plan cycle,
so the cycle at an event's start read 'off' and wrote its own commands while Axle took over
the inverter, and the cycle at the end stayed read-only. It now compares the event_current
window with now_utc, using the same helper publish_axle_event() uses; the state is only a
fallback when the window is missing or unreadable.

Fixes #6522

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008 springfall2008 self-assigned this Dec 4, 2026
@springfall2008 springfall2008 added BOT_REVIEW Trigger an autotriage BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push BOT_PR_OPENED Bot PR flow opened a draft PR for this ticket labels Dec 4, 2026

@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.

Verdict: 🟡 Amber - Recommend addressing the feedback, then approval

One docs sentence overstates what happens in managed mode; the code change itself is sound and the new sub-tests do exercise it.

Reviewed head 2033b584: 1 finding posted inline, 0 in the body.

What I checked: the shared helper is the same rule the publisher already used, so the two cannot disagree; set_read_only now clears/sets from the window before fetch_sensor_data(), and execute_plan() skips every inverter write (and reset_inverter() is guarded) while it is set, so starting one cycle earlier only removes writes. The state fallback still covers a sensor with no event_current list or unparseable times. In _test_axle_read_only_at_event_start the first assertion depends on the window decision (without the fix fetch_axle_active() reads the still-off state), so the test is not vacuous.

Comment thread docs/components.md Outdated
- Alert notification sent when Predbat adds a new Axle VPP event to the Predbat plan
- When **axle_control** is enabled (set to `true` in `apps.yaml`), Predbat will enter read-only mode during active VPP events (default is `false`)
- Read-only mode prevents Predbat from controlling the inverter while VPP events are running
- Predbat judges whether an event is running from its start and end times in `event_current`, so read-only starts on the plan cycle at the event's start time and ends on the cycle at its end time, rather than waiting for the binary sensor's state to change

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.

This sentence is true in BYOK mode but not in managed mode, where event_current can only name the slot that was active at the last price-curve fetch.

In managed mode _process_price_curve() resets current_event and fills it only from the slot satisfying start <= now < end at fetch time, and run() refetches at most every 10 minutes. So at a half-hour slot boundary the plan cycle reads the slot that has just ended (now < end_time is false) or an empty event_current, fetch_axle_active() returns False, and read-only starts at the next price-curve fetch - up to 10 minutes into the slot. That is the same lag this PR removes for BYOK. (The end half of the sentence does hold: the cycle at a slot's end reads the same slot and turns read-only off.)

Verified by reading _process_price_curve(), run()'s fetch_due check and fetch_axle_active(). The PR body's managed-mode note ("follows the same slots as before, without the publish lag") is accurate - it is only this blanket sentence that promises more.

Either qualify the sentence for managed mode (for example "in BYOK mode", or "once the price-curve fetch has published the slot"), or have managed mode publish the active-or-next slot so it agrees with the sentence; a managed-mode sub-test would pin whichever is intended.

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 reply from the triage bot.

Fixed in 63706ff by qualifying the sentence. I didn't change managed mode itself.

I checked the claim against the code. _process_price_curve() resets current_event and fills it only from a slot with start <= now < end at fetch time, and run() fetches at most every 10 minutes. At a half-hour boundary, fetch_axle_active() therefore still reads the slot that has just ended and returns False until the next fetch.

The Axle notes in docs/components.md now say:

  • With an API key (BYOK), read-only starts on the plan cycle at the event's start time and ends on the cycle at its end time.
  • In managed mode, event_current holds only the slot that was active at the last fetch. Read-only still ends on the cycle at that slot's end. For a new slot it starts only once a fetch has published that slot, which can be up to 10 minutes into it.

Why I didn't change managed mode: publishing "the active or next slot" would not fix this on its own. A fetch at 10:25 still finds 10:00-10:30 active. Closing the gap would mean publishing several upcoming slots and changing what event_current means for managed sites. That is a behaviour change beyond this PR, so I'm leaving it for a maintainer. I didn't add a managed-mode sub-test either, because it would only lock in the lag. If a maintainer decides managed mode should match BYOK, a test should come with that change.

@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Dec 4, 2026
In managed mode event_current only holds the slot active at the last 10-minute price-curve fetch, so read-only for a new slot starts at the next fetch rather than at the slot boundary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008 springfall2008 removed the BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push label Dec 4, 2026

This branch has not been deployed

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

Labels

BOT_PR_OPENED Bot PR flow opened a draft PR for this ticket

Projects

None yet

2 participants