Difference between "is_state(XXX,YYY)" & "states(XXX) == YYY"

I believed that these lines are same but I was wrong:
image
The specified entity does not exist in HA.
Is it a bug or a proper behaviour?

is_state checks the state against the state string and does not perform a check when the state is None. states() returns ‘unknown’ when the state is actually None. This is a byproduct of that. I personally only use is_state when I have devices that never go ‘unknown’.

Petro, thank you for a quick reply!
There are some entities that may not be created after HA startup - for example, if some integration is not loaded properly.
What check should I perform for these entities?

I always use the 2nd one or 3rd

1 Like