EV-21: Solar cuts the car first for the quarter peak
infra-pin / fresh (pull_request) Successful in 2s
checks / unit (pull_request) Failing after 1h10m59s

In Solar, when the 15-minute period heads over the aim and the batteries
would have to give more, the car is lowered first: floor((car - excess) /
(230 x phases)) A, 0 under 6 A. At once without real headroom (saturated,
floor-limited, excess beyond what the batteries can add, no battery figure,
cover off, last 120 s), else after at most 15 s. One cut per episode from
its start, deeper only on a growing excess; restart with the start power
under the aim for the start time; none after a 2nd cut in the period.

Grading (formal C2): a Solar car Solar cannot cut is graded, banked and
left in the guard as in Off. A Solar car is never banked. Grey note and Why
"Solar lowered the car for the peak." Manual and Off unchanged.

Tests: test_ev21.py, test_ev21_paths.py, test_ev21_same.py; T49 in
tools/ev20_day.py; T50 in test_ev20_fuzz.py; test_ev20_guard section 8
moved from "as Manual" to "as Off" where Solar cannot cut (T51).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-25 17:01:07 +01:00
co-authored by Claude
parent a8e4ceb859
commit 7bc8988be0
17 changed files with 2175 additions and 85 deletions
@@ -0,0 +1,87 @@
# EV-21 — Solar: the car is cut first for the quarter peak
Part 2 of the split of cancelled EV-05 (owner 2026-11-19). EV-20 made Solar
and graded a Solar car exactly as a Manual car; this card lets Solar lower the
car before the batteries give more for the peak. Manual and Off do not change.
The rules are the PM rulings Q1-Q6, OQ1-OQ10 and Q-A to Q-D (brief v2); the
formal check is reports/EV-21-formal-report.md. EV-05's review rounds 2-9 are
the failure catalogue it answers.
## The rule, in plain words
- **Solar only.** When the 15-minute period heads over the aim (cap less
margin) and the batteries would have to give more than now for it, the car is
lowered first. A charge the batteries only have to slow down is not a cut.
- **How far.** `floor((car W - excess W) / (230 x phases))` A, with the phases
the car draws on (1 for a one-phase car). Under 6 A it is 0 A, never between.
Never above the current Solar has set. An untrusted car figure cuts to 0 A.
- **When.** At once without real headroom: the guard is saturated or at the
peak reserve, the excess is more than the batteries can still add, a battery
figure is missing, the cover option is off, or 120 s or less of the period
is left. Otherwise after at most 15 s, so a cloud edge the batteries catch is
not a cut. A refusing or sign-stopped battery, one at its cut-out or reserve,
and one switched off in battery modes add nothing (a charge it takes can
still stop).
- **Once per episode.** The cut is sized from the episode's start: the car's
power then, less the largest excess seen in it. A lagging meter never takes
it again from the lowered car. A growing excess makes it deeper, never
shallower.
- **Back up.** While a cut is due or stands, Solar does not raise the car, start
it or change its phases; it may still lower it. The car comes back when the
period's projection with the car's start power (6 A) has been under the aim
for the start rule's time (`ev_start_min`), counted from when it went under.
After a second cut in one period it waits for the next period. Then Solar's
own start rule runs as before.
- **The period's end.** No cut state goes over the edge: no cut at :15:00 for
the old period's energy; a new period heading over is cut in its first cycle.
- **Grading.** Solar takes the car out of the alarm grading only while it can
really cut it: Solar writes (no shadow, Stop, safety stop or shutdown), no
other writer, no charger fault or stuck reading, and the read-back shows the
current Solar sent. A cut written but not read back is not a cut. In every
other case the car figure is None for the alarm, the banking and the guard,
exactly as in Off. A Solar car is never banked as the period's cause.
- **The cover option keeps its meaning.** Off: while Solar can cut the car the
guard leaves it out, and the cut comes at once. While Solar cannot cut it,
the guard keeps it in (as Off).
- **What the user sees.** While the cut works: no car-over row and no "Car over
the peak limit" note, the card's Why says "Solar lowered the car for the
peak.", and one grey note with the same words per charging session. When
Solar cannot cut the car, the row and note say the car sets the peak.
## Where it lives
- `app/ctl_car.py` decides, in `car_cycle` (after the guard) and in a cycle
that holds before the guard (missing or late readings, Q4): `_car_cut_tick`.
The state is in memory only (`_cut`): a restart starts afresh, no store key.
- `app/carmode.py` writes: the decision is a cap on Solar's plan
(`SolarWriter.cut_a`, `SolarPlan.step(cap=...)`). The plan lowers to it at
once, past the 30 s gate and the 6 A hold, and starts nothing under it. A
phase change under way closes no higher than the cap. The write goes through
Solar's one write rule: never over another writer's value; a refused cut is
tried again as the same value after 60 s, three times.
- The seam is unchanged: `write_current` and `write_phases` are still called
only from `ManualWriter`; a cut never selects phases.
## Choices the rulings left open
- **"The batteries would have to give more than now"** is `battery W + excess
> 0` on the projection with the car: the guard's `wanted_w` with the cover on,
the same test on the real period with it off. Without it, Solar's own start
on slow batteries cut the car for the seconds the batteries took to stop
charging.
- **While the 15 s wait runs** the cap is the current Solar has then (C4: no
raise while due).
- **Under a cut the plan may lower** (formal C10), by its own 30 s rule.
- **The cut's own ramp-down.** The trusted car figure is capped by the new,
lower read-back, so for one corroboration window (60 s) after a cut the
charger took, the car's real power (fresh, not stuck, never above the current
before the cut) stands in for grading only. A car that does not come down is
graded as in Off after that window (T45).
- **Freshness (N9).** A cut is sized only from a projection that is not blind,
with the meter's own age within `stale_input_s` (`meter_max_age_s` on
`ha_signed`, whose age counts from the last change).
## Rollback
No new option, no store key, no migration. An older build ignores nothing it
does not know; it grades a Solar car as Manual again.