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:
@@ -267,6 +267,55 @@ def threshold_eur_kwh(opts: dict) -> float:
|
||||
return v
|
||||
|
||||
|
||||
# TARIFF-30. A unit's own losses are the whole reason the buy leg is refused.
|
||||
IDLE_LOSSES = ("the price gap does not cover the energy these batteries lose "
|
||||
"on the way in and out")
|
||||
|
||||
|
||||
def leg_clears(v, eta) -> bool:
|
||||
"""TARIFF-30. Does ONE unit's buy leg clear on the verdict `v`?
|
||||
|
||||
With no efficiency set (`eta` None) the verdict itself is the answer, as
|
||||
today. With one set, the cheap hour is priced at `price / eta` and the gap
|
||||
to the dear hour must still reach what this cycle needs
|
||||
(`v.required_spread_eur_kwh`). That figure is the cycle cost widened for
|
||||
doubt and is NOT widened again for the loss: `eta` is a configured number,
|
||||
not price uncertainty. The sell leg has no `eta`. Rounded to six places like
|
||||
the verdict's own spread, so the boundary agrees with it."""
|
||||
if eta is None:
|
||||
return True
|
||||
net = round(float(v.dearest.eur_per_kwh)
|
||||
- float(v.cheapest.eur_per_kwh) / float(eta), 6)
|
||||
return net >= float(v.required_spread_eur_kwh)
|
||||
|
||||
|
||||
def clearing(plan, now: datetime, *, min_spread_eur_kwh, uncertainty, etas):
|
||||
"""TARIFF-30. `{name: bool}`: which units' own buy legs clear, or None.
|
||||
|
||||
`etas` is `{name: round_trip_eff or None}`. None is returned when nobody
|
||||
has an efficiency (nothing to decide: today's behaviour) and when the
|
||||
verdict does not allow a trade at all (the caller's own gate speaks). The
|
||||
peak guard is asked as clear: the interlock is the caller's, and an
|
||||
efficiency can only narrow a verdict, never widen it."""
|
||||
if plan is None or not any(e is not None for e in etas.values()):
|
||||
return None
|
||||
verdict = plan.arbitrage(peak_guard_active=False,
|
||||
min_spread_eur_kwh=min_spread_eur_kwh,
|
||||
uncertainty=uncertainty, now=now)
|
||||
return verdict.match(
|
||||
refused=lambda _v: None,
|
||||
allowed=lambda v: {n: leg_clears(v, e) for n, e in etas.items()})
|
||||
|
||||
|
||||
def idle_for_losses(decision: ArbitrageDecision) -> ArbitrageDecision:
|
||||
"""TARIFF-30. `decision` (an IDLE_NO_SIZE refusal) as the efficiency
|
||||
refusal it really is, with the same numbers: no unit's own leg cleared, so
|
||||
the buy was sized at 0 W. Still no claim (never a 0 W one)."""
|
||||
return _idle(IDLE_LOSSES, spread=decision.spread_eur_kwh,
|
||||
required=decision.required_eur_kwh,
|
||||
price=decision.price_now_eur_kwh)
|
||||
|
||||
|
||||
def weather_uncertainty(modes_on: bool, solar_fc, held: bool = False) -> frozenset:
|
||||
"""The "no weather" doubt (x1.5) a trade must clear. TARIFF-24.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user