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â.