Cheapest Energy Hours - Jinja macro for dynamic energy prices

Since the update the sensor hasn’t been unavailable again, so it looks like the bug is fixed! Thank you again for your quick support and enjoy your :coffee:

1 Like

Dit it also turn on at the cheapest moment?

Update

v5.1.0

:sparkles: IMPROVEMENTS

  • This version adds support for data sources which don’t provide the date and time in the list with prices. 2 new parameters are added: datetime_in_data (defaults to true) and data_minutes (defaults to 60, only used when datetime_in_data is set to false). More information can be found in the documentation

What’s Changed

Full Changelog: Comparing v5.0.3...v5.1.0 · TheFes/cheapest-energy-hours · GitHub

Yes it did turn on. I made a steel column for the final 3 phase charger, but the paint is still drying. Once I’ve installed the final charger I’ll be able to use the sensor to charge the car. Then I can see if it fully works as intended, but I have no reason to think it won’t.

Are you open to adding examples/settings for specific energy providers to the github repo? That way people with Zonneplan can easily use my config and others could add other providers.

The only differences per energy provider are in the source data settings. But I’m open to adding another section there with the attribute and key settings for each provider.

I created a first version, feel free to add more
DATA PROVIDER SETTINGS

Update

v5.2.0

:sparkles: IMPROVEMENTS

  • The parameter latest_possible has been added. This defaults to false, but when set to true it will use the end of the time block in case all prices are the same instead of the start. This can be useful if you want to turn on a boiler during the night, and want to avoid the water cools down again while you are sleeping.
  • The parameter price_tolerance has been added. This allows to set a tolerance within prices will be considered lowest. Eg, if the lowest price is 0.042 and you set price_tolerance=0.005 all prices up to 0.047 will also be considered lowest. When lowest=false the same applies to the highest prices.
  • More information can be found in the documentation.

:books: DOCUMENTATION

  • Provider settings have been added to the README, you can help by providing the settings for your provider. See documentation for more information.

What’s Changed

Full Changelog: Comparing v5.1.0...v5.2.0 · TheFes/cheapest-energy-hours · GitHub

Update

v5.3.0

:sparkles: IMPROVEMENTS

  • A new mode: extreme_now has been added. This will return true in case the current price matches the lowest price (or highest price in case lowest=false). When used in combination with price_tolerance, which was added in v5.2.0, it will also be true if the current price is within the set tolerance compared to the lowest (or highest) price.
  • price_tolerance now accepts percentages. So you can use something like price_tolerance="5%" instead of a fixed tolerance. The percentage will be used to calculate the price tolerance based on the lowest price in your time range (or hightest price when lowest=false)

:books: DOCUMENTATION

  • Provider settings for EnergyZero have been added. These settings require to setup a trigger based template sensor to make the prices availalbe for the macro. See documentation.

:bug: BUG FIXES

  • The parameters for ENTSO-E were not correct, Thanks @DutchDeffy for fixing this
  • There was a bug for mode='is_now' when split was set to true. This has been fixed by @Fizz55. Thanks for that!

What’s Changed

New Contributors

Full Changelog: Comparing v5.2.0...v5.3.0 · TheFes/cheapest-energy-hours · GitHub

Update

v5.3.1

:bug: BUG FIXES

  • The code for the extreme_now mode caused an error when the current time was outside the time in scope. This has been fixed

:books: DOCUMENTATION

  • EasyEnergy has been added to the providers, and some additional notes have been added to the section about the template sensor needed for EnergyZero and EasyEnergy
  • Usage of single and double quotes was not consistant in the documentation.

What’s Changed

Full Changelog: Comparing v5.3.0...v5.3.1 · TheFes/cheapest-energy-hours · GitHub

Thanks for all your work @TheFes !
I configured a template to get the cheapest hours to start the dishwasher in the cheapest hours between 0:00 and 8:00h. My energy provider is Zonneplan.

{{ cheapest_energy_hours(sensor=‘sensor.zonneplan_current_electricity_tariff’, hours=2.7, start=‘0:00’, end=‘08:00’, include_tomorrow=true) }}

The first time I used the template it worked well, but the other day the status is a date and time in the past. Do you have any idea how to fix that?
I think it has something to do with the fact that Zonneplan gives the prices for today and tomorrow in one ‘variable’.
I hope there is a solution for it, because I like the macro a lot! :smiley:

Your selection now gives the cheapest 2.7 hours from today and the first 8 hours tomorrow. So the total hours number of hours which are checked are 24 + 8 = 32 hours.
It you only want tomorrow, you need to exclude today, so add include_today=false
Do note that you need to use a trigger based template sensor or automation to make sure the datetime is known after midnight (when you actually need it). Otherwise it will start looking for the data of the next day, which won’t be available yet

update:
If you want to create the sensor as a template helper in the GUI, you can do this:

{% set today = now() < today_at('16:00') %}
{% set start = today_at('00:00') + timedelta(days=0 if today else 1) %}
{% set end = today_at('08:00') + timedelta(days=0 if today else 1) %}
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours(sensor='sensor.zonneplan_current_electricity_tariff', hours=2.7, start=start, end=end) }}

This will show the best time for today until 16:00, after that it will show the best time for tomorrow. After 16:00 the prices for tomorrow should be available.

2 Likes

Update

v5.4.4

Sorry for all the releases today, but I had to squash some bugs :slight_smile: For completeness I added all the changes in these release notes.

:bug: BUG FIXES

  • (v5.4.4) fixed rounding of estimated_costs when precision parameter was set.
  • (v5.4.3) fix a pedmas error which would add a second to the start time
  • (v5.4.2) the start time returned by the macro was sometimes in the past when look_ahead was set to true
  • (v5.4.2) look_ahead wasn’t used when a datetime object or datetime string was used as input for the start parameter

:books: DOCUMENTATION

  • (v5.4.2) added some additional clarification on look_ahead in the documentation

What’s Changed

Full Changelog: Comparing v5.4.3...v5.4.4 · TheFes/cheapest-energy-hours · GitHub

3 Likes

Just installed the Jinja macro and Nordpool.

Having issues with testing the template in the Developer Tools menu, using the basic example provided in the documentation but HASS gives:
TemplateNotFound: cheapest_energy_hours.jinja

I’m new to the topic so perhaps I missed something?

@ivarv How did you install it? Using HACS or manually?

Via HACS, Nordpool as well.

Do you have a cheapest_energy_hours.jinja file in your custom_templates folder?

Its in the standard HACS Lovelace folder, I thought it was a integration but it installed as lovelace plugin. I couldn’t find anything in the documentation on this.

Should it be somewhere else then?

Screenshot 2024-03-19 at 19.54.04

@ivarv You placed it there yourself?

It should be placed in the custom_templates folder as explained here

That’s also where HACS will place it if you install it using HACS. Which requires experimental mode to be enabled as explained in the same section linked above.

Did you manage to get it running?

Yes, with the toggle of experimental it works, thanks. Looked over it.