mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-09-03 14:36:37 +00:00
feat: add PVForecastHomeAssistant provider (#1258)
* feat: add PVForecastHomeAssistant provider
Reads a PV forecast time series directly from a Home Assistant entity
attribute (matching the {"forecast": [{"datetime", "watts"}]} shape
already exposed by common HA PV forecast integrations, e.g. Helios
Forecast and Solcast) and feeds it into pvforecast_ac_power, following
the same self-polling provider pattern as PVForecastVrm.
Closes #1232.
* fix: use MagicMock instead of monkeypatched Response for mypy
requests.Response().json is a typed bound method; reassigning it to a
lambda fails mypy's method-assign check. Use MagicMock(spec=...) instead,
which mocks the response without fighting its static type.
* fix: address PR review on PVForecastHomeAssistant provider
Fixes two issues raised in review on PR #1258:
- _update_data() left stale pvforecast_ac_power values in place when a
refreshed forecast was empty or shorter than a previous one; it now
clears the active forecast window before writing and raises instead
of silently no-op'ing when the response has no usable data.
- pvforecast.homeassistant.entity_id used a "select" widget with no
manual-entry fallback in EOSdash, leaving it unusable in standalone
mode where the entity list can't be resolved without SUPERVISOR_TOKEN;
switched to a plain text field.
Also fills in the config docs and openapi.json for the new
pvforecast.homeassistant.* fields, which were missing from the
original commit.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix: preserve retained forecast history when clearing stale entries
The previous fix cleared pvforecast_ac_power from start-of-day, but
PredictionProvider deliberately retains historical records back to
keep_datetime (prediction.historic_hours). Since Home Assistant
forecasts are future-only, that clear wiped out retained history
between midnight and the EMS start on every refresh.
Narrow the clear to [ems_start_datetime, end_datetime) - the actual
active forecast window, DST-adjusted - instead of the day boundary.
Addresses review feedback from @NormannK on PR #1258.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Mathias <mathias@Mathiass-MacBook-Air.local>
Co-authored-by: Mathias <mathias@Mathiass-Air.localdomain>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
Mathias
Mathias
parent
ba76087db9
commit
7bafc8d02d
@@ -244,6 +244,15 @@
|
||||
"token": "your-token",
|
||||
"site_id": 12345
|
||||
},
|
||||
"homeassistant": {
|
||||
"entity_id": "sensor.pv_forecast",
|
||||
"attribute": "forecast",
|
||||
"datetime_key": "datetime",
|
||||
"value_key": "watts",
|
||||
"value_unit": "W",
|
||||
"base_url": null,
|
||||
"token": null
|
||||
},
|
||||
"pvlib": {},
|
||||
"pvnode": {
|
||||
"api_key": "",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
| Name | Environment Variable | Type | Read-Only | Default | Description |
|
||||
| ---- | -------------------- | ---- | --------- | ------- | ----------- |
|
||||
| forecastsolar | `EOS_PVFORECAST__FORECASTSOLAR` | `PVForecastForecastSolarCommonSettings` | `rw` | `required` | ForecastSolar provider settings |
|
||||
| homeassistant | `EOS_PVFORECAST__HOMEASSISTANT` | `PVForecastHomeAssistantCommonSettings` | `rw` | `required` | Home Assistant provider settings |
|
||||
| max_planes | `EOS_PVFORECAST__MAX_PLANES` | `int | None` | `rw` | `0` | Maximum number of planes that can be set |
|
||||
| planes | `EOS_PVFORECAST__PLANES` | `list[akkudoktoreos.prediction.pvforecast.PVForecastPlaneSetting] | None` | `rw` | `None` | Plane configuration. |
|
||||
| planes_azimuth | | `List[float]` | `ro` | `N/A` | Compute a list of the azimuths per active planes. |
|
||||
@@ -42,6 +43,15 @@
|
||||
"token": "your-token",
|
||||
"site_id": 12345
|
||||
},
|
||||
"homeassistant": {
|
||||
"entity_id": "sensor.pv_forecast",
|
||||
"attribute": "forecast",
|
||||
"datetime_key": "datetime",
|
||||
"value_key": "watts",
|
||||
"value_unit": "W",
|
||||
"base_url": null,
|
||||
"token": null
|
||||
},
|
||||
"pvlib": {},
|
||||
"pvnode": {
|
||||
"api_key": "",
|
||||
@@ -124,6 +134,15 @@
|
||||
"token": "your-token",
|
||||
"site_id": 12345
|
||||
},
|
||||
"homeassistant": {
|
||||
"entity_id": "sensor.pv_forecast",
|
||||
"attribute": "forecast",
|
||||
"datetime_key": "datetime",
|
||||
"value_key": "watts",
|
||||
"value_unit": "W",
|
||||
"base_url": null,
|
||||
"token": null
|
||||
},
|
||||
"pvlib": {},
|
||||
"pvnode": {
|
||||
"api_key": "",
|
||||
@@ -257,6 +276,47 @@
|
||||
```
|
||||
<!-- pyml enable line-length -->
|
||||
|
||||
### Common settings for pvforecast data from a Home Assistant entity
|
||||
|
||||
<!-- pyml disable line-length -->
|
||||
:::{table} pvforecast::homeassistant
|
||||
:widths: 10 10 5 5 30
|
||||
:align: left
|
||||
|
||||
| Name | Type | Read-Only | Default | Description |
|
||||
| ---- | ---- | --------- | ------- | ----------- |
|
||||
| entity_id | `str` | `rw` | `sensor.pv_forecast` | Home Assistant entity providing the PV forecast. |
|
||||
| attribute | `str` | `rw` | `forecast` | Entity attribute holding the forecast list. |
|
||||
| datetime_key | `str` | `rw` | `datetime` | Key for the timestamp in each forecast entry. |
|
||||
| value_key | `str` | `rw` | `watts` | Key for the AC power value in each forecast entry. |
|
||||
| value_unit | `Literal['W', 'kW']` | `rw` | `W` | Unit of the forecast value. Converted to W internally. |
|
||||
| base_url | `str | None` | `rw` | `None` | Base URL of the Home Assistant instance. Only required when EOS is not running as a Home Assistant add-on (no SUPERVISOR_TOKEN available). |
|
||||
| token | `str | None` | `rw` | `None` | Long-lived access token for the Home Assistant instance. Only required when EOS is not running as a Home Assistant add-on. |
|
||||
:::
|
||||
<!-- pyml enable line-length -->
|
||||
|
||||
<!-- pyml disable no-emphasis-as-heading -->
|
||||
**Example Input/Output**
|
||||
<!-- pyml enable no-emphasis-as-heading -->
|
||||
|
||||
<!-- pyml disable line-length -->
|
||||
```json
|
||||
{
|
||||
"pvforecast": {
|
||||
"homeassistant": {
|
||||
"entity_id": "sensor.pv_forecast",
|
||||
"attribute": "forecast",
|
||||
"datetime_key": "datetime",
|
||||
"value_key": "watts",
|
||||
"value_unit": "W",
|
||||
"base_url": null,
|
||||
"token": null
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
<!-- pyml enable line-length -->
|
||||
|
||||
### Common settings for the Solcast PV forecast provider
|
||||
|
||||
<!-- pyml disable line-length -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Akkudoktor-EOS
|
||||
|
||||
**Version**: `v0.3.0.dev2608221553448643`
|
||||
**Version**: `v0.3.0.dev2609011977897641`
|
||||
|
||||
<!-- pyml disable line-length -->
|
||||
**Description**: This project provides a comprehensive solution for simulating and optimizing an energy system based on renewable energy sources. With a focus on photovoltaic (PV) systems, battery storage (batteries), load management (consumer requirements), heat pumps, electric vehicles, and consideration of electricity price data, this system enables forecasting and optimization of energy flow and costs over a specified period.
|
||||
|
||||
Reference in New Issue
Block a user