WTH can't I use a template for Time Conditions

It would be really nice to be able to use template values for a time condition.

something like:

  - condition: time
    after: "{{ states('input_datetime.start_time') }}"
    before: "{{ states('input_datetime.finish_time') }}"

Instead of having to do multiple conditions to compare the current time converted to a string or int to an input_datetime converted to a string or int:

    - condition: template
      value_template: "{{ now().strftime('%H%M%S') | int >= states('input_datetime.start_time') | replace(':', '') | int }}"
    - condition: template
      value_template: "{{ now().strftime('%H%M%S') | int <= states('input_datetime.finish_time') | replace(':', '') | int }}"

Umm, I don’t know if I’m missing something here but as per the time conditions in the docs you linked to, you can just put the input datetime directly into the time conditions before and after keys without requiring a template.

Anything more than that is a template condition anyway, which has also been ‘shorthanded’ to reduce the amount of code required.

Your first example would be

  - condition: time
    after: input_datetime.start_time
    before: input_datetime.finish_time

And your second is covered by that too, but if you actually did need a template it would simply be

- condition: "{{ your template here }}"

Thanks. Not sure how I missed that after reading through it so many times.

1 Like

Turns out both of your solutions were part of today’s release - that’s how I had missed it so many times!