I created a first version, feel free to add more
DATA PROVIDER SETTINGS
Update
v5.2.0
IMPROVEMENTS
- The parameter
latest_possible
has been added. This defaults tofalse
, but when set totrue
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 is0.042
and you setprice_tolerance=0.005
all prices up to0.047
will also be considered lowest. Whenlowest=false
the same applies to the highest prices. - More information can be found in the documentation.
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
- add provider settings by @TheFes in add provider settings by TheFes · Pull Request #108 · TheFes/cheapest-energy-hours · GitHub
- add Zonneplan parameters by @TheFes in add Zonneplan parameters by TheFes · Pull Request #109 · TheFes/cheapest-energy-hours · GitHub
- Add
latest_possible
andprice_tolerance
by @TheFes in Add `latest_possible` and `price_tolerance` by TheFes · Pull Request #112 · TheFes/cheapest-energy-hours · GitHub
Full Changelog: Comparing v5.1.0...v5.2.0 · TheFes/cheapest-energy-hours · GitHub
Update
v5.3.0
IMPROVEMENTS
- A new mode:
extreme_now
has been added. This will returntrue
in case the current price matches the lowest price (or highest price in caselowest=false
). When used in combination withprice_tolerance
, which was added in v5.2.0, it will also betrue
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 likeprice_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 whenlowest=false
)
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 FIXES
- The parameters for ENTSO-E were not correct, Thanks @DutchDeffy for fixing this
- There was a bug for
mode='is_now'
whensplit
was set totrue
. This has been fixed by @Fizz55. Thanks for that!
What’s Changed
- Docs source parameter ENTSO time_key by @DutchDeffy in Docs source parameter ENTSO time_key by DutchDeffy · Pull Request #113 · TheFes/cheapest-energy-hours · GitHub
- Add
extreme_now
mode by @TheFes in Add `extreme_now` mode by TheFes · Pull Request #118 · TheFes/cheapest-energy-hours · GitHub - allow percentages for price_tolerance by @TheFes in allow percentages for price_tolerance by TheFes · Pull Request #119 · TheFes/cheapest-energy-hours · GitHub
- Fix is_now binary_sensor output for split mode by @Fizz55 in Fix is_now binary_sensor output for split mode by Fizz55 · Pull Request #117 · TheFes/cheapest-energy-hours · GitHub
- Add EnergyZero provider settings by @TheFes in Add EnergyZero provider settings by TheFes · Pull Request #120 · TheFes/cheapest-energy-hours · GitHub
- Small change on EnergyZero sensor information by @TheFes in Small change on EnergyZero sensor information by TheFes · Pull Request #121 · TheFes/cheapest-energy-hours · GitHub
New Contributors
- @DutchDeffy made their first contribution in Docs source parameter ENTSO time_key by DutchDeffy · Pull Request #113 · TheFes/cheapest-energy-hours · GitHub
- @Fizz55 made their first contribution in Fix is_now binary_sensor output for split mode by Fizz55 · Pull Request #117 · TheFes/cheapest-energy-hours · GitHub
Full Changelog: Comparing v5.2.0...v5.3.0 · TheFes/cheapest-energy-hours · GitHub
Update
v5.3.1
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
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
- Consistent usage of single/double quotes in examples by @TheFes in Consistent usage of single/double quotes in examples by TheFes · Pull Request #122 · TheFes/cheapest-energy-hours · GitHub
- Add EasyEnergy and some additional notes on the template sensor by @TheFes in Add EasyEnergy and some additional notes on the template sensor by TheFes · Pull Request #123 · TheFes/cheapest-energy-hours · GitHub
- Bugfix for extreme_now by @TheFes in Bugfix for extreme_now by TheFes · Pull Request #124 · TheFes/cheapest-energy-hours · GitHub
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!
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.
Update
v5.4.4
Sorry for all the releases today, but I had to squash some bugs For completeness I added all the changes in these release notes.
BUG FIXES
- (v5.4.4) fixed rounding of
estimated_costs
whenprecision
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 totrue
- (v5.4.2)
look_ahead
wasn’t used when a datetime object or datetime string was used as input for thestart
parameter
DOCUMENTATION
- (v5.4.2) added some additional clarification on
look_ahead
in the documentation
What’s Changed
- Fix rounding in estimated cost calcualtion by @TheFes in Fix rounding in estimated cost calcualtion by TheFes · Pull Request #133 · TheFes/cheapest-energy-hours · GitHub
Full Changelog: Comparing v5.4.3...v5.4.4 · TheFes/cheapest-energy-hours · GitHub
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?
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?
@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.
I’m not experienced (enough) with the coding, would be great to have an example of car charging based on remaining the current battery percentage.
Ie. if the car has 30% remaining, and default charging profile is set to max. 80%, would be nice to have a notification when the charge should start charging (which can be automated as well) for best price performace.
You would need the battery capacity (in my case 77kWh) and the default charging speed (11kW) in a helper I guess?
This example is based on remaining time: cheapest-energy-hours/documentation/6b-charge_car.md at 06c1ded7496b77e5ffae1a653a298a263b62ddbc · TheFes/cheapest-energy-hours · GitHub
In most situation the time only is provided when the car is actually charging, which is not the case when you just plugin the chargeconnector, then it’s narmally ‘connected - waiting to charge’.
You can plug it in, let it charge for a few minutes until you know the remaining time, then use that to determine the best time to continue charging.
You will need to know what the remaining time is, as that is a factor to determine the best time.
Yes that’s true, but not very ‘hands-off automation’.
When you know the current percentage, full capacity of the battery (kWh), and charging speed (kW) you can make a estimation of the chargetime which can be used in the code. Right? Or am I missing an element?
Somthing like this?
(ChatGPT)
sensor:
- platform: template
sensors:
ev_remaining_charge_time:
friendly_name: "EV Remaining Charge Time"
unit_of_measurement: "hours"
value_template: >
{% set battery_capacity_kWh = 77 %}
{% set charge_speed_kW = 11 %}
{% set battery_percentage = states('sensor.your_battery_percentage_sensor') | float %}
{% if battery_percentage is defined and battery_percentage > 0 %}
{% set remaining_capacity_kWh = (100 - battery_percentage) / 100 * battery_capacity_kWh %}
{% set remaining_time_hours = remaining_capacity_kWh / charge_speed_kW %}
{{ remaining_time_hours }}
{% else %}
N/A
{% endif %}
Well, batteries usually charge slower the fuller they are.
I don’t have an electric vehicle myself, so I don’t have any practical experience with how to use the macro for it. The example is based on the information provided by another user of the macro.