Files
goodwe-addon/goodwe_controller/DECISIONS/EV-04-manual-mode.md
T
glenn schrooyenandClaude f31dcb62b6
checks / unit (pull_request) Failing after 21m10s
infra-pin / fresh (pull_request) Successful in 1s
EV-04 round 3: undo restores the current in shadow mode too, energy rule catches a frozen 6 A figure, settle after a refused select
N1 the undo gives the old current back (clamped) in shadow mode; DECISIONS records it as the one write shadow mode allows.
N2 the corroboration looks back to a stretch with at least 40 Wh expected (60 s at 2.4 kW and up, 104 s at 1.38 kW).
L4 the current comes back 10 s after the phase select returned, also when it was refused.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-16 07:59:15 +01:00

122 lines
7.1 KiB
Markdown

# EV-04 — Manual mode: the first write to a car charger
The design is `reports/EV-01-design-report.md` (sections 2 to 5), accepted on
2026-11-15 with all eight decisions as recommended. This record keeps what the
code had to decide that the design left open.
## What writes, and who may
`app/carmode.py` `ManualWriter` is the only caller of `write_current` and
`write_phases` (test_ev03.py greps for any other). It runs in a background task
(`ctl_car.CarMixin.car_kick`), never in the control cycle: a write waits up to
10 s for the charger's read-back, and the cycle must never wait for a charger.
- **Off writes nothing.** The mode is runtime state in the store (`car_mode`,
`car_current`, `car_phases`), changed on Home or from Home Assistant with no
restart. Solar and Night are not accepted (EV-05, EV-02).
- **Once per user change.** A user change sets a flag the writer clears when the
charger has what was asked. A difference nobody asked for is the other-writer
detector's business, not a reason to write.
- **No car or a full car: nothing is written**, and the setting waits for a car.
- **Shadow mode and a stopped control write nothing**; the card says what the add-on
would set.
- **The clamp is the driver's too.** The writer asks for at most the clamp, and
`AlfenHaDriver.write_current` refuses anything above
`min(ev_max_a, station limit read now, entity range max)`: it sends nothing,
logs `CHARGER_CLAMP` at ERROR (the OUTPUT_CLAMP shape) and answers False.
- **"Taken"** means the read-back followed within 10 s. A write that was not
taken is tried again after a minute, three times, then it waits for the user
(an amber row). A late read-back is adopted, never called another writer.
## The phase sequence
0 A, wait until the charger reports under 100 W or mode3 leaves C (20 s at most),
select the phases, wait 10 s, write the current. One switch per 10 minutes. A
charger that does not take the 0 A never gets the phases select. A sequence that
has begun is finished whatever the mode, because it leaves the car at 0 A
otherwise; a stop of the add-on in the middle gives the car its current back
(`car_shutdown`).
## Another writer
A read-back that differs from what the add-on last wrote (or tried to write, or
saw before a refused write) for 30 s is another writer: a grey row, and no write
until the user changes the mode or a value. EV-03's detector still serves Off;
the tracker mutes its own detector for 15 s after each of our writes, so Manual
back to Off does not show the add-on as a second writer.
## The peak guard's alarm path
`Controller` passes the car's power to the guard's alarm path (`car_cycle`).
**The car explains the excess when the house alone would land the period under
the aim**: the car's average over the whole period (what it drew so far, and its
power now for the rest, `car_avg_w`) is at least how far the projected period is
over the aim. With decision 1 on it also needs the guard to be unable to hold
it (saturated or at the peak reserve). Then "Load too high" and "Battery stopped
limiting the peak" are not raised, the rows are not red, and one grey notice per
charging session says so. The claim, the floor and the commands are unchanged.
The brief's wording is `car_w >= projected excess over the aim`. The
instantaneous form (`car_w >= excess_w`, the watts to come off the meter now)
stops holding late in a period that the car already pushed over, because
`excess_w` grows as the seconds run out; the average form does not, and it is the
same test for a steady car.
**A stale, stuck or frozen car figure must never hide a real overload.** Only
`CarTracker.car_w_trusted` is used: fresh (the EV-03 rules, which also make an
unavailable reading None at once), not stuck after a write (SAFETY-37's shape),
never above what the read-back allows, and CORROBORATED by the charger's energy
meter (round 2). The rule (`CarTracker.corroborated`, constants `CORR_*` in
`chargers.py`): the charger reports charging (mode3 C) and has an energy entity,
and, looking back over unbroken charging readings to the shortest stretch that
is at least 55 s long and over which the reported power adds up to at least
40 Wh, the meter has gained at least 50 % of that, less 15 Wh (the meter shows
10 Wh steps, so at 40 Wh it must show one step; an honest car can fall one step
short and still passes). Readings are kept 180 s. A gap, a state other than C or
a meter that goes back starts the history again. With no such stretch yet (a
session just began, or the add-on just started) the figure is believed, so a
charge does not raise false alarms for its first minute; a frozen figure is
believed for that long only. No energy entity: never corroborated, so the normal
alarms stand. **Bound:** a frozen figure of P watts on a car that has really
stopped is caught within max(60 s, 40 Wh / P): 60 s from 2.4 kW up, 104 s at
1.38 kW (6 A, 1 phase, the lowest charge), plus the alarms' own 10 s hold. Below
about 0.8 kW (40 Wh over the 180 s kept) the figure is believed; it cannot hide
an overload that matters. (Round 2 had a 15 Wh slack that cancelled the 50 % rule
up to 1.8 kW; the 40 Wh floor fixes that.)
## The one write shadow mode allows
When the add-on has paused the car (0 A) for a phase change and has not yet
selected the phases, Off, a stop of control, a safety latch or shadow mode ends
the change. The old current is given back (clamped, `_restore_a`) in every one of
those cases, shadow mode included. With the shipped `shadow_mode: auto`, stopping
control turns shadow on, so without this the car would stay at 0 A for as long
as control is stopped, while the design's Manual column says the current
stands. Undoing our own half-done change is not a new command; it is the same
write the shutdown restore makes. Nothing else is written in shadow mode: no
phase switch, and no write afterwards.
## Decision 1 (`ev_batt_cover`)
On (the default): the guard works as it does and the batteries cover the car down
to the peak reserve. Off: the projection the guard sees leaves the car out
(`house - car_w`, with the car's average so far), so it does not force the
batteries to discharge for it, and the period goes over by the car alone. The
car is never throttled either way. The projection the guard sees is also the
one `charge_room_w` reads, so with the switch off a grid charge of the batteries
sees the room the car leaves; that is the owner's trade and DOCS says so.
## Deviations from the design text
- **Titles and setting names** follow STYLE.md (at most 5 and 6 words):
"Car over the peak limit" (the design: "Car charge over the peak limit"),
setting "Batteries help with the peak" (the design: "... while the car
charges", which is in its description).
- **No "or choose Solar"** in the Why or the notice: Solar is not in this card.
- **The Why lines** are two sentences of at most 12 words, as test_messages.py
asks; `peak.car` says "The car takes {car} and the batteries cover {cov}."
without "of it".
- **`peak.set_by_car`** keeps its first sentence only ("The batteries were at the
peak reserve" is not true with decision 1 off). A quarter counts as set by the
car when the car drew half the peak or more over it.