mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-03-30 10:16:16 +00:00
feat: add Home Assistant and NodeRED adapters (#764)
Adapters for Home Assistant and NodeRED integration are added. Akkudoktor-EOS can now be run as Home Assistant add-on and standalone. As Home Assistant add-on EOS uses ingress to fully integrate the EOSdash dashboard in Home Assistant. The fix includes several bug fixes that are not directly related to the adapter implementation but are necessary to keep EOS running properly and to test and document the changes. * fix: development version scheme The development versioning scheme is adaptet to fit to docker and home assistant expectations. The new scheme is x.y.z and x.y.z.dev<hash>. Hash is only digits as expected by home assistant. Development version is appended by .dev as expected by docker. * fix: use mean value in interval on resampling for array When downsampling data use the mean value of all values within the new sampling interval. * fix: default battery ev soc and appliance wh Make the genetic simulation return default values for the battery SoC, electric vehicle SoC and appliance load if these assets are not used. * fix: import json string Strip outer quotes from JSON strings on import to be compliant to json.loads() expectation. * fix: default interval definition for import data Default interval must be defined in lowercase human definition to be accepted by pendulum. * fix: clearoutside schema change * feat: add adapters for integrations Adapters for Home Assistant and NodeRED integration are added. Akkudoktor-EOS can now be run as Home Assistant add-on and standalone. As Home Assistant add-on EOS uses ingress to fully integrate the EOSdash dashboard in Home Assistant. * feat: allow eos to be started with root permissions and drop priviledges Home assistant starts all add-ons with root permissions. Eos now drops root permissions if an applicable user is defined by paramter --run_as_user. The docker image defines the user eos to be used. * feat: make eos supervise and monitor EOSdash Eos now not only starts EOSdash but also monitors EOSdash during runtime and restarts EOSdash on fault. EOSdash logging is captured by EOS and forwarded to the EOS log to provide better visibility. * feat: add duration to string conversion Make to_duration to also return the duration as string on request. * chore: Use info logging to report missing optimization parameters In parameter preparation for automatic optimization an error was logged for missing paramters. Log is now down using the info level. * chore: make EOSdash use the EOS data directory for file import/ export EOSdash use the EOS data directory for file import/ export by default. This allows to use the configuration import/ export function also within docker images. * chore: improve EOSdash config tab display Improve display of JSON code and add more forms for config value update. * chore: make docker image file system layout similar to home assistant Only use /data directory for persistent data. This is handled as a docker volume. The /data volume is mapped to ~/.local/share/net.akkudoktor.eos if using docker compose. * chore: add home assistant add-on development environment Add VSCode devcontainer and task definition for home assistant add-on development. * chore: improve documentation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic import Field, computed_field, field_validator
|
||||
|
||||
from akkudoktoreos.config.configabc import SettingsBaseModel
|
||||
from akkudoktoreos.prediction.elecpriceabc import ElecPriceProvider
|
||||
@@ -57,6 +57,12 @@ class ElecPriceCommonSettings(SettingsBaseModel):
|
||||
json_schema_extra={"description": "Energy Charts provider settings."},
|
||||
)
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def providers(self) -> list[str]:
|
||||
"""Available electricity price provider ids."""
|
||||
return elecprice_providers
|
||||
|
||||
# Validators
|
||||
@field_validator("provider", mode="after")
|
||||
@classmethod
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic import Field, computed_field, field_validator
|
||||
|
||||
from akkudoktoreos.config.configabc import SettingsBaseModel
|
||||
from akkudoktoreos.prediction.feedintariffabc import FeedInTariffProvider
|
||||
@@ -56,6 +56,12 @@ class FeedInTariffCommonSettings(SettingsBaseModel):
|
||||
},
|
||||
)
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def providers(self) -> list[str]:
|
||||
"""Available feed in tariff provider ids."""
|
||||
return feedintariff_providers
|
||||
|
||||
# Validators
|
||||
@field_validator("provider", mode="after")
|
||||
@classmethod
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic import Field, computed_field, field_validator
|
||||
|
||||
from akkudoktoreos.config.configabc import SettingsBaseModel
|
||||
from akkudoktoreos.prediction.loadabc import LoadProvider
|
||||
@@ -62,6 +62,12 @@ class LoadCommonSettings(SettingsBaseModel):
|
||||
},
|
||||
)
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def providers(self) -> list[str]:
|
||||
"""Available load provider ids."""
|
||||
return load_providers
|
||||
|
||||
# Validators
|
||||
@field_validator("provider", mode="after")
|
||||
@classmethod
|
||||
|
||||
@@ -39,11 +39,11 @@ class LoadImportCommonSettings(SettingsBaseModel):
|
||||
@field_validator("import_file_path", mode="after")
|
||||
@classmethod
|
||||
def validate_loadimport_file_path(cls, value: Optional[Union[str, Path]]) -> Optional[Path]:
|
||||
"""Ensure file is available."""
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, str):
|
||||
value = Path(value)
|
||||
"""Ensure file is available."""
|
||||
value.resolve()
|
||||
if not value.is_file():
|
||||
raise ValueError(f"Import file path '{value}' is not a file.")
|
||||
|
||||
@@ -24,7 +24,7 @@ class VrmForecastResponse(PydanticBaseModel):
|
||||
|
||||
|
||||
class LoadVrmCommonSettings(SettingsBaseModel):
|
||||
"""Common settings for VRM API."""
|
||||
"""Common settings for load forecast VRM API."""
|
||||
|
||||
load_vrm_token: str = Field(
|
||||
default="your-token",
|
||||
|
||||
@@ -52,22 +52,7 @@ from akkudoktoreos.prediction.weatherimport import WeatherImport
|
||||
|
||||
|
||||
class PredictionCommonSettings(SettingsBaseModel):
|
||||
"""General Prediction Configuration.
|
||||
|
||||
This class provides configuration for prediction settings, allowing users to specify
|
||||
parameters such as the forecast duration (in hours).
|
||||
Validators ensure each parameter is within a specified range.
|
||||
|
||||
Attributes:
|
||||
hours (Optional[int]): Number of hours into the future for predictions.
|
||||
Must be non-negative.
|
||||
historic_hours (Optional[int]): Number of hours into the past for historical data.
|
||||
Must be non-negative.
|
||||
|
||||
Validators:
|
||||
validate_hours (int): Ensures `hours` is a non-negative integer.
|
||||
validate_historic_hours (int): Ensures `historic_hours` is a non-negative integer.
|
||||
"""
|
||||
"""General Prediction Configuration."""
|
||||
|
||||
hours: Optional[int] = Field(
|
||||
default=48,
|
||||
|
||||
@@ -260,6 +260,12 @@ class PVForecastCommonSettings(SettingsBaseModel):
|
||||
},
|
||||
)
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def providers(self) -> list[str]:
|
||||
"""Available PVForecast provider ids."""
|
||||
return pvforecast_providers
|
||||
|
||||
# Validators
|
||||
@field_validator("provider", mode="after")
|
||||
@classmethod
|
||||
|
||||
@@ -193,20 +193,6 @@ class PVForecastAkkudoktor(PVForecastProvider):
|
||||
from the PVForecastAkkudoktor API and maps it to `PVForecastDataRecord` fields, applying
|
||||
any necessary scaling or unit corrections. It manages the forecast over a range
|
||||
of hours into the future and retains historical data.
|
||||
|
||||
Attributes:
|
||||
hours (int, optional): Number of hours in the future for the forecast.
|
||||
historic_hours (int, optional): Number of past hours for retaining data.
|
||||
latitude (float, optional): The latitude in degrees, validated to be between -90 and 90.
|
||||
longitude (float, optional): The longitude in degrees, validated to be between -180 and 180.
|
||||
start_datetime (datetime, optional): Start datetime for forecasts, defaults to the current datetime.
|
||||
end_datetime (datetime, computed): The forecast's end datetime, computed based on `start_datetime` and `hours`.
|
||||
keep_datetime (datetime, computed): The datetime to retain historical data, computed from `start_datetime` and `historic_hours`.
|
||||
|
||||
Methods:
|
||||
provider_id(): Returns a unique identifier for the provider.
|
||||
_request_forecast(): Fetches the forecast from the Akkudoktor API.
|
||||
_update_data(): Processes and updates forecast data from Akkudoktor in PVForecastDataRecord format.
|
||||
"""
|
||||
|
||||
# overload
|
||||
|
||||
@@ -24,7 +24,7 @@ class VrmForecastResponse(PydanticBaseModel):
|
||||
|
||||
|
||||
class PVForecastVrmCommonSettings(SettingsBaseModel):
|
||||
"""Common settings for VRM API."""
|
||||
"""Common settings for PV forecast VRM API."""
|
||||
|
||||
pvforecast_vrm_token: str = Field(
|
||||
default="your-token",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic import Field, computed_field, field_validator
|
||||
|
||||
from akkudoktoreos.config.configabc import SettingsBaseModel
|
||||
from akkudoktoreos.prediction.prediction import get_prediction
|
||||
@@ -52,6 +52,12 @@ class WeatherCommonSettings(SettingsBaseModel):
|
||||
},
|
||||
)
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def providers(self) -> list[str]:
|
||||
"""Available weather provider ids."""
|
||||
return weather_providers
|
||||
|
||||
# Validators
|
||||
@field_validator("provider", mode="after")
|
||||
@classmethod
|
||||
|
||||
@@ -37,7 +37,7 @@ WheaterDataClearOutsideMapping: List[Tuple[str, Optional[str], Optional[float]]]
|
||||
("Precipitation Type", "Precipitation Type", None),
|
||||
("Precipitation Probability (%)", "Precipitation Probability (%)", 1),
|
||||
("Precipitation Amount (mm)", "Precipitation Amount (mm)", 1),
|
||||
("Wind Speed (mph)", "Wind Speed (kmph)", 1.60934),
|
||||
("Wind Speed/Direction (mph)", "Wind Speed (kmph)", 1.60934),
|
||||
("Chance of Frost", "Chance of Frost", None),
|
||||
("Temperature (°C)", "Temperature (°C)", 1),
|
||||
("Feels Like (°C)", "Feels Like (°C)", 1),
|
||||
@@ -218,7 +218,7 @@ class WeatherClearOutside(WeatherProvider):
|
||||
for detail_name in detail_names:
|
||||
if detail_name not in clearoutside_key_mapping:
|
||||
warning_msg = (
|
||||
f"Clearoutside schema change. Unexpected detail name {detail_name}."
|
||||
f"Clearoutside schema change. Unexpected detail name '{detail_name}'."
|
||||
)
|
||||
logger.warning(warning_msg)
|
||||
|
||||
@@ -226,17 +226,13 @@ class WeatherClearOutside(WeatherProvider):
|
||||
# Beware there is one ul paragraph before that is not associated to a detail
|
||||
p_detail_tables = p_day.find_all("ul")
|
||||
if len(p_detail_tables) != len(detail_names) + 1:
|
||||
error_msg = f"Clearoutside schema change. Unexpected number ({p_detail_tables}) of `ul` for details {len(detail_names)}. Should be one extra only."
|
||||
error_msg = f"Clearoutside schema change. Unexpected number ({p_detail_tables}) of 'ul' for details {len(detail_names)}. Should be one extra only."
|
||||
logger.error(error_msg)
|
||||
raise ValueError(error_msg)
|
||||
p_detail_tables.pop(0)
|
||||
|
||||
# Create clearout data
|
||||
clearout_data = {}
|
||||
# Replace some detail names that we use differently
|
||||
detail_names = [
|
||||
s.replace("Wind Speed/Direction (mph)", "Wind Speed (mph)") for s in detail_names
|
||||
]
|
||||
# Number of detail values. On last day may be less than 24.
|
||||
detail_values_count = None
|
||||
# Add data values
|
||||
@@ -266,7 +262,7 @@ class WeatherClearOutside(WeatherProvider):
|
||||
extra_detail_name = None
|
||||
extra_detail_data = []
|
||||
for p_detail_value in p_detail_values:
|
||||
if detail_name == "Wind Speed (mph)":
|
||||
if detail_name == "Wind Speed/Direction (mph)":
|
||||
# Get the usual value
|
||||
value_str = p_detail_value.get_text()
|
||||
# Also extract extra data
|
||||
|
||||
Reference in New Issue
Block a user