Second opinion on a template

I have been working on some logic and code, and just want to make sure the code matches the logic. I have been looking at this for way to long and think it works right, just want a second opinion.

Thanks!

Logic: If between May 1 and December 1 and
not Friday after 3
not Saturday
not Sunday after 3
then true, otherwise false

else (December 2 through April 30)
true

            {% if (5,1) <= (now().month, now().day) <= (12,1) %}
            {{ (not(now().isoweekday() == 5 and states('sensor.time') > '15:00') and
                not(now().isoweekday() == 6) and
                not(now().isoweekday() == 7 and states('sensor.time') > '15:00')) }}
            {% else %}
              true
            {% endif %}

You are comparing strings here which are compared left to right. In this case it will work because sensor.time has leading zeros (15:00 would be less than 2:00 but not less than 02:00), however a more correct way would be:

and now().hour >= 15

Or

and now().hour > 14
{% if (5,1) <= (now().month, now().day) <= (12,1) %}
  {% set day = now().isoweekday() %}
  {{ not(day in [5, 7] and now().hour >= 15) and not(day == 6) }}
{% else %}
  true
{% endif %}

EDIT: Fixed >= error mentioned below.

1 Like

Drew, that will be significantly different from

yours wont be true until 16:00, Monty’s is true at 15:01

See my post above.

1 Like

Thank you very much!

1 Like