Why does 'None' appear to be handled inconsistently?

None is how a null value is represented. For example, I have an entity whose attribute, pattern, is reported to be null in the States page:

Screenshot%20from%202019-07-24%2009-10-50

When tested in the Template Editor, it behaves exactly the same way as your device_tracker's attribute does:

I don’t have insight into how the is_state_attr function performs its comparisons but it’s clear it doesn’t like comparing to a null value. In contrast, the equivalence operator == handles a null value properly.

Your second example, involving true and false, works as one would expect. A boolean value (true/false) is never a null value so is_state_attr handles it correctly.


EDIT
The function is_state_attr is located in Home Assistant’s template.py file. I believe this line of code is responsible for how it handles a comparison with None (null value).

return attr is not None and attr == value

It returns a result but only if its not None (except in this case, it is None so it returns nothing).

2 Likes