Create template to check that I am between 2 dates

Hello,

I am creating an automation that I only want to run at 20:00 only between the 1st of November and the 31st of December.

In the automation in the first option, when: Put time = 20:00

In the second option and if, I wanted to put only between 1 November and 31 December. I have not found any date tool so the only option I can think of is to do with a template that returns TRUE or FALSE.

Can you help me?

You could create two date/time helpers, and use those in the condition, by selecting Time and Value of a date/time helper or timestamp-class sensor.

Or you could create a template binary sensor:

- binary_sensor:
    - name: "Last Two Months"
      state: "{{ now().month > 10 }}"
1 Like

You can use easy time as a condition.

condition: template
value_template: >
  {% from 'easy_time.jinja' import month_day %}
  {{ month_day(11, 1) | as_datetime <= now() <= month_day(12, 31) | as_datetime }}

Or just a simple template condition:

{{ now().month >= 11 }}

thanks. works perfectly!

1 Like