Files
EOS/src/akkudoktoreos/prediction/feedintarifffixed.py
T
Bobby NoelteandGitHub ba76087db9 feat: electricity fee provider framework and generic providers (#1235)
Add new provider class for electricity fees providers.

Add the generic providers:
- ElecFeeFixed
- ElecFeeImport

The providers provide predictions for:

- elecfee_consumption_amt_wh:
  Total fixed fee for consumed energy per Wh [amount/Wh]. This is the accumulation of all
  fixed per-Wh fees payable on "consumed energy - such as network charge, concession fee,
  and electricity charge - into a single amount.
- elecfee_consumption_percent_amt:
  Total fixed surcharge on consumed energy, given as a percentage of the monetary amount
  already charged for that energy [%]. This is the accumulation of all percentage-based
  surcharges payable on top of the consumed-energy fee - such as VAT - into a single
  percentage. This is a percentage of the fee amount, not a per-Wh rate.
- elecfee_feedin_amt_wh:
  Total fixed deduction from feed-in energy per Wh [amount/Wh]. This is the accumulation of
  all fixed per-Wh charges deducted from feed-in energy - such as metering fees or
  grid-operator handling "charges - into a single amount. Applied after the percentage-based
  deduction, i.e. it reduces the price by a flat amount per Wh rather than by a share of the
  raw price.
- elecfee_feedin_percent_amt:
  Total percentage deducted from the raw feed-in price (spot price) [%]. This is the
  accumulation of all percentage-based deductions payable on the feed-in tariff - such as a
  marketing or balancing fee retained by the aggregator - into a single percentage. It is
  applied as `raw_price * (100 - percent) / 100`, i.e. it scales down the raw price rather
  than adding a surcharge to it.

A new _apply_fee() method is added to the base class for ElecPrice and FeedInTariff to be used to
add the fees in a consistent way. Fees are taken from the active ElecFee provider and applied
to the raw prices given to the _apply_fee() method.

The optional application of fees is added to:

- ElecPriceAkkudoktor
- ElecPriceFixed
- ElecPriceEnergyCharts
- ElecPriceSMARD
- FeedInTariffEnergyCharts
- FeedInTariffFixed
- FeedInTariffSMARD

The import providers ElecPriceImport and FeedInTariffImport do not apply fees by intentention.

The following providers currently do not handle fees defined by ElecFee:

- ElecPriceTibber
- FeedInTariffAkkudoktor
- FeedInTariffDvhubOnline
- FeedInTariffTibber

The tests for this feature are either added or existing tests are extended.

The documentation was extended for the electricity fee provider settings.

Besides this feature further improvements are added:

* feat: add SMARD quarter-hour electricty price and feed-in tariff provider

* feat: to_series method for TimeWindows and ValueTimeWindows

  Additional to to_array the time window sequence can now also produce a pandas series.
  Test have been extended to cover the series generation.

* feat: use time windows in fixed feedin tariff provider

  Feedin tariff can now be configured by time windows - not a single value.

* feat: EOSdash select for PVLib inverters and modules

  Provide PVLib inverter and module names in config selection.

* feat: EOSdash lazy select for big option sets

  Add a new form for lazy selection of big option sets. Filtering and
  generation of the option set is done server-side.

* fix: use raw data for ETS/ median prediction

  Use to raw time series data for ETS/ median prediction to avoid interference
  by e.g. dynamic grid charges.

* fix: EOSdash config drops by type only on details resolve

  Drop configuration by type and path. Prevents dropping of configuration items
  with same type and level but different path.

* fix: EOSdash configuration section closes on update

  Open section if searching or if last update touched this category — including
  updates on deeply nested sub-fields.

* chore: make elecfeefixed, elecpricefixed and feedintarifffixed warn about no windows and default to 0

  Missining configuration creates default 0 value and a warning instead of an exception.

* fix: test setup for providers

  Reset db state on each test run.

* chore: improve config option naming for elecpricefixed.

* chore: adapt elecpricefixed test to changed time_windows naming

* chore: factorized common price provider helpers to priceabc.py

  Factorized common price provider helpers to priceabc.py. Add tests for these helpers.
  Reduce/ change testing of elecpriceabc.py and feedintariffabc.py to cover
  only specifics. Rest of testing is already covered by test_priceabc.py.

* chore: update version

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2026-08-23 02:26:16 +02:00

121 lines
4.6 KiB
Python

"""Provides feed in tariff data."""
from typing import Optional
from loguru import logger
from pydantic import Field
from akkudoktoreos.config.configabc import (
SettingsBaseModel,
ValueTimeWindowSequence,
)
from akkudoktoreos.prediction.feedintariffabc import FeedInTariffProvider
from akkudoktoreos.utils.datetimeutil import DateTime, to_duration
class FeedInTariffFixedCommonSettings(SettingsBaseModel):
"""Common settings for elecprice fixed price."""
feed_in_tariff_amt_kwh: ValueTimeWindowSequence = Field(
default_factory=ValueTimeWindowSequence,
json_schema_extra={
"description": (
"Sequence of time windows defining the electricity feed in tariff [amount/kWh]. "
"If not provided, no fixed feed in tariff is applied."
),
"examples": [
{
"windows": [
{"start_time": "00:00", "duration": "8 hours", "value": 0.028},
{"start_time": "08:00", "duration": "16 hours", "value": 0.034},
],
}
],
},
)
class FeedInTariffFixed(FeedInTariffProvider):
"""Fixed price feed in tariff data.
FeedInTariffFixed is a singleton-based class that retrieves elecprice data.
"""
highest_orig_datetime: Optional[DateTime] = None
@classmethod
def provider_id(cls) -> str:
"""Return the unique identifier for the FeedInTariffFixed provider."""
return "FeedInTariffFixed"
async def _update_data(self, force_update: Optional[bool] = False) -> None:
"""Update feed-in tariff data from fixed schedule.
Generates feed-in tariff based on the configured time windows
at the optimization interval granularity. The tariff sequence starts
synchronized to the wall clock at the next full interval boundary.
Args:
force_update: If True, forces update even if data exists.
Raises:
ValueError: If no time windows are configured.
"""
prediction_key = "feed_in_tariff_wh"
raw_prediction_key = "feed_in_tariff_raw_wh"
time_windows_seq: ValueTimeWindowSequence = (
self.config.feedintariff.feedintarifffixed.feed_in_tariff_amt_kwh
)
start_datetime = self.ems_start_datetime
interval_seconds = 900 # Usual smallest time interval (15 min) used in electricty prices
total_hours = self.config.prediction.hours
interval = to_duration(interval_seconds)
end_datetime = start_datetime.add(hours=total_hours)
if time_windows_seq is None or not time_windows_seq.windows:
warning_msg = f"No time windows configured for `{raw_prediction_key}`, defaulting to 0."
logger.warning(warning_msg)
# Store two values to have a default interval to be used by _apply_fees
end_datetime = start_datetime + interval
await self.update_value(start_datetime, raw_prediction_key, 0.0)
await self.update_value(end_datetime, raw_prediction_key, 0.0)
self.highest_orig_datetime = end_datetime
await self._store_gross_series(
start_datetime=start_datetime,
end_datetime=end_datetime + to_duration("1 second"),
)
return
logger.debug(
f"Generating {prediction_key} for {total_hours} hours starting at {start_datetime}"
)
# Build the full tariff array in one call — kWh values aligned to the
# optimization grid. to_series mirrors the key_to_series signature so
# the grid is constructed identically to how prediction data is read.
tariffs_kwh = time_windows_seq.to_series(
start_datetime=start_datetime,
end_datetime=end_datetime,
interval=interval,
dropna=False,
boundary="context",
align_to_interval=True,
)
# Convert kWh → Wh
tariffs_wh = tariffs_kwh / 1000.0
await self.key_from_series(raw_prediction_key, tariffs_wh)
self.highest_orig_datetime = tariffs_wh.index.max()
# Bounded to exactly the window just generated - covers the whole
# forecast horizon in one shot, since FeedInTariffFixed has no
# fetch/predict split to worry about like the other providers.
await self._store_gross_series(
start_datetime=tariffs_wh.index.min(),
end_datetime=tariffs_wh.index.max() + to_duration("1 second"),
)
logger.debug(f"Successfully generated {len(tariffs_wh)} `{prediction_key}` entries")