EV-20 rig round 2: a short charger read gap keeps the last reading; ha_signed pause timed from the meter age
A charger reading missing for less than stale_input_s keeps the last trusted reading in CarTracker (shared by Solar, Manual and the peak guard): no decision or write in that cycle, no stuck arm or clear. At stale_input_s the safe path is unchanged. This also stops the false PEAK_GUARD_FLOOR_LIMITED after one gap (EV-18 T10(b) updated). On ha_signed Solar's unknown-sun pause comes at meter age meter_max_age_s + ev_pause_min, checked every cycle. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VSY9UpTaUYnjJF5oVtbM1w
This commit is contained in:
@@ -144,3 +144,18 @@ one small set of facts and derives every path from them:
|
||||
`meter_max_age_s` is the bound (a silent meter: 0 A at
|
||||
`meter_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 than
|
||||
`stale_input_s` keeps the last trusted reading (`held`); nothing is decided
|
||||
or written in that cycle (`ctl_car.car_step` returns), and it neither arms
|
||||
nor clears the stuck check. At `stale_input_s` the 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 passed `meter_max_age_s`, so 0 A when the
|
||||
age reaches `meter_max_age_s` + `ev_pause_min` (330 s), checked every
|
||||
control cycle (bound 330 s + one cycle). Arrival sources are unchanged.
|
||||
|
||||
|
||||
@@ -498,8 +498,12 @@ class SunInputs:
|
||||
|
||||
def __init__(self, target_w=None, hold=False, auto=True, start_s=120.0,
|
||||
pause_s=300.0, spare_w=None, room_w=0.0, margin_w=100.0,
|
||||
first=DEFAULT_FIRST):
|
||||
first=DEFAULT_FIRST, unknown_s=0.0):
|
||||
self.target_w, self.hold, self.auto = target_w, hold, auto
|
||||
# EV-20 rig round 2: how long the sun has already been unknown when
|
||||
# the cause is the meter's own age (`ha_signed`): the pause is timed
|
||||
# from that age, not from the cycle that noticed it.
|
||||
self.unknown_s = unknown_s
|
||||
self.start_s, self.pause_s = start_s, pause_s
|
||||
self.spare_w, self.room_w, self.margin_w = spare_w, room_w, margin_w
|
||||
self.first = first
|
||||
@@ -563,7 +567,7 @@ class SolarPlan:
|
||||
self.switch, self._before = False, None
|
||||
|
||||
def step(self, now, *, target_w, n_now, auto, clamp, start_s, pause_s,
|
||||
hold=False, gap_ok=True):
|
||||
hold=False, gap_ok=True, unknown_s=0.0):
|
||||
"""`n_now`: the phases the car draws on now (1 for a one-phase car);
|
||||
`auto`: Solar may choose the phases; `gap_ok`: a phase change is
|
||||
allowed now (EV-04's one per `PHASE_GAP_S`); `hold`: readings late
|
||||
@@ -586,6 +590,11 @@ class SolarPlan:
|
||||
if self.a > 0.0:
|
||||
if self.unknown_since is None:
|
||||
self.unknown_since = now
|
||||
if unknown_s > 0.0:
|
||||
# ha_signed: unknown since the meter's age passed its
|
||||
# bound, so the pause comes at that age + `pause_s`.
|
||||
self.unknown_since = min(self.unknown_since,
|
||||
now - unknown_s)
|
||||
# A hold that began on a known low spare still ends on time.
|
||||
if now - self.unknown_since >= pause_s or (
|
||||
self.low_since is not None
|
||||
@@ -919,7 +928,7 @@ class SolarWriter(ManualWriter):
|
||||
now, target_w=sun.target_w, hold=sun.hold, n_now=n_now,
|
||||
auto=sun.auto and not self.single and not self.phases_gave_up,
|
||||
clamp=clamp, start_s=sun.start_s, pause_s=sun.pause_s,
|
||||
gap_ok=gap_ok)
|
||||
gap_ok=gap_ok, unknown_s=getattr(sun, "unknown_s", 0.0))
|
||||
|
||||
@staticmethod
|
||||
def _drawing(r) -> bool:
|
||||
|
||||
@@ -719,6 +719,7 @@ class CarTracker:
|
||||
# write went out, kept at `begin_write` (the arming baseline). Empty: no
|
||||
# write begun, and `note_write` uses `sig`.
|
||||
pre_sig: tuple = ()
|
||||
held: bool = False # EV-20: the last reading stands in for a gap
|
||||
armed_at: float | None = None
|
||||
armed_sig: tuple | None = None
|
||||
sig: tuple | None = None
|
||||
@@ -735,6 +736,17 @@ class CarTracker:
|
||||
persist: bool = False # set when `today` changed, for the store
|
||||
|
||||
def observe(self, r: ChargerReading, now: float, now_utc, day: str):
|
||||
if not r.available and self.bad_since is None:
|
||||
self.bad_since, self.bad_since_utc = now, now_utc
|
||||
if self._held(r, now):
|
||||
# EV-20 rig round 2 (PM): a reading missing for less than
|
||||
# `stale_s` keeps the last trusted figure and decides nothing:
|
||||
# no write, no pause, and it neither arms nor clears the stuck
|
||||
# check. At `stale_s` the missing reading is taken as before.
|
||||
self.held = True
|
||||
self._status_edge(now, now_utc)
|
||||
return
|
||||
self.held = False
|
||||
self.reading = r
|
||||
self.obs_at = now
|
||||
self._corr_note(r, now)
|
||||
@@ -757,6 +769,13 @@ class CarTracker:
|
||||
self._timers(r, now)
|
||||
self._status_edge(now, now_utc)
|
||||
|
||||
def _held(self, r, now: float) -> bool:
|
||||
"""Is this missing reading a short gap behind a usable one?"""
|
||||
last = self.reading
|
||||
return (not r.available and last is not None and last.available
|
||||
and self.last_ok is not None
|
||||
and now - self.last_ok < self.stale_s)
|
||||
|
||||
# -- reachability ----------------------------------------------------------
|
||||
def unreachable(self, now: float) -> bool:
|
||||
return self.bad_since is not None and now - self.bad_since >= UNREACHABLE_S
|
||||
|
||||
@@ -368,6 +368,11 @@ class CarMixin:
|
||||
cycle's read did) and writes only through `carmode`'s writers."""
|
||||
if not self.charger.configured():
|
||||
return
|
||||
if self.car.held:
|
||||
# EV-20 rig round 2 (PM): the charger missed a read for less than
|
||||
# `stale_input_s`; the last trusted figure stands and nothing is
|
||||
# decided or written from the gap.
|
||||
return
|
||||
now = self.car_now()
|
||||
if self.car_mode != carmode.SOLAR:
|
||||
await self.car_writer.step(
|
||||
@@ -452,7 +457,19 @@ class CarMixin:
|
||||
hold=hold, auto=ph not in ("1", "3"),
|
||||
start_s=60.0 * carmode.solar_option(o, "ev_start_min"),
|
||||
pause_s=60.0 * carmode.solar_option(o, "ev_pause_min"),
|
||||
spare_w=spare, room_w=room, margin_w=margin, first=self.car_first)
|
||||
spare_w=spare, room_w=room, margin_w=margin, first=self.car_first,
|
||||
unknown_s=self._car_meter_over_s() if spare is None else 0.0)
|
||||
|
||||
def _car_meter_over_s(self) -> float:
|
||||
"""EV-20 rig round 2 (PM): on `ha_signed`, how far the meter's age is
|
||||
past `meter_max_age_s`, so Solar's pause comes at that age +
|
||||
`ev_pause_min` (checked every cycle), not a cycle or two later."""
|
||||
if not self.p1_enabled \
|
||||
or str(self.o.get("meter_source") or "") != "ha_signed":
|
||||
return 0.0
|
||||
age = self.p1.age_s()
|
||||
bound = float(self.o.get("meter_max_age_s", 30) or 30)
|
||||
return 0.0 if age is None else max(0.0, age - bound)
|
||||
|
||||
def _car_sun_tick(self, mono) -> None:
|
||||
"""Solar kWh: per cycle, in Solar only, the car's power up to the sun
|
||||
|
||||
@@ -605,11 +605,14 @@ for nm, kw in (("T2", dict(house=H.shape(14000.0), b=const(800.0))),
|
||||
r10b, tr10b = H.run(a=ZERO, extra=unavailable(E + 1, E + 2), **kw)
|
||||
summary(f"T10(b) {nm}", r10b, tr10b)
|
||||
if nm == "T2":
|
||||
# EV-20 rig round 2 (PM): a charger read missing for less than
|
||||
# stale_input_s keeps the last trusted figure, so this one-cycle gap
|
||||
# is no longer an unknown car figure (was: the alarm for that cycle).
|
||||
check("T10(b) T2: the charger unavailable for one cycle (E+1): the "
|
||||
"alarm stands for that cycle only (Expected 5)",
|
||||
H.edges(tr10b) == [E + 1]
|
||||
and all(not x["alarm"] for x in H.window(tr10b, E + 2, E + 899))
|
||||
and all(x["explains"] for x in H.window(tr10b, E + 2, E + 899)
|
||||
"last trusted figure stands (EV-20), no alarm edge, the car "
|
||||
"explains every limited cycle",
|
||||
H.edges(tr10b) == [] and quiet(r10b, tr10b)
|
||||
and all(x["explains"] for x in H.window(tr10b, E, E + 899)
|
||||
if x["lim"]))
|
||||
else:
|
||||
check("T10(b) T5: the alarm at the base second and it stands",
|
||||
@@ -813,6 +816,21 @@ def per_quarter(ts):
|
||||
return out
|
||||
|
||||
|
||||
# EV-20 rig round 2: ONE failed charger read in the T2 shape. The tracker keeps
|
||||
# the last trusted figure for a gap under `stale_input_s`, so the car still
|
||||
# explains the peak and no floor alarm comes (rig: a false FLOOR_LIMITED 1-2 s
|
||||
# after a single read gap, on base and head).
|
||||
for gap in (1, 2):
|
||||
rg, trg = H.run(H.shape(14000.0), a=ZERO, b=const(800.0),
|
||||
extra={E + 30: lambda p, c: p.ch.go_unavailable(),
|
||||
E + 30 + gap: lambda p, c: p.ch.go_unavailable(
|
||||
False)})
|
||||
wg, limg = summary(f"T-gap {gap} s", rg, trg)
|
||||
check(f"T-gap: {gap} missed charger read(s) at E+30: no "
|
||||
f"goodwe_peak_soc_floor, no FLOOR_LIMITED ERROR, no red peak_guard "
|
||||
f"row, the car explains every limited cycle",
|
||||
quiet(rg, trg) and all_explained(limg))
|
||||
|
||||
# Cover off, the T9(c) liar at the reserve: the guard's own engagement flips
|
||||
# as the liar's figure is corroborated now and then (its input is
|
||||
# `car_exclude`), pre-existing (base: 4 edges). Printed, not graded here.
|
||||
|
||||
@@ -502,4 +502,116 @@ for race in (True, False):
|
||||
nevers(r, f"C13 controller [race={race}]")
|
||||
|
||||
|
||||
# =========================================================================== #
|
||||
print("\n7. RIG ROUND 2: A SHORT CHARGER READ GAP; THE ha_signed PAUSE BY AGE")
|
||||
# =========================================================================== #
|
||||
# Full sun, Car first, charging 10 A from 120 s; the charger does not answer
|
||||
# for 1, 2 or 16 cycles at 600 s (Home Assistant shows it unavailable).
|
||||
def gap_run(n, beside=False):
|
||||
sim = SimCharger(setpoint_a=0)
|
||||
if beside:
|
||||
sim.lag_s = 1.0
|
||||
return S.drive(const(500.0), const(2900.0), dur=1100, first="car",
|
||||
socs={"a": 100.0, "b": 100.0}, sim=sim, beside=beside,
|
||||
events={600: lambda p, c: p.ch.go_unavailable(),
|
||||
600 + n: lambda p, c: p.ch.go_unavailable(False)})
|
||||
|
||||
|
||||
for n in (1, 2):
|
||||
for beside in (False, True):
|
||||
r = gap_run(n, beside)
|
||||
w = cur_writes(r)
|
||||
late = [(t, a) for t, a, _ in w if t >= 590]
|
||||
unk = [x["t"] for x in r["trace"] if 590 <= x["t"] < 1100
|
||||
and x["spare"] is None]
|
||||
check(f"read gap of {n} sample(s) at 600 s [beside={beside}]: no "
|
||||
f"write and no pause after it, the spare stays known (writes "
|
||||
f"from 590 s {late}, unknown {unk[:3]})",
|
||||
late == [] and unk == [] and r["sim"].power_w > 2000.0)
|
||||
nevers(r, f"read gap {n} [beside={beside}]")
|
||||
|
||||
# 16 s (>= stale_input_s): the safe path as before. The charger is taken as
|
||||
# gone; on its return Solar writes 0 A first (D2), then the start rule.
|
||||
r = gap_run(16)
|
||||
w = cur_writes(r)
|
||||
late = [(t, a) for t, a, _ in w if t >= 590]
|
||||
check(f"read gap of 16 s: the safe path, 0 A first on the return, then the "
|
||||
f"start rule ({late[:3]})",
|
||||
present(nth(late, 0)) and nth(late, 0)[1] == 0.0
|
||||
and 616 <= nth(late, 0)[0] <= 620 and present(nth(late, 1))
|
||||
and nth(late, 1)[1] > 0.0)
|
||||
|
||||
# The held figure neither arms nor clears the stuck check: a frozen reading
|
||||
# after an accepted write is still stuck, with a 2-sample gap inside the 60 s
|
||||
# (flagged at the first real reading at or after +60 s).
|
||||
tr = CH.CarTracker()
|
||||
for i in range(-5, 1):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.begin_write()
|
||||
tr.end_write(TS + 1)
|
||||
tr.note_write(TS, 10.0, 0.0, True)
|
||||
gone = CH.ChargerReading(why="no answer")
|
||||
st_at = None
|
||||
for i in range(1, 90):
|
||||
if i in (59, 60):
|
||||
tr.observe(gone, TS + i, UTC, DAY)
|
||||
else:
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
if st_at is None and tr.stuck(TS + i):
|
||||
st_at = i
|
||||
check(f"frozen reading with a 2-sample gap at +59/+60: still stuck, at the "
|
||||
f"first real reading after +60 (+{st_at})", st_at == 61)
|
||||
tr = CH.CarTracker()
|
||||
for i in range(-5, 1):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.begin_write()
|
||||
tr.end_write(TS + 1)
|
||||
tr.note_write(TS, 10.0, 0.0, True)
|
||||
for i in range(1, 70):
|
||||
tr.observe(rd(), TS + i, UTC, DAY)
|
||||
tr.observe(gone, TS + 70, UTC, DAY)
|
||||
check("a held gap does not clear a stuck verdict (+70 s gap, still stuck)",
|
||||
tr.stuck(TS + 70) and getattr(tr, "held", None) is True)
|
||||
|
||||
# ha_signed: the pause is timed from the meter's age (PM): unknown since the
|
||||
# age passed meter_max_age_s, so 0 A when the age reaches 330 s. A plan
|
||||
# stepped every 10 s (the rig's cycle) that notices the stale meter 7 s late
|
||||
# pauses at the first step at or after age 330 (bound: 330 + one cycle).
|
||||
plan = carmode.SolarPlan()
|
||||
plan.reset(1)
|
||||
kw = dict(n_now=1, auto=False, clamp=16.0, start_s=120.0, pause_s=300.0)
|
||||
t = 0.0
|
||||
while plan.a <= 0.0 and t < 400:
|
||||
plan.step(t, target_w=2900.0, **kw)
|
||||
t += 10.0
|
||||
age0 = t + 3.0 # the meter's last reading; the bound passes at +30
|
||||
paused_at = None
|
||||
while t < age0 + 400:
|
||||
age = t - age0
|
||||
over = max(0.0, age - 30.0)
|
||||
try:
|
||||
plan.step(t, target_w=None if age > 30.0 else 2900.0,
|
||||
unknown_s=over, **kw)
|
||||
except TypeError: # a build without the age rule
|
||||
plan.step(t, target_w=None if age > 30.0 else 2900.0, **kw)
|
||||
if plan.a == 0.0 and paused_at is None:
|
||||
paused_at = age
|
||||
break
|
||||
t += 10.0
|
||||
check(f"ha_signed pause by age, plan stepped every 10 s: 0 A at meter age "
|
||||
f"{paused_at} (330 <= age <= 340)",
|
||||
paused_at is not None and 330.0 <= paused_at <= 340.0)
|
||||
# The controller hands Solar that age: 40 s after the meter went silent at
|
||||
# 300 s, `unknown_s` is 10 (age 40 - 30).
|
||||
seen = {}
|
||||
r = S.drive(const(500.0), const(2900.0), dur=360, first="car",
|
||||
socs={"a": 100.0, "b": 100.0}, opts={"ev_phases": "1"},
|
||||
events={300: lambda p, c: setattr(p, "meter_on", False),
|
||||
340: lambda p, c: seen.update(
|
||||
u=getattr(c.car_sun_inputs(p.clock[0]),
|
||||
"unknown_s", None))})
|
||||
check(f"ha_signed: 40 s after the meter went silent Solar is told the sun "
|
||||
f"has been unknown for 10 s ({seen})",
|
||||
seen.get("u") is not None and 9.0 <= seen["u"] <= 12.0)
|
||||
|
||||
report()
|
||||
|
||||
Reference in New Issue
Block a user