A jinja macro to easily find the cheapest block of hours to know when to turn on your dryer
Why this macro
If your energy provider uses dynamic pricing, you might want to know when to turn on devices which consume a lot of power. It is relatively easy to find the lowest price on the day, but if it takes 3 hours for your dryer to complete, you might want to find the cheapest block of hours. It could be that the cheapest hour is not even in that block.
This macro comes to the rescue!
Funny note I don’t have a dynamic price contract myself. It started as a challenge to myself to get it working, and gradually expanded to what it is now. I do have the Nordpool and ENTSOE integrations installed to test, but I don’t have real life scenario’s implemented, so I’m also depending on your feedback to improve the macro even further. So please keep sending in issues/questions/other feedback.
In case you are able to reduce your energy bill by using this macro, please consider to buy me a cup of coffee
How to install
You need to have Home Assistant 2023.11 or higher installed to use this custom template.
This custom template is compatible with HACS, which means that you can easily download and manage updates for it. Custom templates are currently only available in HACS when you enable experimental features. Make sure to enable it in the HACS settings, which you can access from Settings > Devices & Services > HACS When experimental features are enabled you click the button below to add it to your HACS installation,
For a manual install you can copy the contents of cheapest_energy_hours.jinja to a jinja file in your custom_templates folder.
Run the homeassistant.reload_custom_templates service call to load the file.
How to use
See the separate documentation section on how to use the macro
Thanks to
@basbruss for providing the output mode and a lot of other additions!
The template no longer checks if data plots are complete. I’ve amended the template sensor so it will create a temporary plot while it’s running, so the complete plots are not overwritten while a new plot is created. As the plots not marked as incomplete are per definition complete, there is no need to check on that. There is also no longer a complete key to check on in the new data plots. It might be wise to check if there are incomplete plots in the sensor, and remove them.
The data plot sensor is not automatically updated through HACS, you need to do that manually!
NEW
The template now also works with energy providers with dynamic prices which update more than once per hour.
It is now possible to remove data plots from the sensor.
IMPROVEMENTS
More error messages are added
Checks on correct input for the parameters which expect a boolean are added (including error messages if not)
BUG FIXES
Version 2.1.0 introduces a whitespace issue, where the output would have some additional whitespace. This meant you could not convert it to a datetime without using trim first. This is fixed now.
I installed it thru HACS (Experimental Features enabled) and can see the jinja file in /config/custom_templates/cheapest_energy_hours.jinja.
I reloaded the Home Assistant Core Integration: Reload custom Jinja2 templates service call.
The integration I am using to pull the energy data from is EntsoE;
I use sensor “sensor.dynamische_prijzen_elektriciteit_average_electricity_price_today”; attribute is “prices_today”.
Attributes for above sensor look like this:
state_class: measurement
prices_today:
You were missing time_key and value_key in your template. The macro should have told you that, but there was an issue which should be fixed in 3.0.1 now
I will now take some time to play around with it and figure out how I can use it to steer my heat pump’s electricity consumption in function of electricity prices.
I did al the steps needed for installation and restart HA.
cheapest_energy_hours.jinja is located in in * /config/custom_templates
I also use the EntsoE integration. I use “sensor.steven_average_electricity_price_today”
Oops, my mistake
let’s say if I want to get the start datetime of an a 3 hour time block when the energy price is lowest, for today would this one be correct?
I use your jinja script for my energy data from EnergyZero.
This works fine, except when I request the time I get the UTC (English) time instead of the local (Dutch) time.