feat: add pvlib pv forecast provider (#1214)

Add a PV forecast provider that calculates the forecast using a PVLib system model
and weather forecast from the EOS weather forecast provider.

Additional module and inverter models can be easily added as the database
is build from PVLib and SAM databases and a bundled csv file.

The module model and inververt model names are provided by new endpoints
to be used in configuration.

The provider is based on the fantastic work of EMHASS. See
https://github.com/davidusb-geek/emhass/blob/master/src/emhass/forecast.py

A short description of the provider is added to the documentation.

Besides the new features there are the fixes and improvements:

* feat: improve EOSdash config page

* fix: kex_to_series for start_datetime

  Make key_to_series always start the series at start_datetime.

* fix: default provider for GENETIC and GENETIC0 optimization

  To make the default less dependent on internet servers (with API changes and
  availability issues) the default for PVForecast is set to PVForecastPVLib
  and for ElecPrice to ElecPriceFixed. The default weather provider is changed
  to OpenMeteo.

* fix: EOSdash display resampled prediction values

  Make EOSdash display resampled prediction values where  resampling fits to
  the prediction value type. Use bar width that fits to 15 minutes value samples.

* chore: add a UI hints system to EOSdash

  The UI hints system eases the definition of forms for configuration items.
  There are also forms for items in maps and lists. These forms allow to add and delete
  items to/ from  maps and lists. The forms ensure that all required fields of newly
  added items are filled.

* chore: Create an enum for valid optimization algorithms

* chore. Make config also provide the available energy management modes.

  Used for configuration hints.

* chore: Randomize default device id in configuration

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2026-08-07 13:13:17 +02:00
committed by GitHub
parent 9189fc890e
commit 894790f577
49 changed files with 29242 additions and 667 deletions
@@ -293,6 +293,24 @@ class GeneticOptimizationParameters(
# Assure predictions are uptodate
await cls.prediction.update_data()
try: # Try first - predition is also needed by the default PV forecast
array = await cls.prediction.key_to_array(
key="weather_temp_air",
start_datetime=parameter_start_datetime,
end_datetime=parameter_end_datetime,
interval=interval,
fill_method="ffill",
)
weather_temp_air = array.tolist()
except Exception as e:
logger.info(
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}: {}",
attempt,
e,
)
cls.config.weather.provider = "OpenMeteo"
# Retry
continue
try:
array = await cls.prediction.key_to_array(
key="pvforecast_ac_power",
@@ -311,36 +329,52 @@ class GeneticOptimizationParameters(
cls.config.merge_settings_from_dict(
{
"pvforecast": {
"provider": "PVForecastAkkudoktor",
"provider": "PVForecastPVLib",
"max_planes": 4,
"planes": [
{
"peakpower": 5.0,
"surface_tilt": 7,
"surface_azimuth": 170,
"surface_tilt": 7,
"userhorizon": [20, 27, 22, 20],
"peakpower": 5.0,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 10000,
"modules_per_string": 12,
"strings_per_inverter": 1,
},
{
"peakpower": 4.8,
"surface_azimuth": 90,
"surface_tilt": 7,
"surface_azimuth": 90,
"userhorizon": [30, 30, 30, 50],
"peakpower": 4.8,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 10000,
"modules_per_string": 12,
"strings_per_inverter": 1,
},
{
"peakpower": 1.4,
"surface_azimuth": 140,
"surface_tilt": 60,
"surface_azimuth": 140,
"userhorizon": [60, 30, 0, 30],
"peakpower": 1.4,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 2000,
"modules_per_string": 5,
"strings_per_inverter": 1,
},
{
"peakpower": 1.6,
"surface_azimuth": 185,
"surface_tilt": 45,
"surface_azimuth": 185,
"userhorizon": [45, 25, 30, 60],
"peakpower": 1.6,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 1400,
"modules_per_string": 4,
"strings_per_inverter": 1,
},
],
},
@@ -363,7 +397,24 @@ class GeneticOptimizationParameters(
attempt,
e,
)
cls.config.elecprice.provider = "ElecPriceAkkudoktor"
cls.config.merge_settings_from_dict(
{
"elecprice": {
"elecpricefixed": {
"time_windows": {
"windows": [
{
"duration": "1 day",
"start_time": "00:00:00.000000",
"value": 0.288,
}
]
}
},
"provider": "ElecPriceFixed",
},
},
)
# Retry
continue
try:
@@ -420,24 +471,6 @@ class GeneticOptimizationParameters(
)
# Retry
continue
try:
array = await cls.prediction.key_to_array(
key="weather_temp_air",
start_datetime=parameter_start_datetime,
end_datetime=parameter_end_datetime,
interval=interval,
fill_method="ffill",
)
weather_temp_air = array.tolist()
except Exception as e:
logger.info(
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}: {}",
attempt,
e,
)
cls.config.weather.provider = "BrightSky"
# Retry
continue
# Add device data
@@ -284,6 +284,24 @@ class Genetic0OptimizationParameters(
# Assure predictions are uptodate
await cls.prediction.update_data()
try: # Try first - predition is also needed by the default PV forecast
array = await cls.prediction.key_to_array(
key="weather_temp_air",
start_datetime=parameter_start_datetime,
end_datetime=parameter_end_datetime,
interval=interval,
fill_method="ffill",
)
weather_temp_air = array.tolist()
except Exception as e:
logger.info(
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}: {}",
attempt,
e,
)
cls.config.weather.provider = "OpenMeteo"
# Retry
continue
try:
array = await cls.prediction.key_to_array(
key="pvforecast_ac_power",
@@ -302,36 +320,52 @@ class Genetic0OptimizationParameters(
cls.config.merge_settings_from_dict(
{
"pvforecast": {
"provider": "PVForecastAkkudoktor",
"provider": "PVForecastPVLib",
"max_planes": 4,
"planes": [
{
"peakpower": 5.0,
"surface_tilt": 7,
"surface_azimuth": 170,
"surface_tilt": 7,
"userhorizon": [20, 27, 22, 20],
"peakpower": 5.0,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 10000,
"modules_per_string": 12,
"strings_per_inverter": 1,
},
{
"peakpower": 4.8,
"surface_azimuth": 90,
"surface_tilt": 7,
"surface_azimuth": 90,
"userhorizon": [30, 30, 30, 50],
"peakpower": 4.8,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 10000,
"modules_per_string": 12,
"strings_per_inverter": 1,
},
{
"peakpower": 1.4,
"surface_azimuth": 140,
"surface_tilt": 60,
"surface_azimuth": 140,
"userhorizon": [60, 30, 0, 30],
"peakpower": 1.4,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 2000,
"modules_per_string": 5,
"strings_per_inverter": 1,
},
{
"peakpower": 1.6,
"surface_azimuth": 185,
"surface_tilt": 45,
"surface_azimuth": 185,
"userhorizon": [45, 25, 30, 60],
"peakpower": 1.6,
"module_model": "AXITEC_AC_410MH_144S",
"inverter_model": "Sungrow__SH25T",
"inverter_paco": 1400,
"modules_per_string": 4,
"strings_per_inverter": 1,
},
],
},
@@ -354,7 +388,24 @@ class Genetic0OptimizationParameters(
attempt,
e,
)
cls.config.elecprice.provider = "ElecPriceAkkudoktor"
cls.config.merge_settings_from_dict(
{
"elecprice": {
"elecpricefixed": {
"time_windows": {
"windows": [
{
"duration": "1 day",
"start_time": "00:00:00.000000",
"value": 0.288,
}
]
}
},
"provider": "ElecPriceFixed",
},
},
)
# Retry
continue
try:
@@ -411,24 +462,6 @@ class Genetic0OptimizationParameters(
)
# Retry
continue
try:
array = await cls.prediction.key_to_array(
key="weather_temp_air",
start_datetime=parameter_start_datetime,
end_datetime=parameter_end_datetime,
interval=interval,
fill_method="ffill",
)
weather_temp_air = array.tolist()
except Exception as e:
logger.info(
"No weather forecast data available - defaulting to demo data. Parameter preparation attempt {}: {}",
attempt,
e,
)
cls.config.weather.provider = "BrightSky"
# Retry
continue
# Add device data
+19 -11
View File
@@ -1,3 +1,4 @@
from enum import StrEnum
from typing import Optional
from pydantic import Field, computed_field
@@ -13,22 +14,29 @@ from akkudoktoreos.optimization.genetic.geneticsettings import GeneticCommonSett
from akkudoktoreos.utils.datetimeutil import DateTime
def optimization_algorithms() -> list[str]:
"""Valid optimization algorithms."""
# Return static built-in optimization algorithms.
return [
"GENETIC",
"GENETIC0",
]
class OptimizationAlgorithm(StrEnum):
"""Optimization Algorithm."""
GENETIC = "GENETIC"
GENETIC0 = "GENETIC0"
def optimization_default_algorithm() -> OptimizationAlgorithm:
"""Provide default optimization algorithm."""
return OptimizationAlgorithm.GENETIC
class OptimizationCommonSettings(SettingsBaseModel):
"""General Optimization Configuration."""
algorithm: str = Field(
default="GENETIC",
algorithm: OptimizationAlgorithm = Field(
default_factory=optimization_default_algorithm,
json_schema_extra={
"description": "The optimization algorithm. Defaults to GENETIC",
"description": (
f"Optimization algorithm "
f"[{' | '.join(mode.value for mode in OptimizationAlgorithm)}]. "
f"Defaults to {optimization_default_algorithm()}."
),
"examples": ["GENETIC", "GENETIC0"],
},
)
@@ -54,7 +62,7 @@ class OptimizationCommonSettings(SettingsBaseModel):
@property
def algorithms(self) -> list[str]:
"""Available optimization algorithms."""
return optimization_algorithms()
return [algo.value for algo in OptimizationAlgorithm]
@computed_field # type: ignore[prop-decorator]
@property