Zonneplan - Dynamic Energy pricing and three lowest hours

I’ve a dynamic Zonneplan dynamic energy contract, energy pricing changes per hour. The Dishwasher, washing machine etc, takes about 2 to 3 hours. I want to determine the lowest energy price during 3 sequential hours. In other words, determining the best three hours to which on one of the appliances. Any suggestions on how to do this?

The code to determined the cheapest hour I’ve found on the internet is:

{% set cheapest_hour_next_ten_hours = state_attr(‘sensor.zonneplan_current_electricity_tariff’, ‘forecast’)
| selectattr(‘datetime’, ‘>’, utcnow().isoformat())
| selectattr(‘datetime’, ‘<’, (utcnow() + timedelta(hours = 40)).isoformat())
| sort(attribute=‘electricity_price’)
| first %}
{{ as_timestamp(cheapest_hour_next_ten_hours.datetime) | timestamp_custom(‘%a %d %b %H:%M’) }}

Maybe this helps in answering my question. Thanks for your support.

check this: GitHub - TheFes/cheapest-energy-hours: Jinja macro to find the cheapest energy prices

1 Like

Thanks, this Macro is looking promosing, this is what I need.

Try to understand how to use this macro is still a bit of a challenge for me. Need to reread the documents, but for me they are not so clear yet on how to use the macro.

In my experience @TheFes is always eager to help. So if you get stuck, you can make a new topic and mention that you use the macro

Yes, please let me know if you need help

I’ve installed the Macro via HACS, that was something easy.

What is next? I want to know the cheapest 3 hours for the upcoming Zonneplan energy pricing forcast so that I can start the dishwashing machine. How do I do that? That is my main challenge at the moment.

You will have to create a template sensor. Do you want it to run overnight, or during the day?

Everyday Zonneplan announces the new energy pricing at 13.00 and last until 0.00 the day after, meaning about max 35 hours forecast. At this moment there is not specific time when the dishwasher needs to be switched on, but lets say within 12 hours or so. Does this answer your question?

I’m trying to run this example in the Developer Tools → Template environment:

{% from ‘cheapest_energy_hours.jinja’ import cheapest_energy_hours %}
{% set output = cheapest_energy_hours(sensor=‘sensor.cheap_energy’, hours=2.25, start=‘12:00’, end=today_at(‘19:00’) + timedelta(days=1), look_ahead=true) %}

But this give me a error: TypeError: ‘>’ not supported between instances of ‘str’ and ‘datetime.datetime’

So I’m still at the basics of the syntax of the template coding. Sorry.

That error comes from the macro, I will need to look into that.

Where does sensor.cheap_energy come from? You were referring to a different entity in your start post

My mistake, I didn’t change the sensor name. Sorry. I thought the cheap_energy was a reference or so to the Macro. I’ve got it working now.

This is my output now: 2024-10-10T12:45:00+02:00

How should I read this output? Cheapest price is on 10 October at 12:45 + 2 hours? If so, then I don’t understand why X:45! Zonneplan has different pricing per hour, not per 45 min or so.

Aha, still learning, de X:45 is was because of the input parameter. I’m going to play with the Macro and see how I can use it. Excellent. this is looking good. Thanks for the support.

@TheFes are you able to give me some hints with regards to creating the template sensors? My goal is, when the door of the Dishwasher is closed and remote start is set that at that moment the cheapest time is determined and the time trigger to start the Dishwasher via an automation is set.

Following the examples I’m not able to work this out. Creating an Automation when the door is closed and with the condition is Remote start is set is possible, but how to execute the macro to determine the time and howto set the time for the next automation? That is my challenge at the moment.

You need to create a trigger based template sensor, which triggers on the door closing and the program being set. Trigger based template sensors can only be created using YAML, they can’t be created in the GUI.
Is there also a sensor indicating the duration of the set program?

This template sensor will then give the start time of the program. You can then use that in an automation to actually start the dishwasher.

Aha, that explains it why I cannot find it, through the GUI it is not possible.

The trigger for the door close would be (copied from an automation):

type: not_opened
device_id: db69fb2bab81ab0c258c720aac625c19
entity_id: 3f0fd8c77e4a55af22bc701fe50e4e36
domain: binary_sensor
trigger: device

How would the trigger template look like? Can you help me on this? And where should I put the YAML code? In the sensors.yaml file?