TheFes / cheapest-energy-hours

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

Error: No data within current selection when endtime tomorrow and look_ahead=true #79

Closed rrooggiieerr closed 1 year ago

rrooggiieerr commented 1 year ago

I'm getting the error message Error: No data within current selection when I'm using an end time somewhere tomorrow AND look_ahead = true

{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours('sensor.nordpool_electricity_price', end="01:00", look_ahead=true) }}

Response: Error: No data within current selection

{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours('sensor.nordpool_electricity_price', end="23:00", look_ahead=true) }}

Response: Error: 2023-11-11T22:00:00+01:00

This works fine:

{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours('sensor.nordpool_electricity_price', end="01:00") }}

Response: 2023-11-11T00:00:00+01:00

This too:

{% from "cheapest_energy_hours.jinja" import cheapest_energy_hours %}
{{ cheapest_energy_hours('sensor.nordpool_electricity_price', look_ahead=true) }}

Response: 2023-11-11T23:00:00+01:00

I'm using v4.2.3 of the script

TheFes commented 1 year ago

If you don't include the data of tomorrow (include_tomorrow is set to false by default) then ending your dataset at 01:00 only gives one hour of data (00:00 - 01:00 of last night). Your first template will only work at between 00:00 and 00:05

look_ahead=true does not automatically set include_tomorrow=true

rrooggiieerr commented 1 year ago

Ok, makes sense. I'm quite sure it did work without include_tomorrow in previous versions thought. Thanks for explaining the correct working of your script

TheFes commented 1 year ago

If it worked previously, it wasn't by design.

In the current version you can also use end=today_at('01:00')+timedelta(days=1)