How to use time in a format suitable for if-then-else testing

Hi all,
I need help to sort this one out:

{% if now().strftime('%T') > strptime('09:30:00', '%T') and
      now().strftime('%T') < strptime('10:30:00', '%T') %}
  Do-Something
{% elif is_state('script.test', 'off') %}
  Run Script
{%- else -%}
  Stop
{%- endif %}

The issue here is that strftime returns a string and not a number. So testing if current time is inside or outside a certain time interval becomes impossible as the string ‘9’ in this test i greater then the string ‘10’

I have not been able to figure out the correct syntax to accurately perform such a test.
Please help.

Viking

I’m no expert in Python Time, I find it excruciatingly complex :slight_smile: and always have to relearn it every time I want to do something like this but I’m sure you will get an answer from elsewhere.

In the meantime have you seen this?

And also, I am interested in what you plan to do in here?

{%- else -%}
  Stop
{%- endif %}

Use |int:

{% if now().strftime('%T')|int > strptime('09:30:00', '%T')|int and
      now().strftime('%T')|int < strptime('10:30:00', '%T')|int %}

@tinkerer,
Thank you for the advice, but it didn’t quite work out the way I hoped for.

strptime('09:30:00', '%T')|int

This will always return the number zero (0) as the int will not work on a string value.

For anyone following along I replied to his post in the other thread but I’ll re-post here for continuity: