Condition between two dates

Rookie question - probably
On today - month 2, day 2 why does the value template below not return True

Did not get a syntax error. The condition just did not return as True.

condition: template
value_template: |

{{ (10,25) <= (now().month, now().day) <= (4, 15) }}

Which leads to the obvious question, why does HA not have a Date selection trigger of condition in the UI? Seems like lots of people would use them for seasonal lighting, heating or cooling seasons, etc.

You need to use an Or if you want to wrap around New Years… as written the template will never be true.

condition: template
value_template: |
  {% set today = (now().month, now().day) %}
  {{ (10,25) <= today or today <= (4, 15) }}

FWIW, I made a Template binary sensor Blueprint for these sorts of date range conditions/triggers:


This has been discussed in a number of previous threads on the topic. Generally, it breaks down to the fact that a date or date range on its own without time isn’t that useful as a trigger because, logically, it will fire at midnight. There are other triggers like Time, Calendar, and Sun that are often more appropriately close in time to when the desired actions should be executed.

Regarding conditions, a State condition based on a calendar entity can be used with repeating calendar events covering date spans. There was a PR for a Date condition last year, but it was closed due to the ongoing overhaul/expansion of triggers and conditions that are now being rolled out for review in Labs. I don’t see any evidence in the currently defined Tasks that a Date condition is planned, but that could be an oversight or just mean it’s a more long-term goal.

1 Like

or use not

{{ not ((4,15) <= (now().month, now().day) <= (10, 25)) }}
2 Likes

Thanks - appreciate the guidance and the Blueprint. So much for AI (Gemini)!