Worked example · Dynamic Tariff Automation Pack

From quarter-hour prices to one decision: a worked trace

Before you buy, check exactly how the pack decides. This page feeds the pack's own dry-run fixture through its price logic, step by step. Every number below is computed from the shipped YAML and was checked on a real Home Assistant instance.

Snapshot: Wednesday 2 December 2026, 10:07 local time (CET).

Input: configs/dry-run-fixture.yaml from SWF-060 v2.1.0, at its defaults: price level 0.200 €/kWh, source age 0 minutes, outage simulation off.

Logic: the public price core swf_price.yaml, which the pack embeds byte for byte. Line numbers below refer to that file.

Method: we re-implemented the templates' maths line for line, then compared the result with the same files running in Home Assistant 2026.11.3: rank, percentile, mean and cheapest window matched. The Reproduce it section shows where to see the values yourself.

1. The input: two days of quarter-hour prices

The fixture publishes sensor.swf_price_source, the same entity a real price adapter publishes. Like a day-ahead source in the afternoon, it already holds today and tomorrow: 192 quarter-hours from local midnight today to midnight at the end of tomorrow. Each price follows a typical winter day (cheap night, morning peak, midday dip, evening peak), interpolated between hourly points, and tomorrow is 0.010 €/kWh higher. Because the rows are anchored to midnight, a quarter keeps the same price all day:

