Both are possible. As you are using the EnergyZero integration, with the template sensor, you actually have the data from yesterday as well. That gives you some more options when you want to use data overnight.
Yes, iāam using the EnergyZero intergration.
Using that template the washingmachine turned on so that is working, now i have to track the cycle and to so what are the points its using the most power so i can fine tune the proces.
I wanne thank you for this piece of code and giving me more homework
Iām getting what is probably a noob error, but I canāt get to the bottom of it. Iām testing with the templates tool, using examples taken from this page but I always get the error:
TypeError: Type is not JSON serializable: LoggingUndefined
Here is an example test template:
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours("sensor.average_electricity_price_today", attr_today='prices_today', hours=3, time_key='time') }}
The sensor.average_electricity_price_today entity contains pricing data from entsoe.
I think you have the wrong sensor. Let me check
For me this works
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{{ cheapest_energy_hours("sensor.entsoe_average_electricity_price_today", attr_today='prices_today', hours=3, time_key='time') }}
If you are sure you have the right entity, could you share the content of the prices_today
attribute?
Thanks for the reply. Here are the prices today:
state_class: measurement
prices_today:
- time: '2024-05-10 00:00:00+02:00'
price: 0.08224
- time: '2024-05-10 01:00:00+02:00'
price: 0.076
- time: '2024-05-10 02:00:00+02:00'
price: 0.07484
- time: '2024-05-10 03:00:00+02:00'
price: 0.07199
- time: '2024-05-10 04:00:00+02:00'
price: 0.0728
- time: '2024-05-10 05:00:00+02:00'
price: 0.07618
- time: '2024-05-10 06:00:00+02:00'
price: 0.09981
- time: '2024-05-10 07:00:00+02:00'
price: 0.12722
- time: '2024-05-10 08:00:00+02:00'
price: 0.07622
- time: '2024-05-10 09:00:00+02:00'
price: 0.05
- time: '2024-05-10 10:00:00+02:00'
price: 0.03407
- time: '2024-05-10 11:00:00+02:00'
price: 0.02111
- time: '2024-05-10 12:00:00+02:00'
price: 0.01779
- time: '2024-05-10 13:00:00+02:00'
price: 0.017
- time: '2024-05-10 14:00:00+02:00'
price: 0.017
- time: '2024-05-10 15:00:00+02:00'
price: 0.01764
- time: '2024-05-10 16:00:00+02:00'
price: 0.02111
- time: '2024-05-10 17:00:00+02:00'
price: 0.02559
- time: '2024-05-10 18:00:00+02:00'
price: 0.03064
- time: '2024-05-10 19:00:00+02:00'
price: 0.0383
- time: '2024-05-10 20:00:00+02:00'
price: 0.07422
- time: '2024-05-10 21:00:00+02:00'
price: 0.12722
- time: '2024-05-10 22:00:00+02:00'
price: 0.08553
- time: '2024-05-10 23:00:00+02:00'
price: 0.07517
Just checking, are you using the latest version of the macro and HA?
Almost the latest, my upgrade to the latest version of HA is blocked by a custom integration using a deprecated method.
HA Core 2024.4.4
HA OS 12.2
cheapest-energy-hours āv5.5.0ā
However Iāve just reinstalled cheapest-energy-hours and now itās working!
If OP finds this should be a separate topic, pls feel free to delete my post.
First and foremost:
Have tried few solutions to monitor an utilize dynamic electricity price, but this one is by far, the best and most flexible/most configurable solution!
Good job @thefees !
Now my issue.
Use case:
Letās say my wife (I donāt have one ) is about to cook a meal.
But, if not urgent, she might wait an hour or two, till the hour with less expensive prices. Thus, she needs to know how current hour price relates to an average price today.
- If current hour price above average price > do not switch on the oven > wait until less expensive hour.
- what is relation of the next hour to the average today
- a graph with all coming hours with actual price, plus how the price of each future hour relates to average price
e.g.
- current hour is above avg today by 40% > do not turn on oven
- next hour is 10% above avg
- in two hours price is bellow average today by 15%
then she can decide if OK to wait for the next hour (only 10% above avg) or to wait even 2 hours (when below average)
If everything nicely packed in a tablet dashboard, hanging on the kitchen wall, it can be useful tool to manage/plan an ad-hoc consumption (not to automate; for automation of huge consumption CEH already works well)
Hope I was clear with my explanation.
So the question is, can and how this be achieved with CEH?
I donāt see how the average price for today relates to all this. If you want to have your dinner ready between now and letās say 4 hours, and it needs an hour in the oven, you want the cheapest hour in the next 4 hours.
All the hours already passed earlier today donāt have anything to do with it anymore, your canāt go back in time and cook it 3 hours ago.
So you need:
- the time you really want to have it ready
- the time it needs to be in the oven (including the time to pre-heat the oven)
Both are parameters you can provide already
Right. That was a logical gap in my explanation.
So, instead of daily avg price, it should calculate avg price of the following e.g. 4 hours (or 6 orā¦).
In other words, how cheap is current hour compared to the next X hours.
Still not sure why you are focusing on average so much
Letās assume these are the prices of the next 6 hours
- hour 1: 0.8
- hour 2: 0.1
- hour 3: 0.9
- hour 4: 0.8
- hour 5: 0.3
- hour 6: 0.2
If you want it ready in 6 hours, and cooking time is 1 hour, you should be doing the cooking in hour 2
However, if cooking takes 2 hours, you should be cooking in hours 5 and 6, because the sum of those 2 hours is the lowest combination of 2 consecutive hours
If Iām searching for an āxā number of consecutive hours lowest energy price, I get the hourly price of the starting hour but the time shown belongs to the lowest hourly price within that āxā range. In an attempt to find the time associated with the starting hour, I used the hourly price (āoutputā) as an input into the ālowest=outputā parameter, but this appears to be a Boolean and thus fails. Any suggestion how I could retrieve the time associated with the established starting point of an established lowest rate range.
{%- set sensor = 'sensor.energyzero_prijzen' -%}
{% set n = now() %}
{% set hours = 4 %}
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{% set output = cheapest_energy_hours(sensor=sensor, attr_today='prices', hours=hours, start='', end='', include_tomorrow=true, lowest=True, mode='max', value_key='price', time_key='time') %}
{{output}}
{{cheapest_energy_hours(sensor=sensor, attr_today='prices', hours=hours, start='', end='', include_tomorrow=true, lowest=output, mode='time_min', value_key='price', time_key='time', time_format="time24") }}
If you want the date and time of the start of the block of consecutive hours, just use mode='start'
, or just leave the mode
parameter out, as start
is the default.
Iām also not sure why you are providing empty strings for the start
and end
parameters.
{%- set sensor = 'sensor.energyzero_prijzen' -%}
{% set hours = 4 %}
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{% set output = cheapest_energy_hours(sensor=sensor, hours=hours, include_tomorrow=true, value_key='price', time_key='time') %}
Got you, SUPER! Morover, thanks for your expeditious response.
Hi, we have a dishwasher were we manually can set a delayed start in 1 hour interval. I want a timer on my HA dashboard that shows how many hours we should set the delay to be able to run it when it is cheapest for the coming 7 hours. Dishwasher takes around 2.5 hours. Does anyone have done something similar?
With this I get the time I think, not sure if it is correct to have 07:00 in this place and I donāt know how to just show how many hours it is left:
{%- set sensor = 'sensor.nordpool_tibber' -%}
{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours(sensor=sensor, hours=2.5, start='now', end='07:00', include_tomorrow=true) }}
something like this?
{%- set sensor = 'sensor.nordpool_tibber' -%}
{%- set start = now() -%}
{%- set end = start + timedelta(hours=7) -%}
{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{% set start_time = cheapest_energy_hours(sensor=sensor, hours=2.5, start=start, end=end) | as_datetime %}
{{ time_until(start_time) }}
Yeah, that looks like it works perfect!
Would it be possible to show hours and minutes as well, for other uses?
Also do it always stay updated or does it only tigger when the nordpool prices changes?
It updates every minute, because now()
is used
You can use something like time_until(datetime, 2)
to show two time fractions. Based on the time difference it will show different time fractions. Like 2 days and 3 hours
or 2 minutes and 40 seconds
Excellent, thank you!