mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
feat(devices): add inverter profiles
An inverter profile describes the technical data of an inverter model: its nominal AC power, the DC→AC and AC→DC efficiency curves over the load fraction (AC power relative to the nominal power), the AC charge power limit of the model, whether that limit also limits PV charging, and an optional power derating over the ambient temperature. Curves are read linearly and clamped at their ends, so every lookup yields a value. The packaged profile generic-hybrid has typical hybrid inverter efficiencies, no nominal power (the inverter device has to provide it) and full power up to 45 degC. Inverter settings name their profile (inverter_profile, default generic-hybrid) and hold the differences of the unit in profile_adjustment: nominal_power_w (replaces the profile value, required for a generic profile), max_power_w and max_ac_charge_power_w (installation limits that can only lower; an AC charge limit of 0 disables AC charging). The effective parameters are resolved at the ambient temperature of the inverter, given by the new measurement key <device_id>-temperature-degc (45 degC without a fresh value); the power derating lowers the maximum power and the AC charge limit. Optimization parameters are always valid: the GENETIC and GENETIC0 parameter preparation resolve the inverter with resolve_current_operating_parameters_or_defaults, which never raises. An unusable profile gives the generic-hybrid profile, a missing nominal power the fallback of 10000 W, an inverter derated to zero power the parameters at 45 degC, and no usable profile at all the profile adjustment with constant efficiency; each is logged as error. The GENETIC inverter takes the AC→DC efficiency curve of the profile, solved exactly on each linear piece of the curve (about 2 % longer runs); GENETIC0 keeps constant efficiencies and no longer replaces the configured inverters with the demo inverter; a battery, electric vehicle or inverter that cannot be prepared is left out of the GENETIC0 run, never replaced by a demo device. Configurations migrate: max_power_w becomes profile_adjustment.nominal_power_w, max_ac_charge_power_w moves into the adjustment, an ac_to_dc_efficiency of 0 keeps AC charging disabled, and the efficiency fields are dropped with an error log, as for batteries, so the profile efficiencies apply. Home Assistant config paths follow. Additional changes - Move the curve algorithms of the battery profile into profilecurve, so battery and inverter profiles share them; the battery profile keeps its document format and classes. - Move ProfileBaseModel, the strict base of profile documents, into profilestore. - Serve inverter profiles through the profile REST API. Refuse to delete a profile that a configured device uses and that has no packaged profile to revert to (409). - Share the measurement access of the device settings in devicemeasurement. - Rename check_battery_profiles to check_device_profiles; the device profile check at configuration setup covers inverters, too. - Document inverter profiles, their configuration, defaults and sharing; regenerate the configuration and OpenAPI documentation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e255f987bf
commit
faf37abfe7
@@ -219,7 +219,11 @@ class ConfigOptimizationRequest(
|
||||
device = groups["inverters"][0]
|
||||
if device.battery_id != (battery.device_id if battery else None):
|
||||
raise ValueError("Inverter battery_id must match the configured battery.")
|
||||
inverter = device.to_genetic_param()
|
||||
# The derating of the inverter profile applies at the measured
|
||||
# ambient temperature, 45 degC without a measurement.
|
||||
inverter = device.to_genetic_param(
|
||||
await device.resolve_current_operating_parameters_or_defaults(observation_time)
|
||||
)
|
||||
if inverter is None:
|
||||
raise ValueError("Configure an inverter to model PV and grid energy flows.")
|
||||
appliances = [device.to_genetic_param() for device in groups["home_appliances"]]
|
||||
|
||||
@@ -26,6 +26,7 @@ from akkudoktoreos.devices.devicesabc import (
|
||||
BatteryOperationMode,
|
||||
)
|
||||
from akkudoktoreos.devices.genetic.battery import Battery
|
||||
from akkudoktoreos.devices.genetic.inverter import InverterParameters
|
||||
from akkudoktoreos.optimization.genetic.geneticdevices import GeneticParametersBaseModel
|
||||
from akkudoktoreos.optimization.genetic.geneticparams import (
|
||||
GeneticOptimizationParameters,
|
||||
@@ -593,6 +594,26 @@ class GeneticSolution(ConfigMixin, GeneticParametersBaseModel):
|
||||
# Fallback → safe idle
|
||||
return BatteryOperationMode.IDLE, 1.0
|
||||
|
||||
def _inverter_parameters_list(
|
||||
self, parameters: Optional[GeneticOptimizationParameters]
|
||||
) -> list[InverterParameters]:
|
||||
"""Return the inverter parameters the solution was computed with, as a list.
|
||||
|
||||
Without stored parameters, the first configured inverter is resolved from
|
||||
its inverter profile. An inverter that cannot be resolved is treated as
|
||||
no inverter; the configuration check already reported it.
|
||||
"""
|
||||
if parameters is not None:
|
||||
return [parameters.inverter] if parameters.inverter is not None else []
|
||||
inverters = self.config.devices.inverters or {}
|
||||
if not inverters:
|
||||
return []
|
||||
try:
|
||||
return [list(inverters.values())[0].to_genetic_param()]
|
||||
except ValueError as exc:
|
||||
logger.debug(f"Inverter not resolvable for the solution: {exc}")
|
||||
return []
|
||||
|
||||
def _soc_clamped_operation_factors(
|
||||
self,
|
||||
ac_charge: float,
|
||||
@@ -649,13 +670,7 @@ class GeneticSolution(ConfigMixin, GeneticParametersBaseModel):
|
||||
if headroom_wh <= 0.0:
|
||||
effective_ac = 0.0
|
||||
else:
|
||||
inv_list = (
|
||||
[parameters.inverter]
|
||||
if parameters is not None and parameters.inverter is not None
|
||||
else list((self.config.devices.inverters or {}).values())
|
||||
if parameters is None
|
||||
else []
|
||||
)
|
||||
inv_list = self._inverter_parameters_list(parameters)
|
||||
ac_to_dc_eff = float(inv_list[0].ac_to_dc_efficiency) if inv_list else 1.0
|
||||
max_ac_cp_w = (
|
||||
float(inv_list[0].max_ac_charge_power_w)
|
||||
|
||||
@@ -37,7 +37,6 @@ from akkudoktoreos.devices.genetic0.genetic0homeappliance import (
|
||||
Genetic0HomeApplianceParameters,
|
||||
)
|
||||
from akkudoktoreos.devices.genetic0.genetic0inverter import Genetic0InverterParameters
|
||||
from akkudoktoreos.devices.settings.batterysettings import BatteriesCommonSettings
|
||||
from akkudoktoreos.optimization.genetic0.genetic0abc import Genetic0ParametersBaseModel
|
||||
from akkudoktoreos.optimization.genetic.forecast import bounded_forecast_array
|
||||
from akkudoktoreos.utils.datetimeutil import DateTime, to_duration
|
||||
@@ -47,12 +46,15 @@ from akkudoktoreos.utils.datetimeutil import DateTime, to_duration
|
||||
# StartMixin - Creates circular dependency with ems.py
|
||||
|
||||
|
||||
# Demo devices: used if no device is configured, and for this run only if the
|
||||
# configured device cannot be prepared.
|
||||
# Demo devices: used if no device of a kind is configured.
|
||||
DEMO_BATTERY_SETTINGS: dict = {
|
||||
"device_id": "battery1",
|
||||
"profile_adjustment": {"nominal_capacity_wh": 8000},
|
||||
}
|
||||
DEMO_INVERTER_SETTINGS: dict = {
|
||||
"device_id": "inverter1",
|
||||
"profile_adjustment": {"nominal_power_w": 10000},
|
||||
}
|
||||
DEMO_ELECTRIC_VEHICLE_SETTINGS: dict = {
|
||||
"device_id": "ev1",
|
||||
"profile_adjustment": {"nominal_capacity_wh": 50000},
|
||||
@@ -603,47 +605,45 @@ class Genetic0OptimizationParameters(
|
||||
) = await battery_config.resolve_current_operating_parameters_or_defaults()
|
||||
battery_params = battery_config.to_genetic0_pv_bat_param(battery_parameters)
|
||||
except Exception as e:
|
||||
# Never cancel the run and never change the user's configuration:
|
||||
# optimize with the demo battery for this run only.
|
||||
# Never cancel the run, never change the user's configuration and
|
||||
# never invent a device: optimize without this battery.
|
||||
logger.error(
|
||||
"Battery '{}' cannot be prepared for the optimization: {} "
|
||||
"Using the demo battery for this run.",
|
||||
"The battery is left out of this run.",
|
||||
battery_config.device_id,
|
||||
e,
|
||||
)
|
||||
battery_config = BatteriesCommonSettings(**DEMO_BATTERY_SETTINGS)
|
||||
battery_parameters, _ = (
|
||||
battery_config.resolve_operating_parameters_or_defaults()
|
||||
)
|
||||
battery_params = battery_config.to_genetic0_pv_bat_param(battery_parameters)
|
||||
# Levelized cost of ownership
|
||||
if battery_config.levelized_cost_of_storage_amt_kwh is None:
|
||||
logger.info(
|
||||
"No battery device LCOS data available - defaulting to 0 [amount/kWh]. Parameter preparation attempt {}.",
|
||||
attempt,
|
||||
)
|
||||
battery_config.levelized_cost_of_storage_amt_kwh = 0
|
||||
battery_lcos_kwh = battery_config.levelized_cost_of_storage_amt_kwh
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = await cls._nearest_soc_factor(
|
||||
battery_config.measurement_key_soc_factor, ems.observation_datetime
|
||||
)
|
||||
if initial_soc_factor > 1.0 or initial_soc_factor < 0.0:
|
||||
logger.error(
|
||||
f"Invalid battery initial SoC factor {initial_soc_factor} - defaulting to 0.0."
|
||||
battery_params = None
|
||||
battery_lcos_kwh = 0
|
||||
if battery_params is not None:
|
||||
# Levelized cost of ownership
|
||||
if battery_config.levelized_cost_of_storage_amt_kwh is None:
|
||||
logger.info(
|
||||
"No battery device LCOS data available - defaulting to 0 [amount/kWh]. Parameter preparation attempt {}.",
|
||||
attempt,
|
||||
)
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
f"No battery device SoC data (measurement key = '{battery_config.measurement_key_soc_factor}') available - defaulting to 0."
|
||||
)
|
||||
initial_soc_percentage = 0
|
||||
battery_params.initial_soc_percentage = initial_soc_percentage
|
||||
battery_config.levelized_cost_of_storage_amt_kwh = 0
|
||||
battery_lcos_kwh = battery_config.levelized_cost_of_storage_amt_kwh
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = await cls._nearest_soc_factor(
|
||||
battery_config.measurement_key_soc_factor, ems.observation_datetime
|
||||
)
|
||||
if initial_soc_factor > 1.0 or initial_soc_factor < 0.0:
|
||||
logger.error(
|
||||
f"Invalid battery initial SoC factor {initial_soc_factor} - defaulting to 0.0."
|
||||
)
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
f"No battery device SoC data (measurement key = '{battery_config.measurement_key_soc_factor}') available - defaulting to 0."
|
||||
)
|
||||
initial_soc_percentage = 0
|
||||
battery_params.initial_soc_percentage = initial_soc_percentage
|
||||
|
||||
# Electric Vehicles
|
||||
# -----------------
|
||||
@@ -673,44 +673,37 @@ class Genetic0OptimizationParameters(
|
||||
ev_parameters
|
||||
)
|
||||
except Exception as e:
|
||||
# Never cancel the run and never change the user's configuration:
|
||||
# optimize with the demo electric vehicle for this run only.
|
||||
# Never cancel the run, never change the user's configuration and
|
||||
# never invent a device: optimize without this electric vehicle.
|
||||
logger.error(
|
||||
"Electric vehicle '{}' cannot be prepared for the optimization: {} "
|
||||
"Using the demo electric vehicle for this run.",
|
||||
"The electric vehicle is left out of this run.",
|
||||
electric_vehicle_config.device_id,
|
||||
e,
|
||||
)
|
||||
electric_vehicle_config = BatteriesCommonSettings(
|
||||
**DEMO_ELECTRIC_VEHICLE_SETTINGS
|
||||
)
|
||||
(
|
||||
ev_parameters,
|
||||
_,
|
||||
) = electric_vehicle_config.resolve_operating_parameters_or_defaults()
|
||||
electric_vehicle_params = electric_vehicle_config.to_genetic0_ev_bat_param(
|
||||
ev_parameters
|
||||
)
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = await cls._nearest_soc_factor(
|
||||
electric_vehicle_config.measurement_key_soc_factor, ems.observation_datetime
|
||||
)
|
||||
if initial_soc_factor > 1.0 or initial_soc_factor < 0.0:
|
||||
logger.error(
|
||||
f"Invalid electric vehicle initial SoC factor {initial_soc_factor} - defaulting to 0.0."
|
||||
electric_vehicle_params = None
|
||||
if electric_vehicle_params is not None:
|
||||
# Initial SOC
|
||||
try:
|
||||
initial_soc_factor = await cls._nearest_soc_factor(
|
||||
electric_vehicle_config.measurement_key_soc_factor,
|
||||
ems.observation_datetime,
|
||||
)
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
f"No electric vehicle device SoC data (measurement key = '{electric_vehicle_config.measurement_key_soc_factor}') available - defaulting to 0."
|
||||
)
|
||||
initial_soc_percentage = 0
|
||||
electric_vehicle_params.initial_soc_percentage = initial_soc_percentage
|
||||
if initial_soc_factor > 1.0 or initial_soc_factor < 0.0:
|
||||
logger.error(
|
||||
f"Invalid electric vehicle initial SoC factor {initial_soc_factor} - defaulting to 0.0."
|
||||
)
|
||||
initial_soc_factor = 0.0
|
||||
# genetic parameter is 0..100 as int
|
||||
initial_soc_percentage = int(initial_soc_factor * 100)
|
||||
except Exception:
|
||||
initial_soc_percentage = None
|
||||
if initial_soc_percentage is None:
|
||||
logger.info(
|
||||
f"No electric vehicle device SoC data (measurement key = '{electric_vehicle_config.measurement_key_soc_factor}') available - defaulting to 0."
|
||||
)
|
||||
initial_soc_percentage = 0
|
||||
electric_vehicle_params.initial_soc_percentage = initial_soc_percentage
|
||||
|
||||
# Inverters
|
||||
# ---------
|
||||
@@ -724,30 +717,27 @@ class Genetic0OptimizationParameters(
|
||||
logger.info("No inverter device data available - defaulting to demo data.")
|
||||
cls.config.devices.inverters = {
|
||||
"inverter1": {
|
||||
"device_id": "inverter1",
|
||||
"max_power_w": 10000,
|
||||
**DEMO_INVERTER_SETTINGS,
|
||||
"battery_id": battery_config.device_id,
|
||||
},
|
||||
}
|
||||
# Take first inverter
|
||||
inverter_config = list(cls.config.devices.inverters.values())[0]
|
||||
try:
|
||||
# Take first inverter
|
||||
inverter_config = list(cls.config.devices.inverters.values())[0]
|
||||
inverter_params = inverter_config.to_genetic0_param()
|
||||
# A configuration error gives default values, reported as error.
|
||||
inverter_params = inverter_config.to_genetic0_param(
|
||||
await inverter_config.resolve_current_operating_parameters_or_defaults()
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"No inverter device data available - defaulting to demo data. Parameter preparation attempt {}: {}",
|
||||
attempt,
|
||||
# Never cancel the run, never change the user's configuration and
|
||||
# never invent a device: optimize without this inverter.
|
||||
logger.error(
|
||||
"Inverter '{}' cannot be prepared for the optimization: {} "
|
||||
"The inverter is left out of this run.",
|
||||
inverter_config.device_id,
|
||||
e,
|
||||
)
|
||||
cls.config.devices.inverters = {
|
||||
"inverter1": {
|
||||
"device_id": "inverter1",
|
||||
"max_power_w": 10000,
|
||||
"battery_id": battery_config.device_id,
|
||||
},
|
||||
}
|
||||
# Retry
|
||||
continue
|
||||
inverter_params = None
|
||||
|
||||
# Home Appliances
|
||||
# ---------------
|
||||
|
||||
@@ -26,6 +26,7 @@ from akkudoktoreos.devices.devicesabc import (
|
||||
BatteryOperationMode,
|
||||
)
|
||||
from akkudoktoreos.devices.genetic0.genetic0battery import Genetic0Battery
|
||||
from akkudoktoreos.devices.genetic0.genetic0inverter import Genetic0InverterParameters
|
||||
from akkudoktoreos.optimization.genetic0.genetic0devices import (
|
||||
Genetic0ParametersBaseModel,
|
||||
)
|
||||
@@ -507,6 +508,26 @@ class Genetic0Solution(ConfigMixin, Genetic0ParametersBaseModel):
|
||||
# Fallback → safe idle
|
||||
return BatteryOperationMode.IDLE, 1.0
|
||||
|
||||
def _inverter_parameters(
|
||||
self, parameters: Optional[Genetic0OptimizationParameters]
|
||||
) -> Optional[Genetic0InverterParameters]:
|
||||
"""Return the inverter parameters the solution was computed with.
|
||||
|
||||
Without stored parameters, the first configured inverter is resolved from
|
||||
its inverter profile. An inverter that cannot be resolved is treated as
|
||||
no inverter; the configuration check already reported it.
|
||||
"""
|
||||
if parameters is not None:
|
||||
return parameters.inverter
|
||||
inverters = self.config.devices.inverters or {}
|
||||
if not inverters:
|
||||
return None
|
||||
try:
|
||||
return list(inverters.values())[0].to_genetic0_param()
|
||||
except ValueError as exc:
|
||||
logger.debug(f"Inverter not resolvable for the solution: {exc}")
|
||||
return None
|
||||
|
||||
def _soc_clamped_operation_factors(
|
||||
self,
|
||||
ac_charge: float,
|
||||
@@ -565,8 +586,7 @@ class Genetic0Solution(ConfigMixin, Genetic0ParametersBaseModel):
|
||||
if headroom_wh <= 0.0:
|
||||
effective_ac = 0.0
|
||||
else:
|
||||
inv_dict = self.config.devices.inverters
|
||||
inv = list(inv_dict.values())[0] if inv_dict else None
|
||||
inv = self._inverter_parameters(parameters)
|
||||
ac_to_dc_eff = float(inv.ac_to_dc_efficiency) if inv else 1.0
|
||||
max_ac_cp_w = (
|
||||
float(inv.max_ac_charge_power_w)
|
||||
|
||||
Reference in New Issue
Block a user