Skip to content

Refactor fix hour tariff price calculation for quarter hours#3145

Open
tpd-opitz wants to merge 12 commits intoopenWB:masterfrom
tpd-opitz:synchronize-fixed-hours-tariffs-with-flexible-tarifs
Open

Refactor fix hour tariff price calculation for quarter hours#3145
tpd-opitz wants to merge 12 commits intoopenWB:masterfrom
tpd-opitz:synchronize-fixed-hours-tariffs-with-flexible-tarifs

Conversation

@tpd-opitz
Copy link
Contributor

@tpd-opitz tpd-opitz commented Feb 14, 2026

harmonize fixed hours tariff with dynamic tariffs

  • shortening the intervals to 15 minutes
  • extend Grid_Fee prices to 36 hours (fixed_hours tariff) to cover flexible tariff prices until next day midnight
  • expect flex ep tariff containig fix grid fee
    • select median of grid fee (standard fee)
    • final price = current_ep_price - median_grid_fee + current_grid_fee
  • Publish updated prices via MQTT in optional.py
    backend updates are done via MQTT listener in optional_data.py
  • move next_query_date calculation
  • move tariff update hours to tariff module configuration
  • introduce separate MQTT topics for next_query_time of ep tariff and grid fee
  • implement independent update of ep tariff and grid fee

known issue

  • grid fee configuration must be completely removed an configured from scratch to make changes work

see forum

