Use forward fill to interpolate time series data that represents prices:
- elecprice_marketprice_wh
- feed_in_tariff_wh
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This PR adds three native PV power forecast providers, giving operators more
cloud forecast sources to choose from via pvforecast.provider, alongside the
existing PVForecastAkkudoktor, PVForecastVrm and PVForecastImport:
PVForecastPVNode — native 15-minute forecasts from the pvnode.com
V2 API. Saved-site mode (GET /v2/forecast/{site_id}) where the operator enters their API key +
site id, or inline mode (POST /v2/forecast/inline) using the configured planes.
PVForecastForecastSolar — the free Forecast.Solar API (no key
required for the public endpoint). Multi-plane systems issue one request per plane and the
instantaneous powers are summed per timestamp.
PVForecastSolcast — the Solcast rooftop-site API (API key + resource id).
Implementation notes
All three populate the existing pvforecast_ac_power (and mirror pvforecast_dc_power)
prediction keys, so they slot into the optimizer unchanged.
Timezone handling: pvnode and Forecast.Solar return site-local wall-clock timestamps with an
IANA timezone field, which are resolved to absolute instants before resampling; Solcast returns
UTC period_end and is normalised to the period start.
Each provider follows the existing provider pattern (provider_id(), _request_forecast() with
@cache_in_file, _update_data()), is registered in pvforecast.py and prediction.py, and is
upstream-neutral.
Validation
27 unit tests (timezone resolution, null/zero handling, kW→W and period-start conversion,
azimuth conversion, multi-plane summation, request URL/auth, HTTP-error handling).
ruff check (F/D/S/bandit) and ruff format clean.
Each provider was additionally validated against its live API with a real plant, confirming
the response shapes (pvnode: 288 native 15-min slots; Forecast.Solar: instantaneous watts;
Solcast: kW estimates with period_end/PT30M).
Documentation
Provider descriptions and configuration examples added to docs/akkudoktoreos/prediction.md.
CHANGELOG.md entry under Unreleased.
Regenerated docs/_generated/configpvforecast.md and configexample.md.
Notes for reviewers
Forecast.Solar's free endpoint is rate-limited (12 req/hour) and Solcast's free tier limits daily
calls; both providers rely on the standard 1-hour cache_in_file TTL to stay within budget.
Authors:
The code is created by Christin. Only minor adaptions by Bobby.
Signed-off-by: Christin <info@bikinibottom.capital>
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-authored-by: Christin <info@bikinibottom.capital>
FAstAPI is an async framework. Data may be imported and exported, load and save, set and get
asynchronously. Prevent interleaving data operations to corrupt the data. In the previous design
sync and async data access was intermixed leading to data corruption.
The basic data classes DataSequence and DataContainer and the derived classes like Provider and
Measurement now are async. Data access is protected by several async locks.
To support the async design of the data classes the database interface became async.
The energy management is also adapted to the new async design. Optimization is still off-loaded
to another thread, but the prepration for the optimization and the post optimization actions now
follow the async design.
Adapter operations are now also protected by async locks.
Tests were adapted to the async design and new tests were created.
Besides this major fix several other improvements and fixes are included in this PR.
* fix: key_to_dict/list/array only regard data records with key value set.
Before the exclusion of no value data records was only done if the dropna flag was set.
* fix: test for visual result pdf generation
Due to updates in the library the generated charts text was a little bit different.
Adapt the test to create the comaprison pdf in the test data durectory and
update the reference pdf.
* chore: Remove MutableMapping from DataSequence and DataContainer.
Mutable Mapping does not fit to the now async design.
* chore: Add NoDB database backend
This backend implements the full database backend interface but performs
no actual persistence. It is intended for configurations where database
persistence is disabled (`provider=None`).
* chore: Improve measurement data import testing with real world scenarios.
Added two new endpoints to support testing.
* chore: Add mermaid to supported documentation tools
* chore: Add documentation about async design
* chore: Add documentation about generic data handling
Covers the basics of measurement and prediction time series data handling.
* chore: Add empty lines around markdown lists.
* chore: sync pre-commit config to updated package versions
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Fix documentation for the loadforecast_power_w key.
Fix documentation to explain the usage of import file/ JSON string to
primarily initialise prediction data.
Fix code scanning alert no. 6: URL redirection from remote source
Enable to automatically save the configuration to the configuration file
by default, which is a widespread user expectation.
Make the genetic parameters non optional for better pydantic compliance.
Update:
- bump pytest to 9.0.3
- bump pillow to 12.2.0
- bump platformdirs to 4.9.6
- bump typespyyaml to 6.0.12.20260408
- bump tzfpy to 1.2.0
- bump pydantic to 2.13.0
- bump types-requests to 2.33.0.20260408
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-authored-by: Normann <github@koldrack.com>
Make openmeteo test robust against timing issues.
Also update:
- types-docutils==0.22.3.20260322
- pytest-cov==7.1.0
- ruff-pre-commit v0.15.7
- uvlock
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Make device id in solution follow actual configuration.
Adapt version update to new CI bump workflow design.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This pull request prepares release **v0.3.0**.
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.
Adapters for Home Assistant and NodeRed integration are added. These adapters
provide a simplified interface to these HEMS besides the standard REST interface.
The prediction and measurement data can now be backed by a database. The database allows
to keep historic prediction data and measurement data for long time without keeping
it in memory. The database supports backend selection, compression, incremental data load,
automatic data saving to storage, automatic vacuum and compaction. Two database backends
are integrated and can be configured, LMDB and SQLight3.
New prediction providers allow to access OpenMeteo weather data and to define fixed
electricity prices for configurable time windows.
An anoying bug in the genetic algorithm that created unfeasable battery charge and
discharge amounts is now hopefully fixed.
In addition, bugs were fixed and new features were added.
See CHANGELOG for full details.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
* record battery SOC at the start of the interval for accurate display
* map battery charge rates to GeneticOptimizationParameters and update related logic
Instead of using the EV charge rates, the battery now has its own charge rate defined
in the GeneticOptimizationParameters to better separate those entities.
* separate raw gene values from SOC-clamped op factors
The genetic_*_factor columns in the OptimizationSolution dataframe now
always carry the raw gene values (optimizer intent), while the
battery1_*_op_mode / battery1_*_op_factor columns and FRBCInstruction
operation_mode_factor reflect SOC-clamped effective values that can
actually be executed given the battery's state of charge at each hour.
Adds GeneticSolution._soc_clamped_operation_factors():
- AC charge factor: proportionally scaled down when battery headroom
(max_soc - current_soc) is less than what the commanded factor
would store in one hour; zeroed when battery is full.
- DC charge factor: zeroed when battery is at or above max SOC.
- Discharge: blocked when SOC is at or below min SOC.
Both optimization_solution() and energy_management_plan() pass the
clamped values to _battery_operation_from_solution(), so the plan
instructions the HEMS receives reflect physically achievable targets.
* ensure max AC charge power is only used if defined
* update fixtures for PV suffix + SOC-clamp algorithm changes
* handle None case for home appliance start hour in simulation
if the hour is zero, the the home appliance wont start
* update handling of invalid charge indices in autocharge hours
Seems to be a bug, since all invalid indexes needs to be invalidated (also the first one)
* remove double code in simulation preparation and improve comments
* update version
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Co-authored-by: Christopher Nadler <christopher.nadler@gmail.com>
Ensure that the bidding zone in the request is correctly set to a
string value (not an enum).
This seems to be also an issue with python version < 3.11. Add safeguards
to only use python >= 3.11. Still keep a regression test for the enum
conversion to string.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
When running as Home Assistant add-on the only viable usage is running with
cyclic optimization. Make this the default to als propvide a better experience
for first time users. The optimization will start with demo data, which also
helps to configure Akkudoktor-EOS to the personal usage.
The disabling of the automatic energy management is now an explicit mode
"DISABLED".
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Add a fixed electricity prediction that supports prices per time window.
The time windows may flexible be defined by day or date.
The prediction documentation is updated to also cover the ElecPriceFixed
provider.
The feature includes several changes that are not directly related to the
electricity price prediction implementation but are necessary to keep
EOS running properly and to test and document the changes.
* feat: add value time windows
Add time windows with an associated float value.
* feat: harden eos measurements endpoints error detection and reporting
Cover more errors that may be raised during endpoint access. Report the
errors including trace information to ease debugging.
* feat: extend server configuration to cover all arguments
Make the argument controlled options also available in server configuration.
* fix: eos config configuration by cli arguments
Move the command line argument handling to config eos so that it is
excuted whenever eos config is rebuild or reset.
* chore: extend measurement endpoint system test
* chore: refactor time windows
Move time windows to configabc as they are only used in configurations.
Also move all tests to test_configabc.
* chore: provide config update errors in eosdash with summarized error text
If there is an update error provide the error text as a summary. On click
provide the full error text.
* chore: force eosdash ip address and port in makefile dev run
Ensure eosdash ip address and port are correctly set for development runs.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Validate solution prediction data before processing.
If required prediction data is missing, the prediction is skipped
instead of raising an exception.
Introduce a new configuration file saving policy to improve loading robustness:
- Exclude computed fields
- Exclude fields set to their default values
- Exclude fields with value None
- Use field aliases
- Recursively remove empty dictionaries and lists
- Ensure general.version is always present and correctly set
When loading older configuration files, computed fields are now stripped
before migration. This further improves backward compatibility and loading
robustness.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Adapt uvicorn log level to allowed levels.
Ensure that EOSdash is started after EOS configuration is available.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Startup retention manager for asynchronous tasks. Handle gracefully
exceptions in these tasks or the configuration for them.
Remove tasks.py as repeated tasks are now handled by the retention
manager.
When running on GitHub, only the version date file is checked. The
development tag is merely a label, so any date set during development suffices.
The test_doc is also skipped on GitHub actions.
Ensure that the snapping sequence generated in the test fixture
is within the boundaries expected by the test.
Ensure we read the _version_date.py info as UTC datetime and do
no localtime conversion.
Prevent and guard test_version.py to modify the version date file.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Upgrade to:
- pandas==3.01
- fastapi[standard-no-fastapi-cloud-cli]==0.132.0
- fastapi_cli==0.0.23
- MonsterUI==1.0.44
- uvicorn==0.41.0
Close database in database fixture on teardown.
Fix file exclusion in hash and version date generation.
Update version information in documentation.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Home Assistant expects versioning always increases numbers. Add
a date component to the development version to comply with this
expectation. The scheme is now 0.0.0.dev<date><hash>.
Use uv for creating and managing the virtual environment for developement.
This enourmously speeds up dependency updates. For this change
dependency requirements are now solely handled in pyproject.toml.
requirements.tx and requirements-dev.txt are deleted.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
The database supports backend selection, compression, incremental data load,
automatic data saving to storage, automatic vaccum and compaction.
Make SQLite3 and LMDB database backends available.
Update tests for new interface conventions regarding data sequences,
data containers, data providers. This includes the measurements provider and
the prediction providers.
Add database documentation.
The fix includes several bug fixes that are not directly related to the database
implementation but are necessary to keep EOS running properly and to test and
document the changes.
* fix: config eos test setup
Make the config_eos fixture generate a new instance of the config_eos singleton.
Use correct env names to setup data folder path.
* fix: startup with no config
Make cache and measurements complain about missing data path configuration but
do not bail out.
* fix: soc data preparation and usage for genetic optimization.
Search for soc measurments 48 hours around the optimization start time.
Only clamp soc to maximum in battery device simulation.
* fix: dashboard bailout on zero value solution display
Do not use zero values to calculate the chart values adjustment for display.
* fix: openapi generation script
Make the script also replace data_folder_path and data_output_path to hide
real (test) environment pathes.
* feat: add make repeated task function
make_repeated_task allows to wrap a function to be repeated cyclically.
* chore: removed index based data sequence access
Index based data sequence access does not make sense as the sequence can be backed
by the database. The sequence is now purely time series data.
* chore: refactor eos startup to avoid module import startup
Avoid module import initialisation expecially of the EOS configuration.
Config mutation, singleton initialization, logging setup, argparse parsing,
background task definitions depending on config and environment-dependent behavior
is now done at function startup.
* chore: introduce retention manager
A single long-running background task that owns the scheduling of all periodic
server-maintenance jobs (cache cleanup, DB autosave, …)
* chore: canonicalize timezone name for UTC
Timezone names that are semantically identical to UTC are canonicalized to UTC.
* chore: extend config file migration for default value handling
Extend the config file migration handling values None or nonexisting values
that will invoke a default value generation in the new config file. Also
adapt test to handle this situation.
* chore: extend datetime util test cases
* chore: make version test check for untracked files
Check for files that are not tracked by git. Version calculation will be
wrong if these files will not be commited.
* chore: bump pandas to 3.0.0
Pandas 3.0 now performs inference on the appropriate resolution (a.k.a. unit)
for the output dtype which may become datetime64[us] (before it was ns). Also
numeric dtype detection is now more strict which needs a different detection for
numerics.
* chore: bump pydantic-settings to 2.12.0
pydantic-settings 2.12.0 under pytest creates a different behaviour. The tests
were adapted and a workaround was introduced. Also ConfigEOS was adapted
to allow for fine grain initialization control to be able to switch
off certain settings such as file settings during test.
* chore: remove sci learn kit from dependencies
The sci learn kit is not strictly necessary as long as we have scipy.
* chore: add documentation mode guarding for sphinx autosummary
Sphinx autosummary excecutes functions. Prevent exceptions in case of pure doc
mode.
* chore: adapt docker-build CI workflow to stricter GitHub handling
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Truncate long lines on logging from EOSdash.
Rate limit log messages from EOSdash to prevent overload.
Log messages read and dropped to avoid EOSdash is blocked on
standard or error output.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Add documentation for home assistant adapter.
Make adapter correctly set the measurement keys for PV production.
Add adapter configuration for grid import and export measurements.
Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
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