What am I missing… been staring at this for hours now, and the individual bits are correct, the complete template simply doesn’t output:
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in [0,1,2,3,4]
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now %}
{% if (now().weekday() in [0,1,2,3,6] and is_state('input_boolean.alarmclock_wd_enabled','on')) or
(now().weekday() in [4,5] and is_state('input_boolean.alarmclock_we_enabled','on')) %} Tomorrow
{% else %} Not tomorrow
{% endif %}
{% elif alarm == 'Not set' %} Not set
{% else %} Today
{% endif %}
the sub If…else works fine:
{% if (now().weekday() in [0,1,2,3,6] and is_state('input_boolean.alarmclock_wd_enabled','on')) or
(now().weekday() in [4,5] and is_state('input_boolean.alarmclock_we_enabled','on')) %} Tomorrow
{% else %} Not tomorrow
{% endif %}
and the structure template also:
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in [0,1,2,3,4]
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now %} Without sub template
{% elif alarm == 'Not set' %} Not set
{% else %} Today
{% endif %}
(flipped a boolean, so the first template changed output…
If I reverse turn both templates around in dev-template, nothing is displayed, so something must be wrong, can’t spot it though…
if I only test the {{alarm < now}} the outcome is correct:
But it won’t render that part of the If correctly.
it does run when alarm > now, using the else of the structure template…
Please have a look?
Might even want to do:
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in [0,1,2,3,4]
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now and
(now().weekday() in [0,1,2,3,6] and is_state('input_boolean.alarmclock_wd_enabled','on')) or
(now().weekday() in [4,5] and is_state('input_boolean.alarmclock_we_enabled','on')) %} Tomorrow
{% elif alarm == 'Not set' %} Not set
{% else %} Today
{% endif %}
to make it simpler…
this works also, so it must the sub template:
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in [0,1,2,3,4]
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now %}
{% if 1==1 %} Tomorrow
{% else %} Not tomorrow
{% endif %}
{% elif alarm == 'Not set' %} Not set
{% else %} Today
made an intermediary sensor:
test_tomorrow_alarm:
friendly_name: Test tomorrow alarm
value_template: >
{{(now().weekday() in [0,1,2,3,6] and is_state('input_boolean.alarmclock_wd_enabled','on')) or
(now().weekday() in [4,5] and is_state('input_boolean.alarmclock_we_enabled','on'))}}
which makes this possible:
next_alarm_today_full:
friendly_name: Next alarm today full
value_template: >
{% set alarm = states('sensor.alarmclock_wd_time') if now().weekday() in [0,1,2,3,4]
else states('sensor.alarmclock_we_time') %}
{% set now = now().time().strftime('%H:%M')%}
{% if alarm < now %}
{% if is_state('sensor.test_tomorrow_alarm','True') %} Tomorrow
{% else %} Not tomorrow
{% endif %}
{% elif alarm == 'Not set' %} Not set
{% else %} Today
{% endif %}
which gets me the desired result finally.
Really can’t see why the original setup doesn’t work though… How can that be?