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.
Because you’re talking past the original issue, which is your icon template and you’re focusing on this completely unrelated question. Do you want to fix your unknown icon or what?
“He” did restart even after changing a code.
Then I played with input_select, and changing the “input_select” was supposed to change the binary_sensor too.
Right, which has been explained. If you just restarted after executing your logic, it should restore your previous state.
Then the word ‘unknown’ being output should result in on or off, because binary sensors only accept on, off, or none. All other words resolve to either on or off because that’s how the resolver works.
You can try just making a simple binary sensor that just outputs the word {{ 'unknown' }} and see what it resolves to.
if you want tri-logic, then set your unknown case to output none or make an availablity template for that case. It will show up as unavailable with an unknown icon.
Binary_snesors can only be unknown at startup with trigger based binary_sensors and IIRC that now restores states so you shouldn’t get unknown in 2022.5 anymore.