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).
| Quarter starts | Quarter in the hour (q) | Price (€/kWh) |
|---|---|---|
| 10:00 | 0 | 0.2000 |
| 10:15 | 1 | 0.1925 |
| 10:30 | 2 | 0.1850 |
| 10:45 | 3 | 0.1775 |
| 11:00 | 0 | 0.1700 |
| 11:15 | 1 | 0.1625 |
| 11:30 | 2 | 0.1550 |
| 11:45 | 3 | 0.1475 |
| 12:00 | 0 | 0.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).
| Reason it would report | Rule | Value now | Result |
|---|---|---|---|
no_data | forecast empty or no coverage | 176 quarters, coverage set | pass |
no_current_interval | coverage ends at or before now | ends Fri 00:00 | pass |
insufficient_horizon | less than 60 min covered ahead | 2,273 min | pass |
source_age | source not updated for more than 6 h | 0 min | pass |
tomorrow_missing_after_cutoff | after 16:00 and tomorrow not covered | tomorrow covered | pass |
implausible_prices | any |price| above 20 €/kWh | max 0.320 | pass |
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).
| Quarter | Price (€/kWh) | Rank | Percentile | Cheap | Expensive |
|---|---|---|---|---|---|
| today 13:00 | 0.1300 | 1 | 0.0 | yes | no |
| tomorrow 03:00 | 0.1550 | 11 | 10.4 | yes | no |
| today 11:15 | 0.1625 | 22 | 21.9 | yes | no |
| today 23:00 | 0.1800 | 39 | 39.6 | no | no |
| today 10:00 (now) | 0.2000 | 51 | 52.1 | no | no |
| today 16:30 | 0.2550 | 76 | 78.1 | no | yes |
| tomorrow 08:00 | 0.2800 | 87 | 89.6 | no | yes |
| today 18:00 | 0.3100 | 97 | 100.0 | no | yes |
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 | State | Why |
|---|---|---|
sensor.swf_price_now | 0.200 €/kWh | the 10:00–10:15 quarter |
sensor.swf_price_rank_now | 51 | 50 of the 97 quarters in the window are cheaper |
binary_sensor.swf_cheap_now | off | rank 51 > 24 |
binary_sensor.swf_expensive_now | off | percentile 52.1 < 75 |
binary_sensor.swf_negative_price | off | 0.200 is not below 0 |
sensor.swf_cheapest_window_start | 12: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:
| Local time | Price (€/kWh) | Rank / quarters | Percentile | Cheap | Expensive |
|---|---|---|---|---|---|
| 03:10 | 0.1450 | 8 / 97 | 7.3 | yes | no |
| 07:30 | 0.2600 | 78 / 96 | 81.1 | no | yes |
| 10:07 | 0.2000 | 51 / 97 | 52.1 | no | no |
| 13:20 | 0.1350 | 1 / 97 | 0.0 | yes | no |
| 18:50 | 0.2950 | 90 / 97 | 92.7 | no | yes |
| 23:50 | 0.1725 | 28 / 97 | 28.1 | no | no |
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.
| Change | How to trigger it | Gate reasons | Cheap / expensive |
|---|---|---|---|
| Source 360 min old | input_number.swf_demo_source_age_minutes = 360 | none (the limit is more than 6 h) | off / off (as normal at 10:07) |
| Source 365 min old | same helper = 365 | source_age | off / off |
| Source unavailable | input_boolean.swf_demo_simulate_outage on | no_data, source_age | off / off; price unavailable |
| Tomorrow not published by 16:00 | edit a test copy of the fixture to stop at midnight tonight | tomorrow_missing_after_cutoff from 16:00 | off / off |
| Negative prices | input_number.swf_demo_price_value = −0.100 (shifts the whole curve) | none | off / off; swf_negative_price on |
| Gap: quarter 13:00 missing | edit a test copy to skip that row | none; coverage ends 13:00 (173 min) | off / off: only 12 quarters in the window, minimum is 16 |
| Gap: quarter 11:00 missing | skip that row instead | insufficient_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
- Install the core and the fixture on a test instance, never beside a real adapter (both publish
sensor.swf_price_source). - Open Developer tools → States and look at
sensor.swf_price_rank_now. Itswindowattribute showsintervals,rank,percentile,cheapest,dearestandmean. 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. - Check
binary_sensor.swf_price_data_stale:reasonsshould be empty andcoveragefullat any hour. - Work through the failure table with the fixture's helpers and watch
reasonschange.
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.