cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.650: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-04 03:22:07 +02:00
1 parent 85edd56ec8
commit 3edd015039
20 files changed
+2021 -35

No files matched your search

+48 -7
View File
@@ -459,9 +459,8 @@ def plan(s: dict, time_limit: float = 30.0) -> dict:
kind, v = m.devices.get(d["id"], (d["kind"], None))
entries = []
for t in range(T):
e = _entry(d, kind, v, t, x, s, pi)
if e is not None and (not entries or (entries[-1]["set"], entries[-1].get("grid")) !=
(e["set"], e.get("grid"))):
e = _entry(d, kind, v, t, x, s, pi, (x(m.gin[t]), x(m.gout[t])))
if e is not None and (not entries or _key(entries[-1]) != _key(e)):
entries.append({"t": start + t * step, **e})
devices[d["id"]] = entries
energy = sum(m.eur_wh(t, pi[t]) * x(m.gin[t]) - m.eur_wh(t, s["price_export"][t]) * x(m.gout[t])
@@ -550,8 +549,34 @@ def flexibility(m, x) -> dict:
return {"grid_w": grid, "shed_w": [round(min(sh, g)) for sh, g in zip(shed, grid)]}
def _entry(d, kind, v, t, x, s, pi):
"""What a device is to do in step t, and why (a few words)."""
def _charge_why(pi, t) -> str:
"""Why the battery charges from the grid: "cheap grid power" only in the
cheapest quarter of the horizon's prices and 10 % below their mean
(sim-munich-1 called 47.6 ct cheap: an evening day-ahead price under a
50 ct flat); else what it is for, the dearer hours later."""
p25 = sorted(pi)[len(pi) // 4]
mean = sum(pi) / len(pi)
if pi[t] <= p25 + 1e-9 and pi[t] < 0.9 * mean:
return f"cheap grid power ({pi[t]:.1f} ct)"
later = pi[t + 1:]
if later and max(later) > pi[t]:
k = t + 1 + later.index(max(later))
return f"charge for dearer hours later ({pi[t]:.1f} ct now, {pi[k]:.1f} ct in {(k - t) * 15 // 60} h)"
return f"charge from the grid ({pi[t]:.1f} ct)"
def _key(e) -> tuple:
"""What makes a plan entry a change: a battery's self-consumption is one
state whatever its power (it follows the house)."""
return ("auto",) if e.get("auto") else (e["set"], e.get("grid"))
GRID_ZERO_W = 50.0 # the meter's import and export below this: the battery balances the house
def _entry(d, kind, v, t, x, s, pi, grid_w=(1e9, 1e9)):
"""What a device is to do in step t, and why (a few words). grid_w:
the meter's planned import and export in t."""
occ = s["occupied"][t]
if v is None:
return None
@@ -561,7 +586,7 @@ def _entry(d, kind, v, t, x, s, pi):
surplus = s["pv_w"][t] - s["load_w"][t]
grid = net > max(0.0, surplus) + 50
if net > 0:
why = f"cheap grid power ({pi[t]:.1f} ct)" if grid else "PV surplus"
why = _charge_why(pi, t) if grid else "PV surplus"
elif net < 0:
mean = sum(pi) / len(pi)
# "peak" only well above the horizon's average (Sim Munich: a plain
@@ -570,6 +595,13 @@ def _entry(d, kind, v, t, x, s, pi):
f"above the average price ({pi[t]:.1f} ct, average {mean:.1f})")
else:
why = "hold"
if grid_w[0] < GRID_ZERO_W and grid_w[1] < GRID_ZERO_W and not grid:
# what the battery does is what its own self-consumption mode does:
# the inverter follows the house (no setpoint to chase the PV or
# the load every quarter hour)
return {"set": net, "grid": False, "auto": True,
"why": "self-consumption: the battery covers the house" if net <= 0 else
"self-consumption: PV surplus into the battery"}
return {"set": net, "grid": grid, "why": why}
if kind in ("heating", "cooling"):
temp = x(v["temp"][t])
@@ -590,7 +622,16 @@ def _entry(d, kind, v, t, x, s, pi):
return {"set": "off", "why": "off: cool enough or away"}
return {"set": target, "why": "pre-cool before someone is home" if not occ and ahead else "keep cool"}
if pw < 50:
return {"set": target, "why": "setback: away or night" if not occ else "warm enough"}
# no heat planned: the thermostat at what the room must keep (the
# comfort or setback target in the bounds), not at the room's
# predicted temperature, which a thermostat holds by heating; the
# room never cooled as planned, every next plan started from it
# again (a replay of a munich-1 day: kept at 24 °C all evening)
occ1 = s["occupied"][min(t + 1, s["steps"] - 1)]
p = d["params"]
want = float(p["comfort_c"]) if occ1 else float(p["setback_c"])
floor_t = min(max(math.floor(want * 2) / 2, math.ceil(lo * 2) / 2), math.floor(hi * 2) / 2)
return {"set": min(target, floor_t), "why": "setback: away or night" if not occ else "warm enough"}
return {"set": target, "why": f"pre-heat while power is cheap ({pi[t]:.1f} ct)" if not occ and ahead
else "keep the room warm"}
if kind == "ev":