Need some help with template for binary sensor

Monsoon in Arizona runs from June 15th until September 30th.

I’m trying to create a template for a binary sensor, but it’s breaking my brain :frowning:

This is what I have, but I know it’s not right:

{% if now().month > 9 
  or 
      now().month < 6 
  or 
     (now().month == 6 and now().day < 15) %}
 Off
{% else %}
 On
{% endif %}

Can anybody please confirm I’m on the right track?

The template is okay, just a little verbose.

A good way to do month & day comparisons is to use tuples:

{{ (6, 15) <= (now().month, now().day) <= (9, 30) }}
1 Like

Didn’t know one could do that - thanks!