Do you know the Cheapest Hours Ninja macro?
TheFes/cheapest-energy-hours: Jinja macro to find the cheapest energy prices
With these few simple lines of code you will get the same result:
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours(
sensor='sensor.zonneplan_current_electricity_tariff',
hours=8,
lowest=false,
attr_all='forecast',
look_ahead=false,
split=true,
value_key='electricity_price',
mode='all'
) }}
This is the result for now:
[
{
"start": "2025-10-27T08:00:00+01:00",
"end": "2025-10-27T10:00:00+01:00",
"hours": 2,
"prices": [
2567546,
2576680
],
"is_now": false
},
{
"start": "2025-10-27T16:00:00+01:00",
"end": "2025-10-27T22:00:00+01:00",
"hours": 6,
"prices": [
2640840,
2757455,
2968298,
2876882,
2591230,
2517662
],
"is_now": false
},
{
"total_hours": 8,
"datapoints_per_hour": 1,
"datapoints": 8
}
]
It is compatible with entsoe and nordpool sensors. check it out.
You can paste the following in a boolean helper to get a true/false to trigger expensive/cheap hours.
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours(
sensor='sensor.zonneplan_current_electricity_tariff',
hours=8,
lowest=false,
attr_all='forecast',
look_ahead=false,
split=true,
value_key='electricity_price',
mode='is_now'
) }}
(only thing I changed is mode='is_now')