TheFes / cheapest-energy-hours

Jinja macro to find the cheapest energy prices
GNU General Public License v3.0
85 stars 9 forks source link

can I get the cheapest hour today AND tomorrow within a timespan (08:00-20:)00? #174

Open TylonHH opened 1 day ago

TylonHH commented 1 day ago

So this is my sensor so far. I use the integrated tibber source sensor. after 13 oclock I have the data from tomorrow.

{%- set sensor = 'sensor.tibber_forecast' -%}
          {% from 'cheapest_energy_hours.jinja' import cheapest_energy_hours %}
          {{ cheapest_energy_hours(sensor=sensor, hours=3, start='06:00', end='20:00', include_tomorrow=true, look_ahead=true) }}

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?

TheFes commented 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.

TylonHH commented 1 day ago

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.

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.

TheFes commented 1 day ago

starting at what time do you want to include the part after 20:00 of the current day?

TylonHH commented 1 day ago

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.

TheFes commented 23 hours ago

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?

TheFes commented 23 hours ago

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?

TheFes commented 23 hours ago

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 }}
TylonHH commented 11 hours ago

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?