I cannot figure out what I am doing incorrectly when I'm trying to compare two values. The following code shows the code I'm working on (with some debugging added):
1 {% set next_midnight = state_attr('sun.sun', 'next_midnight') | as_datetime %}
2 next_midnight = {{ next_midnight }} ({{next_midnight | typeof}})
3 {% for attr in states.sun.sun.attributes %}
4 checking {{ attr }} : {{ states.sun.sun.attributes[attr] }} : {{ state_attr('sun.sun', attr)}}
5 {% set value = state_attr('sun.sun',attr) | as_datetime %}
6 value = {{ value }} ({{ value | typeof}})
7 {{ value , next_midnight }}
8 {% endfor %}
lines 2 and 6 show that the items I wish to compare (value and next_midnight) are both datetimes.
line 7 shows the values of both items.
However, change the comma (,) in line 7 to a less than (<) then code fails with
TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
I can't figure out why this is happening when value and next_midnight are both datetimes.
Any help would be appreciated