evcc icon indicating copy to clipboard operation
evcc copied to clipboard

Tariff: Changes to time-based grid fees take effect on full hour rather than at 15-minute intervals

Open zaj78 opened this issue 4 months ago • 2 comments

Describe the bug

I have configured the price changes from my grid operator on a half-hourly basis:

Image

But the half-hour jumps are not carried over:

evcc tariff grid
...
2026-07-26 05:15:00    2026-07-26 05:30:00    0.160
2026-07-26 05:30:00    2026-07-26 05:45:00    0.160
                                              ^^^^ should be 0.199 from here
2026-07-26 05:45:00    2026-07-26 06:00:00    0.160
2026-07-26 06:00:00    2026-07-26 06:15:00    0.269
...
2026-07-26 23:15:00    2026-07-26 23:30:00    0.269
2026-07-26 23:30:00    2026-07-26 23:45:00    0.269
                                              ^^^^ should be 0.230 from here
2026-07-26 23:45:00    2026-07-27 00:00:00    0.269
2026-07-27 00:00:00    2026-07-27 00:15:00    0.230
...

Steps to reproduce

  1. Add time-based grid fees to grid tariff involving tariff changes mid-hour
  2. The change takes effect only to a full hour ...

Configuration details

tariff
---
db:9 {Type:template Title: Icon: Product:Zeitabhängiger Tarif} map[chargesZones:[map[days: hours:00:00-05:30 months: price:-0.0392] map[days: hours:15:00-20:00 months: price:0.0169] map[days: hours:23:30-00:00 months: price:-0.0392]] price:0.2693 template:fixed-zones zones:[map[days: hours:02:00-06:00 months: price:0.1993] map[days: hours:12:00-16:00 months: price:0.1993] map[days: hours:18:00-21:00 months: price:0.3193]]]

Log details

No relevant TRACE logging for tariff?

[tariff] DEBUG 2026/07/25 13:14:56 using cache: grünstromindex-429615b5a6c7358aafb5229b8e0314def96776f3adb1ca7ca1cdf6c2550f9e20 (start: 2026-07-25 11:00:00 +0200 CEST, end: 2026-07-30 01:00:00 +0200 CEST)

What type of operating system or environment does evcc run on?

Linux

External automation

  • [x] I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.

Nightly build

  • [x] I have verified that the issue is reproducible with the latest nightly build

Version

evcc version 0.312.1 (36a789b5c)

zaj78 avatar Jul 25 '26 11:07 zaj78

Root cause confirmed.

The fixed-zones/fixed tariff computes rate-change boundaries only from the price zones, never from chargesZones (grid fee zones). In tariff/fixed.go, Rates() builds interval markers via zones.TimeTableMarkers(), using only t.zones (the price zones). It never factors in t.chargesZones (populated from the chargesZones config, see tariff/embed.go), so a chargesZones boundary that doesn't coincide with a price-zone boundary is silently ignored - the fee change only becomes visible once the next price-zone marker is reached (in your config those happen to be full hours: 02:00, 06:00, 12:00, ...).

This matches your example exactly: the chargesZones entry hours: 00:00-05:30 (fee -0.0392) should end at 05:30, but since no price zone boundary exists there, the old fee keeps being applied until 06:00. Same for 23:30.

Affected files:

  • tariff/fixed.go (Rates() - markers only derived from price zones)
  • tariff/fixed/zone.go (TimeTableMarkers())

This is a genuine software defect (confirmed against the code, reproducible from your config), not a configuration issue. I'll open a fix PR shortly.

🤖 Generated with Claude Code

github-actions[bot] avatar Jul 25 '26 11:07 github-actions[bot]

Now there are two overlapping series: Image

evcc tariff grid
...
2026-07-27 20:30:00    2026-07-27 20:45:00    0.336
2026-07-27 20:45:00    2026-07-27 21:00:00    0.336
2026-07-27 21:00:00    2026-07-27 21:15:00    0.269
2026-07-27 05:30:00    2026-07-27 05:45:00    0.199
2026-07-27 05:45:00    2026-07-27 06:00:00    0.199
2026-07-27 06:00:00    2026-07-27 06:15:00    0.199
2026-07-27 06:15:00    2026-07-27 06:30:00    0.199

sourcery-ai probably makes a good point with

  • When building markers from both zones and chargesZones, consider explicitly sorting the combined slice before calling TimeTableMarkers() to avoid relying on implicit ordering of the concatenated tables.

zaj78 avatar Jul 26 '26 08:07 zaj78