nastavitelny max sollar dle stridace (ulozeno v DB)
Some checks failed
CI and deploy / migration-check (push) Failing after 13s
CI and deploy / deploy (push) Has been skipped

This commit is contained in:
Dusan Vojacek
2026-05-25 11:25:29 +02:00
parent e06f76b9ff
commit c6074e9c74
13 changed files with 101 additions and 17 deletions

View File

@@ -65,7 +65,7 @@ DEYE_REGISTER_NAMES: dict[int, str] = {
142: "limit_control (0=selling first, 1=zero export to load, 2=zero export to CT)",
143: "export_limit_w (max export do sítě)",
145: "solar_sell (0=disabled, 1=enabled)",
340: "max_solar_power_w (strop DC PV A v W; součet nominal_power_wp řiditelných polí)",
340: "max_solar_power_w (strop DC PV A v W; cap z fn_inverter_pv_a_max_w / deye_reg340_max_solar_w)",
178: "control_board_special_1 (bits0-1: MI export cutoff disable=2 enable=3; bits4-5 peak shaving 32/48)",
148: "time_point_1_time",
149: "time_point_2_time",
@@ -157,11 +157,21 @@ def next_slot_hhmm() -> int:
return next_hour * 100 + next_min
def compute_pv_a_reg340_max_solar_w(cap_w: int, forecast_w: int, curtail_w: int) -> int:
def compute_pv_a_reg340_max_solar_w(
cap_w: int,
forecast_w: int,
curtail_w: int,
*,
min_w: int = 0,
) -> int:
"""Hodnota pro Deye reg 340 (max solar power, W) z capu a plánovaného curtailmentu pole A."""
if curtail_w <= 0:
return int(cap_w)
return max(0, min(int(cap_w), int(forecast_w) - int(curtail_w)))
raw = int(cap_w)
else:
raw = max(0, min(int(cap_w), int(forecast_w) - int(curtail_w)))
if raw > 0 and int(min_w) > 0:
return max(int(min_w), raw)
return raw
def _prague_minute_start_utc() -> datetime:

View File

@@ -30,8 +30,10 @@ class InverterConfig:
deye_tou_inactive_signature: str | None = None
deye_zero_export_mode: int = 1
deye_gen_microinverter_cutoff_enabled: bool = False
#: Součet nominal_power_wp controllable PV na invertoru; 0 = EMS nezapisuje reg 340.
#: Strop reg 340 (W) z fn_inverter_pv_a_max_w; 0 = EMS nezapisuje reg 340.
pv_a_cap_w: int = 0
#: Minimální hodnota reg 340 přijatá firmwarem (0 nebo např. 400 u staršího Deye).
pv_a_reg340_min_w: int = 0
#: True = EMS smí řídit Deye reg 340 (max solar power); z SQL `fn_site_has_active_green_bonus_pv(site_id)`.
deye_reg340_pv_a_control_enabled: bool = False

View File

@@ -38,6 +38,7 @@ async def export_setpoints(site_id: int, db: asyncpg.Connection) -> None:
try:
inv_for_pv = await _load_inverter_config(site_id, db)
cap_pv = int(inv_for_pv.pv_a_cap_w) if inv_for_pv is not None else 0
min_pv = int(inv_for_pv.pv_a_reg340_min_w) if inv_for_pv is not None else 0
reg340_en = (
bool(inv_for_pv.deye_reg340_pv_a_control_enabled)
if inv_for_pv is not None
@@ -49,12 +50,14 @@ async def export_setpoints(site_id: int, db: asyncpg.Connection) -> None:
mode,
pi_now,
pv_a_cap_w=cap_pv,
pv_a_reg340_min_w=min_pv,
reg340_pv_a_control_enabled=reg340_en,
)
sp_next = _build_setpoints(
mode,
pi_next,
pv_a_cap_w=cap_pv,
pv_a_reg340_min_w=min_pv,
reg340_pv_a_control_enabled=reg340_en,
)

View File

@@ -78,6 +78,7 @@ async def _load_inverter_config(
SELECT
ai.id, ai.code,
coalesce(ems.fn_inverter_pv_a_max_w(ai.id), 0) AS pv_a_cap_w,
coalesce(ai.deye_reg340_min_solar_w, 0) AS pv_a_reg340_min_w,
se.host, se.port, se.unit_id,
sgc.max_export_power_w,
sgc.max_import_power_w,
@@ -182,6 +183,7 @@ async def _load_inverter_config(
row["deye_gen_microinverter_cutoff_enabled"] or False
),
pv_a_cap_w=int(row["pv_a_cap_w"] or 0),
pv_a_reg340_min_w=int(row["pv_a_reg340_min_w"] or 0),
deye_reg340_pv_a_control_enabled=bool(
row["deye_reg340_pv_a_control_enabled"] or False
),

View File

@@ -97,6 +97,7 @@ def _build_setpoints(
pi: Any | None,
*,
pv_a_cap_w: int = 0,
pv_a_reg340_min_w: int = 0,
reg340_pv_a_control_enabled: bool = False,
) -> ControlSetpoints | None:
code = mode.mode_code
@@ -154,7 +155,10 @@ def _build_setpoints(
pv_a_allowed = None
else:
pv_a_allowed = compute_pv_a_reg340_max_solar_w(
int(pv_a_cap_w), forecast, curtail
int(pv_a_cap_w),
forecast,
curtail,
min_w=int(pv_a_reg340_min_w),
)
return ControlSetpoints(
battery_w=bat_w,