I’m using the below to trigger a different Alexa TTS message on each day which works fine…
{% if now().weekday() in [0,5,6] %}
School on Monday is 8:30 till 1:05 in week 1
{% elif now().weekday() == 1 %}
School on Tuesday is 8:30 till 3:50 in week 1
{% elif now().weekday() == 2 %}
School on Wednesday is 8:30 till 3:50 in week 1
{% elif now().weekday() == 3 %}
School on Thursday is 12:50 till 3:50 in week 1
{% elif now().weekday() == 4 %}
School on Friday is 8:30 till 3:50 in week 1
{% endif %}
What I’d like to do is move from a ‘if it’s Tuesday’ say this statement to ‘if it’s Monday AND after 4pm OR Tuesday AND before 4pm’ but have failed miserably so far.
Untested…
{% set d = now().weekday %}
{% set h = now().hour %}
{% set mon = 'School on Monday is 8:30 till 1:05 in week 1' %}
{% set tue = 'School on Tuesday is 8:30 till 3:50 in week 1' %}
{% set wed = 'School on Wednesday is 8:30 till 3:50 in week 1' %}
{% set thu = 'School on Thursday is 12:50 till 3:50 in week 1' %}
{% set Fri = 'School on Friday is 8:30 till 3:50 in week 1' %}
{% if (d == 2 and h >= 16) or (d == 3 and h < 16) %} {{ tue }}
{% elif (d == 3 and h >= 16) or (d == 4 and h < 16) %} {{ wed }}
{% elif (d == 4 and h >= 16) or (d == 5 and h < 16) %} {{ thu }}
{% elif (d == 5 and h >= 16) or (d == 6 and h < 16) %} {{ fri }}
{% else %} {{ mon }} {% endif %}
1 Like
Nice, many thanks for that, good to see I was on the right track but couldn’t fit the bits together. Understand how ‘set’ works too now
1 Like
Bit of experimentation to get it to work until I found I needed () after weekday but not hour, works a treat now thanks. Nice touch using else to cover the extra that would be needed for the weekend.
With my new found ‘set’ knowledge I then tried auto generating the messages but ended up with far more code than I started with so put everything back how it was
1 Like