raw: >-
  {% set shape = [-0.030, -0.040, -0.050, -0.055, -0.050, -0.030,
                   0.000,  0.050,  0.070,  0.040,  0.000, -0.030,
                  -0.060, -0.070, -0.050, -0.010,  0.030,  0.080,
                   0.110,  0.090,  0.050,  0.020,  0.000, -0.020] %}
  {% set level = states('input_number.swf_demo_price_value') | float(0.2) %}
  {% set d0 = today_at('00:00') %}
  {% set start = as_timestamp(d0) | int(0) %}
  {% set tomorrow = as_timestamp(d0 + timedelta(days=1)) | int(0) %}
  {% set stop = as_timestamp(d0 + timedelta(days=2)) | int(0) %}
  {% for s in range(start, stop, 900) %}
    {% set h = s | timestamp_custom('%H', true) | int(0) %}
    {% set q = (s | timestamp_custom('%M', true) | int(0)) // 15 %}
    {% set a = shape[h] %}
    {% set b = shape[(h + 1) % 24] %}
    {% set day = 0.010 if s >= tomorrow else 0 %}
    ... 'p': (level + day + a + (b - a) * q / 4) | round(4) ...
  {% endfor %}

configs/dry-run-fixture.yaml, lines 56–76 (ships in the paid ZIP; the line that appends each row is shortened here). The fixture declares native_interval_seconds: 900 (line 50).

Rows from 10:00 to 12:00
Quarter startsQuarter in the hour (q)Price (€/kWh)
10:0000.2000
10:1510.1925
10:3020.1850
10:4530.1775
11:0000.1700
11:1510.1625
11:3020.1550
11:4530.1475
12:0000.1400

Between 10:00 (shape 0.000) and 11:00 (shape −0.030) each quarter drops by 0.0075. The cheapest quarter of the two days is today 13:00 at 0.130; the dearest is tomorrow 18:00 at 0.320.

2. Interval length and coverage

The core puts every source onto one quarter-hour grid (lines 112–139). A 15-minute source passes through unchanged. An hourly source (native_interval_seconds: 3600) becomes four identical quarters. A row whose price is missing or not a number is dropped, never filled in with the previous price, so a gap in the data stays a gap. Rows that ended more than six hours ago are left out, which is why the forecast holds 176 quarters at 10:07, not 192.

Coverage is then measured by walking forward from the current quarter and stopping at the first missing one (lines 141–162). It is not the timestamp of the last row, which could sit on the far side of a gap.

Here every quarter is present, so coverage_end is Friday 00:00: 2,273 minutes ahead of 10:07, past the end of tomorrow.

3. The fail-closed gate

Before anything is ranked, binary_sensor.swf_price_data_stale runs six checks (lines 358–391). Any failing check turns the gate on and every price signal off. The limits come from one config block:

swf_config:
  max_age_hours: 6
  publish_cutoff_hour: 16
  min_horizon_minutes: 60
  max_plausible_price: 20
  cheap_max_rank: 24
  expensive_min_percentile: 75
  min_rank_window_intervals: 16

swf_price.yaml, lines 81–104 (abridged).

Gate checks at 10:07
Reason it would reportRuleValue nowResult
no_dataforecast empty or no coverage176 quarters, coverage setpass
no_current_intervalcoverage ends at or before nowends Fri 00:00pass
insufficient_horizonless than 60 min covered ahead2,273 minpass
source_agesource not updated for more than 6 h0 minpass
tomorrow_missing_after_cutoffafter 16:00 and tomorrow not coveredtomorrow coveredpass
implausible_pricesany |price| above 20 €/kWhmax 0.320pass

Result: the gate is off with coverage: full, because tomorrow is covered. A real source shows partial in the morning, before tomorrow's prices are published; data may then be used, but nothing may be planned beyond plan_horizon_end.

4. Rank and percentile

The core compares the current price with every quarter from now until 24 hours ahead or the end of coverage, whichever comes first. At 10:07 that window holds 97 quarters (the current one plus 96 ahead). Rank is the number of strictly cheaper quarters plus one (lines 289–302):

{%- set lim = [t + 86400, cov] | min -%}
{%- for e in fc -%}
  {%- set s = e.s | int(0) -%}
  {%- set p = e.p | float(none) -%}
  {%- if p is not none and s + iv > t and s < lim -%}
    {%- set ns.w = ns.w + [p] -%}
    {%- if s <= t and t < s + iv -%}{%- set ns.cur = p -%}{%- endif -%}
  {%- endif -%}
{%- endfor -%}
{{ (ns.w | select('lt', ns.cur) | list | count) + 1 }}

swf_price.yaml, lines 289–302 (abridged).

Percentile is 100 × cheaper ÷ (quarters − 1) (line 328). binary_sensor.swf_expensive_now needs percentile ≥ 75. binary_sensor.swf_cheap_now needs rank ≤ 24 and percentile below 75, so the two can never be on at the same time, not even in a short window. Both also need at least 16 quarters in the window and the gate explicitly off (lines 476–503).

How some quarters rank inside the 10:07 window
QuarterPrice (€/kWh)RankPercentileCheapExpensive
today 13:000.130010.0yesno
tomorrow 03:000.15501110.4yesno
today 11:150.16252221.9yesno
today 23:000.18003939.6nono
today 10:00 (now)0.20005152.1nono
today 16:300.25507678.1noyes
tomorrow 08:000.28008789.6noyes
today 18:000.310097100.0noyes

25 of the 97 quarters meet the cheap rule (equal prices share a rank) and 25 meet the expensive rule. In plain words, “cheap” means “among the cheapest six hours of the next day”. The window moves every minute, so a quarter's rank can change before you reach it.

5. The decision at 10:07

Entity states at 10:07
EntityStateWhy
sensor.swf_price_now0.200 €/kWhthe 10:00–10:15 quarter
sensor.swf_price_rank_now5150 of the 97 quarters in the window are cheaper
binary_sensor.swf_cheap_nowoffrank 51 > 24
binary_sensor.swf_expensive_nowoffpercentile 52.1 < 75
binary_sensor.swf_negative_priceoff0.200 is not below 0
sensor.swf_cheapest_window_start12:00 (to 14:00)cheapest 2-hour block ending by 07:00, mean 0.1369 €/kWh

So at 10:07 a flexible load should wait: this quarter sits in the middle of the price range. The pack's advisory gate binary_sensor.swf_advisory_ev_cheap_opportunity turns on only when swf_cheap_now is on and your own readiness condition (in the example, input_boolean.swf_example_ev_ready) is on (consumer-gates-example.yaml, lines 18–23). The pack stops there: its gates are advisory binary sensors. Whatever is switched is decided by your own automation or by one of the four free SWF blueprints, which the ZIP also contains.

The cheapest-window sensor looks for the cheapest block of eight consecutive quarters ending by 07:00 (lines 546–574). Of the 77 candidate blocks, 12:00–14:00 today averages 0.136875 €/kWh, just below 12:15–14:15 at 0.1371875. The sensor only replaces its pick when a later block is strictly cheaper (line 569).

The same fixture through the day

Because the prices are anchored to midnight, the decision changes as the clock moves. With the default level:

Signals at six moments on 2 December
Local timePrice (€/kWh)Rank / quartersPercentileCheapExpensive
03:100.14508 / 977.3yesno
07:300.260078 / 9681.1noyes
10:070.200051 / 9752.1nono
13:200.13501 / 970.0yesno
18:500.295090 / 9792.7noyes
23:500.172528 / 9728.1nono

Cheap and expensive are never on together. Checked every five minutes over the whole day, cheap is on roughly 01:15–05:00 and 11:15–14:30, expensive roughly 07:00–09:00 and 16:30–20:00.

6. When the data goes wrong

This is where most price automations quietly misbehave: a missing price read as 0 looks like free electricity. In this core, sensor.swf_price_now becomes unknown, never 0 (lines 252–254). Each row below is the same 10:07 snapshot with one thing changed, using the fixture's own controls where it has them.

Failure scenarios
ChangeHow to trigger itGate reasonsCheap / expensive
Source 360 min oldinput_number.swf_demo_source_age_minutes = 360none (the limit is more than 6 h)off / off (as normal at 10:07)
Source 365 min oldsame helper = 365source_ageoff / off
Source unavailableinput_boolean.swf_demo_simulate_outage onno_data, source_ageoff / off; price unavailable
Tomorrow not published by 16:00edit a test copy of the fixture to stop at midnight tonighttomorrow_missing_after_cutoff from 16:00off / off
Negative pricesinput_number.swf_demo_price_value = −0.100 (shifts the whole curve)noneoff / off; swf_negative_price on
Gap: quarter 13:00 missingedit a test copy to skip that rownone; coverage ends 13:00 (173 min)off / off: only 12 quarters in the window, minimum is 16
Gap: quarter 11:00 missingskip that row insteadinsufficient_horizon (53 min < 60)off / off

The cutoff rule matters in real life. A day-ahead source normally publishes tomorrow's prices in the early afternoon; if they are still missing at 16:00 local time, the gate turns on with tomorrow_missing_after_cutoff. The fixture always covers tomorrow, so it passes at any hour.

A gap three hours out leaves the gate off but still silences both signals, because ranking 12 quarters says little. “Stale” means stop optimising, not stop working: the core raises one persistent notification once the gate has been on for 30 minutes (lines 629–717), the price signals stay off, and your normal schedules keep running.

Reproduce it in your own Home Assistant

  1. Install the core and the fixture on a test instance, never beside a real adapter (both publish sensor.swf_price_source).
  2. Open Developer tools → States and look at sensor.swf_price_rank_now. Its window attribute shows intervals, rank, percentile, cheapest, dearest and mean. Between 10:00 and 10:15 you should see 96 or 97, 51, 52.1 or 52.6, 0.13, 0.31 and about 0.2061. At other times, compare with the through-the-day table.
  3. Check binary_sensor.swf_price_data_stale: reasons should be empty and coverage full at any hour.
  4. Work through the failure table with the fixture's helpers and watch reasons change.

What is free and what you pay for

Everything in steps 2 to 6 lives in the free public core, swf_price.yaml. You can read, install and test it without buying anything.

The paid pack adds what turns that core into a commissioned setup: the dry-run fixture used on this page, a step-by-step commissioning, troubleshooting and rollback guide, an optional retail estimate (market × (1 + VAT/100) + network + supplier), advisory EV, heat and flexible-load gates, a dashboard, a localized guide, installation support and 24 months of compatibility updates.

For households in the Netherlands: net metering (saldering) ends on 1 January 2027. From then on, when you use electricity matters more than what your panels produce over a year. The pack does not promise savings. It gives your automations one price signal they can trust and a defined behaviour when that signal fails.