Difference between Unknown, Unavailable, None and Null

Maybe this is a dumb question, but I didn’t understand the difference between these special states (unknown, unavailable, none). When do they occur?

From my tests, I saw that most of my template sensors start as ‘unknown’ for a few seconds after restart before getting a real value.

Can someone enlighten me, please?

This is how I understand those states.
Hope it is not all wrong.

Unknown is when the entity has no valid state, like a sensor just after boot or a tracker that have not been seen for a long time and the values are therefore expired.

Unavailable is when a sensor does not have a v.alid value but it has an error state instead, like timeout.
Sometimes a sensor can be first unknown then the integration is loaded and it becomes unavailable and then it gets updates and gets a normal state.

None is state that means undefined.
You might have a counter sensor, but it has not been initialized to a value yet and therefore it is None.
In other parts of the computer works this might be called null also.
None or null is not zero though, so a counter of zero is a different value than null.

None/null seem to be not fully thought through, imho, so the dev might not have had all the options in mind (or known). the other two seem OK as explanation.

I think the most important is to understand the state “none” (HA) is NOT the same as the value None (python).
Also, states are always strings.

State “unknown” is when the logic didn’t reach the entity.
This may be because it hasn’t loaded/triggered yet or it just doesn’t exist at all.

State “unavailable” is when the logic reached a existing entity and it can define whether its current state is deterministic or not.
For example, a sensor without power source. The entity exist, but we can’t say anything about its current state.
Another example, a template binary sensor that can’t say for sure whether it is “on” or “off” (deterministic state).

Everything else is part of some valid domain.
I mean, “none” is just like any other state “off”, “standby”, “<not connected>”, “closed”, … someone just decided that the word “none” would make more sense for some specific entity (state class).
The only example I found in my case is the entity “charger type” of my phone when it isn’t charging.

2 Likes