#State attribute shows None, but cannot write check on that

1 messages · Page 1 of 1 (latest)

tawdry forge
#

Here's the catch:

{{ state_attr('fan.microwave_fan', 'preset_modes') }} -> None
{{ state_attr('fan.microwave_fan', 'preset_modes') is None }} -> TemplateAssertionError: No test named 'None'.
{{ state_attr('fan.microwave_fan', 'preset_modes') is defined }} -> True
{{ state_attr('fan.microwave_fan', 'preset_modes')|default([]) }} -> None
{{ state_attr('fan.microwave_fan', 'preset_modes') == "None" }} -> False

What to do?

#

Answering myself. Use

{{ state_attr('fan.microwave_fan', 'preset_modes') == none }}

For some reason lowercase.

steel salmon
#

It needed no quotes, you were checking for the string "None" not the none-type object none

#

And the test is lowercase, so state_attr('foo', 'bar') is none would also have worked

steel salmon
#

And with state_attr('foo', 'bar') | default([], true) you would have got the empty list

#

with the true parameter the default is also applied to falsely values

tawdry forge
#

Oh, great! Thank you!

tawdry forge