EV-10: the car is the cause when the period without it (projected minus the car's fresh, corroborated average) is at or under the aim, also with the projection still under it. EV-11: car_over stays on until the test has been false for 180 s. EV-12: the tracker's own-write mute opens before the write and runs 15 s from its return. Co-Authored-By: Claude <noreply@anthropic.com>
141 lines
8.3 KiB
Markdown
141 lines
8.3 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.)
|
|
|
|
## EV-10, EV-11, EV-12: the rig's three findings (EV-04 test F-1 to F-3)
|
|
|
|
- **The car is the cause when the period without it would not need the
|
|
batteries** (EV-10). `car_cycle` tests `projected - car_avg_w <= aim` (the car's
|
|
average over the same window, fresh and corroborated only) instead of
|
|
`projected > aim`, so it also holds when the car alone has taken the batteries
|
|
to the reserve and the projection is still under the aim (rig: 5888 W against
|
|
6000 W). The car must draw at least `CAR_PEAK_MIN_W`. A stale, stuck or
|
|
uncorroborated figure is `None` and the normal alarms stand.
|
|
- **Steady row, no hold on the alarm** (EV-11). Cause: after the car's own quarter
|
|
became the month peak, the aim sat on the grid it made (14.04 kW +-40 W), so
|
|
the test crossed the aim every few seconds. `car_over` (row, card, notice) now
|
|
stays on until the test has been false for `OVER_OFF_HOLD_S` = 180 s (the rig's
|
|
longest gap; shorter than a quarter) and a gap does not restart the 10 s
|
|
on-count. `car_explains`, which the alarms read, has no hold.
|
|
- **Our own write is ours until its mute ends** (EV-12). The mute of the tracker's
|
|
own detector opens before the write and runs 15 s from when it returns, because
|
|
the read-back reaches the cycle while the write still waits for it.
|
|
|
|
## 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.
|