11 KiB
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
_watchjudges 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 forev_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 mostOWN_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 insideRELEASE_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 = solaras 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 inTOOK_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.
- Baseline: the signature (power, read-back) of the latest reading taken
BEFORE the send, kept at
- 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_sgate applies where the age measures arrival (HomeWizard local, MQTT, DSMR). Onha_signedthe 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 ownmeter_max_age_sis the bound (a silent meter: 0 A atmeter_max_age_s+ev_pause_min).
Rig round 2 (rig FAIL on 09b6af9), PM rulings
- A short charger read gap (chargers.py
CarTracker.observe, shared by Solar, Manual and the peak guard): a reading missing for less thanstale_input_skeeps the last trusted reading (held). A gap is a read that got no answer, or every required entity unavailable; one entity missing, a wrong power unit or the login off stay readings of their own (EV-03 round 4, unchanged); nothing is decided or written in that cycle: no writer steps (ctl_car.car_stepreturns), no plan count moves (start, phase change, hold,set_at) and a decision due then runs on the next real reading (review r3, PM design). The one exception is Solar's pause by the meter's age (C18,held_pause). A held read neither arms nor clears the stuck check. Atstale_input_sthe missing reading is taken as before (the safe path: the charger is gone, 0 A first on its return). This also ends the false PEAK_GUARD_FLOOR_LIMITED after one gap (EV-18 T10(b) changed accordingly). - Silent meter on
ha_signed: Solar's unknown-sun pause is timed from the meter's age: unknown since the age passedmeter_max_age_s, so 0 A when the age reachesmeter_max_age_s+ev_pause_min(330 s), checked every control cycle (bound 330 s + one cycle). Arrival sources are unchanged. - No non-zero write while the meter is silent (SPIKE-06 C17, N8 strict):
while the meter's age is past
meter_max_age_s, Solar sends no non-zero current: no retry, no raise, no phase change begun, and a phase change under way ends at its 0 A (no select after that, no closing current); the plan pauses. 0 A is always allowed. Also on a held read (nz_block). - The age pause on a held read (C18): on a held cycle Solar does not step
(review r3, PM design); only
held_pauseruns: while the meter is silent and its age has reachedmeter_max_age_s+ev_pause_min, the plan pauses and a NEW 0 A goes out (no retry to a charger that is not answering). No phase change, start, hold pause or other count moves on a held cycle. - Accepted (PM, P9g): a frozen charger that also stops answering is flagged only once it answers again; the 15 s safe path covers the gap.
- A held read during a phase change (SPIKE-06 C19): a phase change under
way does nothing on a held read (no write, no pause) and goes on at the next
real reading; it ends at its 0 A only while the meter is silent (C17). No
phase change begins on a held cycle; a gap of
stale_input_sor more takes the safe path unchanged. Accepted by design (PM): a one-sample partial reading (only power unavailable, say) still gives the D2 0 A.