cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1289: full source

This commit is contained in:
Setti Solutions S.R.L committed 2026-11-08 16:35:35 +02:00
1 parent 165dda4479
commit 05802d6f87
57 files changed
+5928 -232

No files matched your search

+20 -11
View File
@@ -6,7 +6,9 @@ the agent's SQLite (<state dir>/training.db), rolling.
slots 15-minute means per asset the trainer uses (load.power,
pv.power, the planned devices' power, room.<r>.temp, the
heating's power, the outdoor thermometer, the grid meter and
the battery), from the agent's own 1-minute windows: per slot
the battery; the carriers': heat.power, the presence sources
room.<r>.occupied and person.<slug>.home, the chargers' plug
state, 0/1 each), from the agent's own 1-minute windows: per slot
the mean of the windows' means, as the cloud's trainer reads
telemetry (time_bucket('15 minutes') of avg(mean)). A slot the
agent did not see can be filled once from Home Assistant's
@@ -43,8 +45,11 @@ KEEP_FC_DAYS = 14
# the assets the trainer reads (building/trainlib.py: SITE_SERIES, ROOM_INPUTS,
# CONTROLLED; trainer.load_site), and the meter for the member's net draw
ASSETS = {"load.power", "pv.power", "weather.outside_temp", "heat.power", "heatpump.power", "heating.power",
"ac.power", "cooling.power", "ev.power", "grid.import_power", "grid.export_power", "battery.power"}
ASSET_RE = re.compile(r"^(room\.[^.]+\.temp|(heatpump|heating|ac|cooling|ev)\.[0-9]+\.power)$")
"ac.power", "cooling.power", "ev.power", "grid.import_power", "grid.export_power", "battery.power",
"ev.plugged", "dhw.heater_power"}
# a room's temperature and presence, a person at home, a part's power, a charger's plug state and power
ASSET_RE = re.compile(r"^(room\.[^.]+\.(temp|occupied)|person\.[^.]+\.home|(heatpump|heating|ac|cooling|ev)\.[0-9]+\.power"
r"|ev\.[0-9]+\.plugged|ev[0-9]+\.(plugged|power))$")
OBSERVED_PREF = ("cloud", "ha") # an observed hour: DWD's (with irradiation) before HA's entity
FORECAST_PREF = ("ha", "cloud") # a forecast hour: as the box forecasts (localml.merge_hours: HA's first)
@@ -74,6 +79,9 @@ class Store:
self._ids = {name: i for i, name in self.db.execute("SELECT id, name FROM assets")}
self.db.execute("CREATE TABLE IF NOT EXISTS weather (end_ts INTEGER NOT NULL, kind TEXT NOT NULL, source TEXT NOT NULL, "
"solar REAL, cloud REAL, temp REAL, issued INTEGER, PRIMARY KEY (end_ts, kind, source))")
# the wind (m/s; the heat model's, methods.md B13), 2026-11-06: an older file gets the column
if "wind" not in {r[1] for r in self.db.execute("PRAGMA table_info(weather)")}:
self.db.execute("ALTER TABLE weather ADD COLUMN wind REAL")
self.db.execute("CREATE TABLE IF NOT EXISTS fc_slots (series TEXT NOT NULL, slot INTEGER NOT NULL, source TEXT NOT NULL, "
"value REAL NOT NULL, issued INTEGER NOT NULL, PRIMARY KEY (series, slot, source))")
self.db.execute("CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)")
@@ -145,8 +153,8 @@ class Store:
# -- the weather -------------------------------------------------------------
def put_weather(self, kind: str, source: str, hours: list, issued: float | None = None) -> int:
"""Hourly records (pvforecast.Hour: end, solar_kwh_m2, cloud_pct,
temp_c). A forecast only for hours not over when it was made, the
newest such kept; an observation replaces what was there."""
temp_c, wind_ms). A forecast only for hours not over when it was
made, the newest such kept; an observation replaces what was there."""
rows = []
for h in hours:
end = int(h.end.timestamp())
@@ -156,10 +164,11 @@ class Store:
continue
if h.solar_kwh_m2 is None and h.cloud_pct is None and h.temp_c is None:
continue
rows.append((end, kind, source, h.solar_kwh_m2, h.cloud_pct, h.temp_c, int(issued) if issued else None))
rows.append((end, kind, source, h.solar_kwh_m2, h.cloud_pct, h.temp_c, int(issued) if issued else None,
getattr(h, "wind_ms", None)))
with self.lock:
self.db.executemany("INSERT OR REPLACE INTO weather (end_ts, kind, source, solar, cloud, temp, issued) "
"VALUES (?, ?, ?, ?, ?, ?, ?)", rows)
self.db.executemany("INSERT OR REPLACE INTO weather (end_ts, kind, source, solar, cloud, temp, issued, wind) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)", rows)
return len(rows)
def weather_hours(self, since: int, until: int, kind: str) -> list:
@@ -168,13 +177,13 @@ class Store:
from .pvforecast import Hour
pref = OBSERVED_PREF if kind == "observed" else FORECAST_PREF
with self.lock:
rows = self.db.execute("SELECT end_ts, source, solar, cloud, temp FROM weather WHERE kind = ? AND end_ts > ? "
rows = self.db.execute("SELECT end_ts, source, solar, cloud, temp, wind FROM weather WHERE kind = ? AND end_ts > ? "
"AND end_ts <= ?", (kind, int(since), int(until))).fetchall()
by: dict[int, tuple] = {}
for end, src, sol, cl, tc in rows:
for end, src, sol, cl, tc, wd in rows:
rank = pref.index(src) if src in pref else len(pref)
if end not in by or rank < by[end][0]:
by[end] = (rank, sol, cl, tc)
by[end] = (rank, sol, cl, tc, wd)
return [Hour(datetime.fromtimestamp(e, timezone.utc), *by[e][1:]) for e in sorted(by)]
def training_hours(self, since: int, until: int) -> list: