Open TylonHH opened 1 day ago
sorry, I don't really understand which time period you want to use now. What you have now will give you start time of the cheapest consecutive 3 hour period starting now (unless it is before 6:00 in the morning, then it will start at 6:00) and ending tomorrow at 20:00, unless that data is not available yet, then it will be ending at midnight.
If you want to ensure it uses tomorrows data as well, you need to make sure the template is only rendered when tomorrows data is available, so if that is after 13:00 you can make a trigger based template sensor which does that for you.
My goal is to identify the cheapest 3-hour window, adapting based on the time of day, but only between 6:00 and 20:00.
Morning (e.g., 5:00 AM): Evaluate today’s data only, finding the cheapest 3-hour period between 06:00 and 20:00.
Afternoon (e.g., 15:00): Evaluate today’s remaining hours AND tomorrow’s data (if available after 13:00) to find the cheapest 3-hour period between 06:00 and 20:00 rest of today AND between 6-20 tomorrow.
I aim to ensure accurate data consideration based on availability, potentially using different sensors or templates for morning and afternoon. Let me know if this aligns with what you’re suggesting.
starting at what time do you want to include the part after 20:00 of the current day?
I don’t want to include any period after 20:00 of the current day. Instead, from that point onwards, the slot for the next day should be determined, as the prices are already available. I do not expect a time slot at 2 AM or during the night.
so, from what point onward do you want to use the data from tomorrow? Is that only after 20:00, or earlier on the day already?
ah wait, I get it now. You can't do that in one template You need to do today, and tomorrow, and compare them.
So if the data from tomorrow is available, what do you want to see? The cheapest one between today and tomorrow? The earliest one? Both?
I think this is what you want
{% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
{% set sensor = 'sensor.nordpool_kwh_nl_eur_3_10_021' %}
{% set today = cheapest_energy_hours(sensor, start='06:00', end='20:00', look_ahead=true, mode='all', value_on_error={}) | from_json %}
{% set tomorrow = cheapest_energy_hours(sensor, start='06:00', end='20:00', mode='all', include_today=false, include_tomorrow=true, value_on_error={}) | from_json %}
{{ [today, tomorrow] | select() | sort(attribute='avarage') | map(attribute='start') | first }}
Awesome... seems to work. I will have an eye on it.
Really great work.
Bonus: I saw in the output docs there is an 'average' for the average price of the slot. Do I need a second sensor to get this?
So this is my sensor so far. I use the integrated tibber source sensor. after 13 oclock I have the data from tomorrow.
I got 2024-11-15T02:00:00+01:00
Is it easy possible, or do I have to use two sensors and take care when thy will be set? the best would be if I calculate the timestamp once a day at 13oclock, wouldnt?