EV-05 round 4: the cut waits only while the batteries have headroom
checks / unit (pull_request) Successful in 23m43s
infra-pin / fresh (pull_request) Successful in 1s

Review of d2504ef, brief v5 Expected 8 (owner 2026-11-18): the 15 s wait
needs batteries that can still raise their output: above the cut-out, the
guard neither saturated nor floor-limited, and their output more than 100 W
under what they can give. Otherwise the car is cut at once.

Tests: R4/N4 rows against a car-Off twin (house to 25900 and 25950 W, aim
3400 W) land under the aim; T21/T22 cut at once beyond the batteries; the
T21b catch rows and T44 (0 cut pauses) stay green.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ems-agent
2026-11-18 16:02:01 +01:00
co-authored by Claude
parent d2504efa82
commit 8818768dab
4 changed files with 71 additions and 17 deletions
@@ -74,6 +74,17 @@ inputs (`car_sun_inputs`) and runs the writer in the same background task.
while the meter still shows the old power. A new cut needs the car to show while the meter still shows the old power. A new cut needs the car to show
the lower power and `CUT_SETTLE_S` (15 s) more for the meter. the lower power and `CUT_SETTLE_S` (15 s) more for the meter.
## Round 4 (review of d2504ef, brief v5)
- **The wait needs headroom** (owner 2026-11-18): `ctl_car._car_batt_headroom`.
The 15 s wait runs only while a battery is above its cut-out, the guard is
neither saturated nor floor-limited (peak reserve), and the batteries'
output is more than `HEADROOM_W` (100 W) under what they can give
(`guard.able_w`, else the site rating). Otherwise the cut comes at once.
Before, "above the cut-out" alone let the car run 15 s while the batteries
were already at full output, and the period landed over the aim (review
repro: house 25 900 and 25 950 W, test_ev05.py R4/N4 against a car-Off twin).
## Solar kWh ## Solar kWh
Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first, Per cycle in Solar: `min(car power, max(0, spare - room))` Batteries first,
+5 -4
View File
@@ -3351,10 +3351,11 @@ Both apply at once, with no restart.
that draws one phase while three are allowed is counted on one phase. that draws one phase while three are allowed is counted on one phase.
- **The car is cut first for the peak limit.** When the 15-minute period heads - **The car is cut first for the peak limit.** When the 15-minute period heads
over the limit and the peak guard would ask the batteries for power, that is over the limit and the peak guard would ask the batteries for power, that is
taken off the car first, down to 0 A if needed. While a battery can still taken off the car first, down to 0 A if needed. While the batteries can
give power, the add-on first waits 15 seconds, so a cloud the batteries still raise their output, the add-on first waits 15 seconds, so a cloud
catch does not pause the car. With every battery at its cut-out level, or the batteries catch does not pause the car. It cuts at once when they
in the last 2 minutes of the 15-minute period, it cuts at once. A Solar cannot: already at full power, at the peak reserve or at their cut-out
level. It also cuts at once in the last 2 minutes of the 15-minute period. A Solar
charge never sets the month's peak. charge never sets the month's peak.
- **Every way out of Solar leaves the charger at 0 A**: a stop or - **Every way out of Solar leaves the charger at 0 A**: a stop or
restart of the add-on (before the inverters go to 0 W), stopping control, a restart of the add-on (before the inverters go to 0 W), stopping control, a
+19 -1
View File
@@ -46,6 +46,10 @@ CAR_SUN_KEY = "car_sun" # EV-05: {day, kwh} charged from the sun today
# under the aim). # under the aim).
CUT_WAIT_S = 15.0 CUT_WAIT_S = 15.0
CUT_NEAR_END_S = 120.0 CUT_NEAR_END_S = 120.0
# Round 4 (owner 2026-11-18, brief v5): the wait needs HEADROOM, batteries that
# can still raise their output. Within this many W of their rating they are
# at full output.
HEADROOM_W = 100.0
# EV-05: at shutdown the charger's 0 A waits at most this long, then the # EV-05: at shutdown the charger's 0 A waits at most this long, then the
# inverters are released whatever the charger did. # inverters are released whatever the charger did.
RELEASE_WAIT_S = 15.0 RELEASE_WAIT_S = 15.0
@@ -456,6 +460,20 @@ class CarMixin:
return True return True
return False return False
def _car_batt_headroom(self, guard) -> bool:
"""EV-05 round 4: can the batteries still RAISE their output? A
battery above its cut-out (`_car_batt_able`), the guard neither
saturated nor at the peak reserve, and the batteries' output more
than `HEADROOM_W` under what they can give."""
if not self._car_batt_able() or guard is None \
or guard.saturated or guard.floor_limited:
return False
batt = self.site_batt_w
top = guard.able_w if guard.able_w is not None else self.site_rating_w
if batt is None or top is None:
return False
return float(batt) < float(top) - HEADROOM_W
def _car_solar_pause(self, mono) -> bool: def _car_solar_pause(self, mono) -> bool:
"""EV-05: Solar's own 0 A (a pause, the peak cut, the phase change) """EV-05: Solar's own 0 A (a pause, the peak cut, the phase change)
gets EV-15's grace, bounded the same way: from the moment it is sent, gets EV-15's grace, bounded the same way: from the moment it is sent,
@@ -584,7 +602,7 @@ class CarMixin:
if self._car_want_since is None: if self._car_want_since is None:
self._car_want_since = mono self._car_want_since = mono
left = QUARTER_S - float(real_proj.elapsed_s) left = QUARTER_S - float(real_proj.elapsed_s)
if not self._car_batt_able() or left <= CUT_NEAR_END_S \ if not self._car_batt_headroom(guard) or left <= CUT_NEAR_END_S \
or mono - self._car_want_since >= CUT_WAIT_S: or mono - self._car_want_since >= CUT_WAIT_S:
self.car_cut_w = cut self.car_cut_w = cut
else: else:
+36 -12
View File
@@ -626,8 +626,9 @@ check(f"T21b: a cloud edge the batteries catch within 15 s gives no cut and "
0 < len(want21c) < 15 0 < len(want21c) < 15
and not first_cut(r21c, 900) and 0.0 not in [v for _t, v in w21c] and not first_cut(r21c, 900) and 0.0 not in [v for _t, v in w21c]
and nonzero(r21c) and nonzero(r21c)[-1][1] >= 6.0) and nonzero(r21c) and nonzero(r21c)[-1][1] >= 6.0)
# T21: a step the batteries cannot catch (500 -> 15500 W for 90 s): the cut # T21: a step the batteries cannot catch (500 -> 15500 W for 90 s). Round 4
# comes 15 s after the guard first wants power, not sooner. # (brief v5): the batteries have no headroom (the guard is saturated), so the
# cut does not wait 15 s; it comes at once.
r21 = S.drive(house=steps((0, 500.0), (200, 15500.0), (290, 500.0)), r21 = S.drive(house=steps((0, 500.0), (200, 15500.0), (290, 500.0)),
sun=const(2900.0), first="car", socs=ABLE, dur=920) sun=const(2900.0), first="car", socs=ABLE, dur=920)
x21 = first_cut(r21, 200) x21 = first_cut(r21, 200)
@@ -635,15 +636,14 @@ since21 = next((x["since"] for x in r21["trace"] if x["since"] is not None),
None) None)
w21 = [] if x21 is None else [(t, v) for t, v in cur(r21) if t >= x21["t"]] w21 = [] if x21 is None else [(t, v) for t, v in cur(r21) if t >= x21["t"]]
lim21 = None if x21 is None else math.floor((2300.0 - x21["cut"]) / 230.0) lim21 = None if x21 is None else math.floor((2300.0 - x21["cut"]) / 230.0)
check(f"T21: a house step beyond the batteries: no cut in the first 15 s the " check(f"T21: a house step beyond the batteries (no headroom): the car is cut "
f"guard wants power, then the car is cut within 1 cycle, to at most " f"at once, within 1 cycle, to at most "
f"floor((2300 - cut) / 230) A (wants from {since21}, cut " f"floor((2300 - cut) / 230) A (wants from {since21}, cut "
f"{None if x21 is None else round(x21['cut'])} W at " f"{None if x21 is None else round(x21['cut'])} W at "
f"{None if x21 is None else x21['t']}, writes {w21})", f"{None if x21 is None else x21['t']}, writes {w21})",
x21 is not None and since21 is not None x21 is not None and since21 is not None
and 15 <= x21["t"] - since21 <= 16 and w21 and 0 <= x21["t"] - since21 <= 1 and w21
and w21[0][0] <= x21["t"] + 2 and w21[0][1] <= max(lim21, 0) and w21[0][0] <= x21["t"] + 2 and w21[0][1] <= max(lim21, 0))
and not [t for t, v in cur(r21) if 200 <= t < x21["t"] and v == 0.0])
q21 = [g for q, g, _c in quarters(r21, 3400.0) if q == 0] q21 = [g for q, g, _c in quarters(r21, 3400.0) if q == 0]
check(f"T21: the period still lands under the aim ({[round(g) for g in q21]} " check(f"T21: the period still lands under the aim ({[round(g) for g in q21]} "
f"W against 3400 W)", q21 and q21[0] <= 3410.0) f"W against 3400 W)", q21 and q21[0] <= 3410.0)
@@ -660,13 +660,12 @@ since22 = next((x["since"] for x in r22["trace"] if x["since"] is not None),
None) None)
w22 = [] if x22 is None else [(t, v) for t, v in cur(r22) if t >= x22["t"]] w22 = [] if x22 is None else [(t, v) for t, v in cur(r22) if t >= x22["t"]]
last_cut22 = max((x["t"] for x in r22["trace"] if x["cut"] > 0), default=None) last_cut22 = max((x["t"] for x in r22["trace"] if x["cut"] > 0), default=None)
check(f"T22: an excess of 920 W or more: 0 A, no 5-min hold, after the 15 s " check(f"T22: an excess of 920 W or more, no headroom: 0 A at once, no 5-min "
f"wait and not sooner ({w22}, wants from {since22}, cut " f"hold ({w22}, wants from {since22}, cut "
f"{None if x22 is None else round(x22['cut'])})", f"{None if x22 is None else round(x22['cut'])})",
x22 is not None and since22 is not None x22 is not None and since22 is not None
and 15 <= x22["t"] - since22 <= 16 and w22 and 0 <= x22["t"] - since22 <= 1 and w22
and w22[0][1] == 0.0 and w22[0][0] <= x22["t"] + 2 and w22[0][1] == 0.0 and w22[0][0] <= x22["t"] + 2)
and not [t for t, v in cur(r22) if 200 <= t < x22["t"] and v == 0.0])
check(f"T22: no restart before the period is under the aim (last cut " check(f"T22: no restart before the period is under the aim (last cut "
f"{last_cut22}) and the 120 s start rule has run", f"{last_cut22}) and the 120 s start rule has run",
last_cut22 is not None and len(w22) >= 2 and w22[1][1] > 0 last_cut22 is not None and len(w22) >= 2 and w22[1][1] > 0
@@ -1690,6 +1689,31 @@ for lag in (0.0, 3.0):
f"takes one cut, to {want3c} A, and no more ({w3c})", f"takes one cut, to {want3c} A, and no more ({w3c})",
x3c is not None and len(w3c) == 1 and w3c[0][1] == want3c x3c is not None and len(w3c) == 1 and w3c[0][1] == want3c
and want3c >= 11) and want3c >= 11)
# =========================================================================== #
print("\nROUND 4. NO HEADROOM, NO WAIT: N4 AGAINST A CAR-OFF TWIN")
# =========================================================================== #
# The review's repro: N=2 at 60 %, Car first, sun 13 kW, the car at 16 A on
# 3 phases; at t=905 the house steps to H and stays. The batteries give their
# full rating, the guard is saturated: the cut must not wait 15 s.
for H in (25900.0, 25950.0):
hh = steps((0, 500.0), (905, H))
r4 = S.drive(house=hh, sun=const(13000.0), first="car", socs=ABLE,
dur=1810)
r4o = S.drive(house=hh, sun=const(13000.0), first="car", socs=ABLE,
dur=1810, mode="off")
q4 = {q: g for q, g, _c in quarters(r4, 3400.0)}
q4o = {q: g for q, g, _c in quarters(r4o, 3400.0)}
cut4 = first_cut(r4, 905)
since4 = next((x["since"] for x in r4["trace"] if x["since"] is not None
and x["t"] >= 905), None)
check(f"R4/N4 house to {H:.0f} W at 905: the cut comes at once "
f"(wants from {since4}, cut at {None if cut4 is None else cut4['t']})"
f" and the period lands under the aim like the car-Off twin "
f"({round(q4.get(900, -1))} W vs {round(q4o.get(900, -1))} W, aim "
f"3400 W)",
cut4 is not None and since4 is not None
and cut4["t"] - since4 <= 1 and 900 in q4 and 900 in q4o
and q4[900] <= 3400.0 and q4o[900] <= 3400.0)
print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)") print("\n(T39, T44, T45, T50 and T51, the long runs, are in test_ev05_long.py)")
print() print()