Repository navigation
fix(axle): decide axle_control read-only from the event window, not the lagging sensor state - #6525
springfall2008 wants to merge 2 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
| - 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_currentholds 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.
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>
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 fromfetch_axle_active(). Until now that function read the on/off state ofbinary_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 readoffand wrote its own charge/export commands while Axle was taking over the inverter. On SolaX, a retriedDisabledfrom those writes cancelled Axle's export. The cycle at the end had the opposite problem: it stayedRead-Only (Axle)for one cycle too many.fetch_axle_active()now compares the window in the sensor'sevent_currentattribute withnow_utc. Those times are published well before the event starts. The comparison uses a new helper,axle_event_in_window(), whichpublish_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 noevent_currentlist or its times can't be parsed (for example a hand-configuredaxle_sessionsensor).now_utcis 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, becausepublish_axle_event()was already judging against that samenow_utc.I also added a line to the Axle notes in
docs/components.mdsaying read-only follows the event times.Testing
tools/triage_test.sh axlewithaxle.pystashed (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 ...active_from_event_windowpublishes the sensor through the realpublish_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 noevent_currentand with unparseable times.read_only_at_event_startdrives the realfetch_config_options()on aPredBatinstance and checksset_read_only/set_read_only_axleat 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.triage_replay.pyrecalculates plans and does not exercise control writes, which is what this changes.Notes
impactratesfetch_axle_activeHIGH. It has two direct callers:fetch_config_options(), on the maintimedplan loop, and Sigenergy's_axle_has_control(). The signature is unchanged; only when the answer flips moves to the boundary.publish_axle_eventrates LOW (one caller,run()). Its behaviour is unchanged, including the parse-failure warning.event_currentis the half-hour price-curve slot active at the last fetch. The window rule is the same onepublish_axle_event()already applied, so read-only in managed mode follows the same slots as before, without the publish lag.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/inverter-setup.mdsetautorepeat_duration28800 onDisabledtoo.docs/energy-rates.mdstill lists Axle as Fox/GivEnergy/SigEnergy only. Axle's current SolaX support can't be verified from this repo.ccc7f2be(current main) when the impact checks ran.🤖 Generated with Claude Code