Stop posting the write-only enable flags back at the inverter - #275
Merged
Poshy163 merged 2 commits intoAug 23, 2026
Merged
Conversation
Both enable flags at 0 means one of two things and the OpenAPI cannot say which: a non-timed working mode is running, or both timers are simply switched off. Treating it as the first locked every time-based control, the two switches that set those flags included — so a system in the second state had no way back to a timed mode from Home Assistant at all. A tester on CharlesGillanders#267 hit exactly that: Time-Based Control selected in the app, both schedule toggles off, every control unavailable, and the services refusing with a message about a self-consumption mode he was not in. Scheduled Charging and Scheduled Discharging now stay available in that state, and turning one on goes out immediately rather than becoming a draft — Apply is unavailable there too, so a staged flag could never be sent. Raising a flag is the one write that is safe under either reading: a self-consumption inverter ignores it, and the next poll simply locks the controls again. Everything else stays locked, turning a switch off there is still refused, and HA still will not author the 0/0 state itself. The refusals now name both possibilities instead of asserting the one HA cannot verify, and point at the switches that undo it.
Poshy163
marked this pull request as ready for review
August 23, 2026 10:01
Collaborator
Author
|
@CharlesGillanders need this to go for a b3 release |
CharlesGillanders
requested review from
CharlesGillanders
and removed request for
CharlesGillanders
August 23, 2026 11:20
Owner
Something odd happening with GitHub mobile, no request for a review of this and adding myself as a reviewer doesn't seem to give me an option to review?!? Can you please request a review and I can do so? |
Collaborator
Author
|
Cool, done, see how that goes |
CharlesGillanders
approved these changes
Aug 23, 2026
dragon2611 probed setTimeChargeBySn directly on CharlesGillanders#267 and found what the two enable flags actually do: 1/0 schedule active, scheduled discharging off 1/1 both schedules enabled 0/1 scheduled discharging only 0/0 switches the inverter to self-consumption and that getTimeChargeBySn answers 0 for both however the inverter is set. He wrote 1 and read back 0 half a minute later. They are write-only. We were reading them, keeping them in the snapshot, and sending them back on every write. On his system that meant every schedule change Home Assistant made posted 0/0 and asked the inverter to leave timed control. Then the lockout read the same zeros and told him he was in self-consumption, which by then he was. The only reason it was not worse is the bug that hid it: with the read always 0/0 the lockout refused every write, so it jammed far more often than it fired. Removing either half alone would have made things worse, so both go here. The read is no longer part of the snapshot. Every write now sends a value that came from the user - this request first, then what was last recorded - and refuses outright when neither has an answer, rather than picking a working mode on their behalf. The two switches are the only place that answer can live, so they restore their published state on startup and hand it back, and they read unknown rather than off until they have one. A recorded 0/0 is a real request, so it still locks the time-based controls and still leaves the switches available to undo it. Backup mode is untouched: there the flags are ordinary read-write fields and behave as before. Also from his probes: an empty list answers 6001 and a missing one 10001, so the both-lists rule stays, and the error now names the workaround - give the side you do not want a period and turn its switch off.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #274, from testing on #267. Two commits: the second is the important one.
What #267 turned up
@dragon2611 probed
setTimeChargeBySndirectly and established what the two enable flags actually do:1 / 01 / 10 / 10 / 0And that
getTimeChargeBySnanswers0for both however the inverter is set — he wrote1and read back0half a minute later, across a schedule rewrite, a switch to Self-Consumption and a switch back to Time-Based Control. They are write-only.The bug that follows
mainreads those flags, keeps them in the snapshot, and sends them back on every write. On a system whose read is always0/0that means every schedule change Home Assistant makes posts0/0and asks the inverter to leave timed control. The lockout then reads the same zeros and reports a self-consumption mode — which by then is true, because we put it there.The only thing that kept it from being worse is the bug that hid it: with the read always
0/0,is_time_based_control_active()is always False, so the lockout refused every write. It jammed far more often than it fired. Removing either half on its own makes things worse, so both are fixed here.The fix
offuntil they have one.0/0is a real request — it is how the API is told to run self-consumption — so it still locks the time-based controls, and the switches stay available to undo it (that is the first commit).gridCharge/ctrDisare ordinary read-write fields, live-probed in Move scheduling onto the periodic API, with staged edits and Apply #274, and behave exactly as before.Also confirmed from his probes: an empty period list answers
6001and a missing one10001, so the both-lists rule stands — and the error now names the workaround, which is to give the side you don't want a period and turn its switch off.Consequence worth flagging
setbatterychargecarries only the charge flag, so on periodic systems both switches must be set once before any service call is accepted. Documented inservices.yamland in the Predbat section of the README.Tests
554 → 568, 100% coverage, ruff clean.
TestWriteOnlyEnableFlagspins the regression directly: a system answering0/0while running a schedule gets1/0posted back, not the zeros. Plus a switch change beating the stored answer, refusal on unknown and half-known state, a flag-only change still reaching the API, and the normaliser stripping the read.TestSwitchStateSurvivesRestartcovers restoration.