You’re referencing the state in the state machine, which is the previous state. Don’t do that, replicate your logic from the value template in your icon template for unknown.
Out of curiosity: I just tried both ( {{ 'unknown' }} and states('binary_sensor.xxxx') ) and both are displaying the wanted icon battery-unknown. But I created the sensors without an availability template.
SO just to clarify and pull from the original post…
The ... in this elif
needs to replace the if here
Because using states("binary_sensor.battery_charging_xxx") inside itself is always referencing the current state machines state. During execution of this icon template, that’s the previous state.
I have no idea what STATE currently is. If it’s unknown, the logic still works because it’s not “XXX”. not STATE if populated will be FALSE and FALSE == “XXXXXX” will be false, i.e. it will hit unknown in that case.
You keep focusing on unkonwn, but there’s nothing special with it. It’s a string, not an object. There is no special case here. It’s the word ‘unknown’.
Can we just focus on your original template, the actual template instead of these tests? They don’t solve anything other than confuse everyone. Post your original issue with the original templates (not these fake templates), I’ll fix it and we can move on.
My original case is rather complex.
But results are same as in the simple example.
In short - when the value_template is unknown, the reported state is “off”.
I wanted to understand the problem, that is why I created a simple example.
Here is the output:
binary sensors restore states, did you just restart? Did you change the input_select? Again, the states machine holds the last state, not the current state. I feel like a broken record here.
The problem with “unknown” happens only to “binary_sensor”.
Only when I specify “unknown” state to the binary_sensor via “Set state” panel - the card shows “unknown” state:
Otherwise, if the “unknown” state is set in “value_template”, it anyway is “turned” to “off”.