@tpd-opitz tpd-opitz changed the title Refactor tariff price calculation for quarter hours Refactor fix hour tariff price calculation for quarter hours Feb 14, 2026
@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch 7 times, most recently from 6f0fe50 to 1293739 Compare February 15, 2026 19:56
@LKuemmel LKuemmel requested a review from ndrsnhs February 17, 2026 07:06
@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch 2 times, most recently from 765bf4e to bf1def5 Compare February 19, 2026 21:21
@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch from bf1def5 to f02d728 Compare February 19, 2026 22:01
@tpd-opitz tpd-opitz marked this pull request as draft February 20, 2026 16:38
@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch from a93b40a to 0493f0b Compare February 22, 2026 15:10
@tpd-opitz tpd-opitz marked this pull request as ready for review February 22, 2026 15:28
bereits ein festes Netzentgeld enthalten.
'''
grid_fee_prices = __reduce_prices(grid_fee_prices)
grid_fee_prices = {int(float(k)): v for k, v in grid_fee_prices.items() if int(float(k)) <= max_timestamp}
Copy link
Contributor Author

@tpd-opitz tpd-opitz Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Die Absicht war hier, die Liste der Netzentgeldpreise auf die Länge der Preissumme zu kürzen, damit sie die Darstellung im PreisChart der Statusseite nicht verzerrt. Für die Berechnungen wäre das nicht notwendig.

Leider funktioniert das nicht zuverlässig, aber openWB/openwb-ui-settings#905 wird das Problem beheben.

Comment on lines 74 to 85
if (hasattr(data.data.optional_data.grid_fee_module.config, "default_price") and
data.data.optional_data.grid_fee_module.config.default_price is not None):
print("Using default grid fee price from configuration: " +
f"{data.data.optional_data.grid_fee_module.config.default_price}")
return data.data.optional_data.grid_fee_module.config.default_price
else:
# Fallback: Median der vorhandenen Netzentgelte wird
# als Schätzung für das Standard-Netzentgelt verwenden
distinct_grid_fee_values = sorted(set(prices.values()))
return (
distinct_grid_fee_values[len(distinct_grid_fee_values) // 2]
if distinct_grid_fee_values else 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bedeutet das, das für alle Module, die nicht default_price implementieren, ein vom Backend ermittelter Wert von den abgefragten Preisen abgezogen wird?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ja.

Die Alternative wäre, wie vorher die Netzentgelte stumpf drauf zuschlagen, was zu deutlich größeren Abweichungen führen würde.

Comment on lines +49 to +56
try:
with SingleComponentUpdateContext(self.fault_state):
tariff_state, timeslot_length_seconds = self.__update_et_provider_data()
self.__store_and_publish_updated_data(tariff_state)
self.__log_and_publish_progress(timeslot_length_seconds, tariff_state)
except Exception as e:
log.exception(f"Fehler beim Aktualisieren der Tarifdaten {e}")
self.fault_state.warning("Error updating tariff data, retry in 5 minutes")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
with SingleComponentUpdateContext(self.fault_state):
tariff_state, timeslot_length_seconds = self.__update_et_provider_data()
self.__store_and_publish_updated_data(tariff_state)
self.__log_and_publish_progress(timeslot_length_seconds, tariff_state)
except Exception as e:
log.exception(f"Fehler beim Aktualisieren der Tarifdaten {e}")
self.fault_state.warning("Error updating tariff data, retry in 5 minutes")
with SingleComponentUpdateContext(self.fault_state):
tariff_state, timeslot_length_seconds = self.__update_et_provider_data()
self.__store_and_publish_updated_data(tariff_state)
self.__log_and_publish_progress(timeslot_length_seconds, tariff_state)

Fehlermeldungen werden so verschluckt und der nachfolgende Code weiß nicht, dass ein Fehler aufgetreten ist.

Copy link
Contributor Author

@tpd-opitz tpd-opitz Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das Verschlucken ist hier OK, weil ja Preise vorhanden sind und der nachfolgende Code weiter arbeiten kann. Der Fehler wird im Status angezeigt.

@benderl benderl added the user-management Anpassung an die Benutzerverwaltung erforderlich! label Feb 26, 2026
@tpd-opitz tpd-opitz requested a review from LKuemmel February 26, 2026 21:04
@tpd-opitz
Copy link
Contributor Author

@copilot
start review

@benderl
Copy link
Contributor

benderl commented Feb 27, 2026

Ich glaube, so funktioniert das noch nicht. Habe das Review manuell angestoßen.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the fixed hour tariff price calculation to use 15-minute intervals instead of hourly intervals, harmonizing it with dynamic tariffs. The changes introduce independent update mechanisms for electricity pricing and grid fees, with separate MQTT topics for next_query_time tracking. The implementation includes logic to handle grid fees that may already be included in flexible tariff prices by subtracting the median grid fee value.

Changes:

  • Refactored fixed hours tariff to generate prices in 15-minute intervals for 36 hours ahead
  • Introduced separate next_query_time tracking for flexible tariff and grid fee modules with dedicated MQTT topics
  • Implemented grid fee normalization logic that subtracts median grid fee when tariffs include grid fees

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
packages/modules/loadvars.py Changed price update trigger condition from checking next_query_time to checking configured status
packages/modules/electricity_pricing/flexible_tariffs/tibber/config.py Added update_hours and includes_grid_fee configuration attributes
packages/modules/electricity_pricing/flexible_tariffs/ostrom/config.py Added update_hours configuration for multiple daily updates
packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff_test.py Added comprehensive test suite for quarter-hour price calculations
packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/tariff.py Refactored to generate prices in 15-minute intervals for 36 hours with corrected return type
packages/modules/electricity_pricing/flexible_tariffs/fixed_hours/config.py Added update_hours configuration to enable all-day updates
packages/modules/configuration.py Enhanced exception logging with path information
packages/modules/common/store/_tariff_test.py Extended tests to cover grid fee normalization and quarter-hour alignment
packages/modules/common/store/_tariff.py Implemented grid fee price normalization and improved price summing logic
packages/modules/common/configurable_tariff.py Refactored to support independent tariff updates with per-module next_query_time calculation
packages/helpermodules/setdata.py Moved next_query_time validation to per-module topics
packages/control/optional_test.py Updated tests to support separate flexible_tariff and grid_fee tracking
packages/control/optional_data.py Moved next_query_time from global to per-module PricingGet dataclass
packages/control/optional.py Refactored price update logic to support independent module updates
Comments suppressed due to low confidence (1)

packages/control/optional.py:174

  • The return value type is inconsistent with the return type annotation. The function is annotated to return int, but line 174 returns float(timestamp) which is a float. The return type should either be changed to float or the conversion should be removed.
    def __get_current_timeslot_start(self) -> int:
        timestamp = self.__get_first_entry()[0]
        return float(timestamp)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch from 913053a to 0bec238 Compare February 28, 2026 09:16
@tpd-opitz tpd-opitz force-pushed the synchronize-fixed-hours-tariffs-with-flexible-tarifs branch from 0bec238 to 6486cc9 Compare February 28, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

user-management Anpassung an die Benutzerverwaltung erforderlich!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants