Files
goodwe-addon/goodwe_controller/DECISIONS/EV-20-solar-mode.md
T
Claude d17f15b33c
checks / unit (pull_request) Successful in 44m16s
infra-pin / fresh (pull_request) Successful in 2s
EV-20 SPIKE-06: stuck start cap backs off instead of holding
Under one stuck verdict Solar still makes at most MAX_TRIES starts and gives
one CHARGER_REFUSED; then one more start after 15 min and one every 30 min
(each by the start rule and the write clock), so a fault that clears is
found again. The episode ends when the reading follows a start, on a press
of Solar, Off, Manual, shadow or a stop. Rows: cap, backoff times,
recovery, press, episode end; T28 (b) no flapping. DOCS and DECISIONS.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
2026-11-23 19:01:36 +01:00

147 lines
8.8 KiB
Markdown

# EV-20 — Solar mode: spare sun to the car (charging only)
Part 1 of the split of cancelled EV-05 (owner 2026-11-19). The design is
`reports/EV-01-design-report.md` sections 2-5 and decision 5; the rules are
EV-20's brief (Expected 1-15, D1-D4). EV-21 (the car cut first for the peak)
and EV-22 (another writer's phase change) are separate cards. This record keeps
what the code had to decide.
## Where it lives
`app/carmode.py`: `SolarPlan` (pure: the spare, the room, the dwells, the auto
phases) and `SolarWriter`, a subclass of EV-04's `ManualWriter`. It writes only
through `ManualWriter._write` and `_advance`, so the two write call sites stay
exactly two (test_ev04 / test_ev20 T55). `app/ctl_car.py` builds the inputs
(`car_spare_w`, `car_room_w`), runs the step beside the cycle, the release at
shutdown and today's solar kWh.
## One rule for every write (EV-05 review rounds 2-9)
EV-05 needed nine review rounds, mostly on exits and other writers. EV-20 keeps
one small set of facts and derives every path from them:
- `sent_a`: the current Solar last decided, recorded BEFORE the write goes out;
`taken`: the charger confirmed it. A write cancelled while it waits is never
trusted (round 2, T37).
- A value is written when Solar DECIDES a new one. One the charger did not take
is tried again after 60 s, three times, then the gave-up row and one
CHARGER_REFUSED warning (EV-04's rule; round 2's Critical, T36). A new 0 A
gets its own three tries and never waits.
- A read-back that shows what Solar sent confirms it, however late (round 9's
second Major, T48).
- A read-back that differs from what Solar sent is never written over:
EV-04's `_watch` judges it, and while the difference stands Solar writes
nothing in its running state. After 30 s the hold (amber row, one
CHARGER_OTHER warning) stops every write, the way-out 0 A and the shutdown's
included (N16; rounds 5-7). Only pressing Solar lifts it.
- `live`: Solar's own current may stand on the charger (a non-zero value it
sent, or a 0 A not yet confirmed). A way out (Off, Stop, shadow, a safety
stop, a charger error or stuck reading, no car, shutdown) writes 0 A only
then. So a start in shadow writes nothing, and once the way-out 0 A is
confirmed nothing more is written, shutdown included (rounds 6 and 7).
- The start-up and a charger (or Home Assistant) that comes back write 0 A
first whatever the charger shows, with the read-back references cleared, so
its own value is never "another writer" (D2; round 9's first Major, T29,
T30, T61).
## Choices the brief left open
- **Writes over an unexplained read-back stop at once**, not after 30 s: the
plan goes on, the next decision waits. A way out still writes its 0 A inside
those 30 s (T39 (b)): 0 A is the safe side.
- **The phases follow the charger.** Solar's arithmetic uses the phases the
charger reports (1 for a one-phase car); its plan adopts them whenever it is
not switching. It selects only by its own dwells (and a start from a pause in
auto, on 1 phase), never "back" over a change it did not make (D4: EV-22).
A lower current is never blocked by the 10-minute phase gap (round 8, T46).
- **An interrupted phase change ends at its 0 A.** Manual's restore of the old
current stays Manual's.
- **Pressing Solar** lifts another writer's hold and takes the charger as it
is; Solar's own value is then decided and written afresh. Choosing Solar from
another mode starts paused: 0 A, then the start rule.
- **Stale and unknown.** The spare is unknown with a meter older than
`stale_input_s` (P1's own bound may be longer), readings late past it, a
missing or NaN battery or grid figure, or a charging car whose figure is
stale, stuck or not corroborated. A paused or idle car counts as 0 W. Unknown
holds the current for `ev_pause_min`, then 0 A. A cycle that returns early for
missing or late readings still steps Solar (Manual is left as it was).
- **The guard treats a Solar car exactly as a Manual car** (Expected 8): every
alarm-path test that said "Manual" says "Manual or Solar"
(`car_controlled`). Solar's own phase change gets EV-15's grace as Manual's;
its own 0 A pause gets it from the send, at most `OWN_PAUSE_MAX_S`, and only
while the read-back still shows that 0 A (round 8's second Major).
- **D1 wording.** The card's Why says "Solar charges the car at {a} A. This
sets the peak."; STYLE.md allows a grey note and a grey row one sentence, so
they say "Solar charges the car at {a} A, which sets the peak." `{a}` is the
charger's read-back, never Manual's stored current.
- **D3 at shutdown.** In Solar the charger's 0 A goes out before the inverters'
0 W: up to three tries 5 s apart, each waiting 4 s for its read-back
(`write_current(took_s=...)`), all inside `RELEASE_WAIT_S` (15 s, also a
wall-clock bound for a charger that hangs). Not taken: one CHARGER_RELEASE
warning, the notice *Car may still be charging* after the inverters are
released, and the next start writes 0 A first (D2) and takes the notice down.
- **A charger error** sets 0 A (while owed) with one CHARGER_ERROR warning
and the card's Why; the existing grey error row shows it. No new
notification.
- **Solar kWh** is counted per cycle in Solar only: `min(car, max(0, spare -
room))` Batteries first, `min(car, max(0, spare))` Car first; never above
today's kWh; stored with its day, reset at the day's change.
- **Rollback.** An older build reads a stored `car_mode = solar` as Off
(`start_mode`) and writes nothing; no state migration.
## SPIKE-05 decisions (brief v4/v5)
- **C1.** An own 0 A that is out and not read back is kept in the store with
the mode (`car_exit_0a_pending`). A start in Off with that flag writes the
0 A (when it may write), retried by the exit rule; Off without it writes
nothing (N10). A start that will not write (shadow, control stopped) after
Manual or Solar, with the charger showing a current, writes nothing and
raises one warning, *Charger kept its current*, taken down at 0 A.
- **C5.** Each shutdown try waits 4 s for its read-back (D3 above).
- **C6.** One write clock: Solar's 30 s gate also counts from Manual's latest
non-zero write, the start included. Solar's first write after Manual is its
0 A, which is never gated.
- **C8.** A charger or HA outage ends a phase change: the return restarts the
plan paused, so nothing of the sequence resumes; only a 0 A may come before
the start rule.
- **C9.** An exit owes its 0 A while Solar's own value may stand: by its own
bookkeeping (a 0 A not read back counts) or by the read-back showing a value
it sent, confirmed, tried or saw at a refused try.
- **C3** is T43-T45; **C7** is EV-22's.
## Rig round 1 (rig FAIL on cc8c0dc), with EV-32 and EV-36
- **The stuck-reading check (chargers.py `CarTracker`), for every writer**
(SPIKE-06 option 2, PM decision; replaces 3a17012's power rules).
- Baseline: the signature (power, read-back) of the latest reading taken
BEFORE the send, kept at `begin_write`; never a reading that arrived
while the write waited (the rig's race, C10/C11, C13).
- Arms: a write that moved the setpoint by `STUCK_MIN_A`. Accepted: at its
send, on the baseline. Refused (EV-13): only with no life in `TOOK_S`,
dated the send, on the baseline. EV-36: the first sample after the send
is not life by itself; life differs from the samples before the send
AND from that first one.
- Clears: any reading whose signature differs from the baseline.
- Stuck: armed and not cleared for `STUCK_S` (60 s).
- A frozen POWER under an accepted write (the read-back moves) is no longer
judged here: the energy meter (EV-18 `contradicted`) and the read-back
cap on the trusted figure judge it.
- **Solar after a stuck verdict (C12, C14):** while no current of Solar's
own may stand (its own 0 A stands, or Solar was just chosen), a stuck
verdict no longer holds Solar: it writes its 0 A first over a current that
is not its own, then the start rule runs; at most MAX_TRIES starts per
verdict, then one CHARGER_REFUSED, then one more start after 15 min and
one every 30 min (PM decision: no hold until a press). The episode ends
when the reading follows a start, on a press of Solar, Off, Manual, shadow
or a stop (`_stuck_end`). Its write moves the reading (the verdict clears) or is
refused (EV-04's retries, then CHARGER_REFUSED).
- **No amp ping-pong:** after a step down, a step back up needs
`UP_HYST_W` (100 W) past the amp boundary.
- **The meter's age:** Solar's own `stale_input_s` gate applies where the age
measures arrival (HomeWizard local, MQTT, DSMR). On `ha_signed` the age is
the time since the value changed (Home Assistant publishes changes only), so
a healthy meter at a flat load would read as stale; there the source's own
`meter_max_age_s` is the bound (a silent meter: 0 A at
`meter_max_age_s` + `ev_pause_min`).