TARIFF-30: per-unit round-trip efficiency in the grid-charge decisions
Optional per-inverter key round_trip_eff (0.5-1). A unit's buy leg is priced at price / eta; the site trade, battery modes, day plan and Home use each unit's own. Not set: byte-identical to before. The discharge split is unchanged (part B is TARIFF-34). Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -102,6 +102,7 @@ class Pack:
|
||||
idle: bool = True # not in a maintenance phase
|
||||
refused: int = 0 # SAFETY-52/73: +1 refuses to give, -1 to charge
|
||||
probing: bool = False # OPT-15: its SAFETY-73 probe window is open
|
||||
eta: float | None = None # TARIFF-30: its own round-trip efficiency
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -140,18 +141,26 @@ def charge_to(p: Pack, ceiling_pct, targets=None):
|
||||
return None if t is None else min(float(ceiling_pct), float(t))
|
||||
|
||||
|
||||
def chargers(packs, ceiling_pct, done=(), targets=None, probe=False) -> list:
|
||||
def chargers(packs, ceiling_pct, done=(), targets=None, probe=False,
|
||||
legs=None) -> list:
|
||||
"""Batteries that may charge from the grid in a cheap run: below the
|
||||
level `charge_to()` allows them (P4: the day plan's). With `probe`, also
|
||||
one refusing to charge while its SAFETY-73 probe is open: its own P_SAFETY
|
||||
pin keeps it at PROBE_W (OPT-15)."""
|
||||
pin keeps it at PROBE_W (OPT-15).
|
||||
|
||||
TARIFF-30. `legs` is `{name: bool}` (`arbitrage.clearing()`) or None. A
|
||||
battery whose own buy leg does not clear (its round-trip losses eat the
|
||||
spread) is not a charger. None is today's list. The SAFETY-73 probe is not
|
||||
an economic charge and runs unchanged (a probing refuser stays a charger)."""
|
||||
out = []
|
||||
for p in packs:
|
||||
to = charge_to(p, ceiling_pct, targets)
|
||||
probing = probe and p.probing and p.refused < 0
|
||||
if (to is not None and p.use and p.idle and p.live
|
||||
and p.soc is not None and p.soc < to
|
||||
and (p.refused >= 0 or (probe and p.probing))
|
||||
and p.name not in done):
|
||||
and p.name not in done
|
||||
and (probing or legs is None or legs.get(p.name, True))):
|
||||
out.append(p)
|
||||
return out
|
||||
|
||||
@@ -166,11 +175,11 @@ def sellers(packs, floor_pct, done=()) -> list:
|
||||
|
||||
|
||||
def energy(packs, floor_pct, ceiling_pct, done_charge=(), done_sell=(),
|
||||
targets=None):
|
||||
targets=None, legs=None):
|
||||
"""`(charge_kwh, charge_kw, sell_kwh, sell_kw)` for `priceruns.plan()`.
|
||||
With a day plan the charge is each battery's shortfall, so the cheap run
|
||||
is only as long as the shortfall needs."""
|
||||
ch = chargers(packs, ceiling_pct, done_charge, targets)
|
||||
is only as long as the shortfall needs. `legs`: see `chargers()`."""
|
||||
ch = chargers(packs, ceiling_pct, done_charge, targets, legs=legs)
|
||||
se = sellers(packs, floor_pct, done_sell)
|
||||
return (sum(_room_kwh(p, charge_to(p, ceiling_pct, targets))
|
||||
for p in ch),
|
||||
@@ -183,7 +192,7 @@ def decide(runs, now, packs, *, charge_ok, sell_ok, trade_why, price_now,
|
||||
headroom_w, floor_pct, ceiling_pct, house_w, charging_now=False,
|
||||
blocked=False, done_charge=(), done_sell=(),
|
||||
targets=None, draining=False, wait=None,
|
||||
maint_charging=False) -> Tick:
|
||||
maint_charging=False, legs=None) -> Tick:
|
||||
"""This tick's ranges, roles and site ask.
|
||||
|
||||
`runs` is the kept `priceruns.RunPlan` or None (no fresh prices).
|
||||
@@ -200,7 +209,8 @@ def decide(runs, now, packs, *, charge_ok, sell_ok, trade_why, price_now,
|
||||
why) says no charge may start yet (SAFETY-135). `maint_charging` says a
|
||||
battery is in its maintenance CHARGE phase: no grid charge for the others
|
||||
either, same why, but a refusal probe goes on (MAINT-24,
|
||||
DECISIONS/MAINT-24-charge-first.md).
|
||||
DECISIONS/MAINT-24-charge-first.md). `legs` (TARIFF-30): `{name: bool}`,
|
||||
which batteries' own buy legs clear (`chargers()`), or None.
|
||||
"""
|
||||
plan_on = runs is not None and runs.on
|
||||
in_cheap = plan_on and runs.cheap.holds(now) and runs.charge_useful()
|
||||
@@ -208,8 +218,8 @@ def decide(runs, now, packs, *, charge_ok, sell_ok, trade_why, price_now,
|
||||
in_sell = plan_on and runs.sell is not None and runs.sell.holds(now)
|
||||
|
||||
why = None
|
||||
ch = chargers(packs, ceiling_pct, done_charge, targets, probe=True) \
|
||||
if in_cheap else []
|
||||
ch = chargers(packs, ceiling_pct, done_charge, targets, probe=True,
|
||||
legs=legs) if in_cheap else []
|
||||
if ch and draining:
|
||||
ch, why = [], "cycle"
|
||||
elif ch and maint_charging:
|
||||
|
||||
Reference in New Issue
Block a user