So why is the template stuck at “unknown” when it is most certainly a defined “false”? I don’t understand how a valid input can result in unknown output?
But shouldn’t they eventually…go to something other than “unknown” eventually? Its been half an hour with changing inputs and STILL unknown? All evaluate to known trues or falses?
I have a theory why this happening. As an experiment, remove the delay_on and delay_off options then restart Home Assistant. Let us know if the Template Sensor still reports unknown.
Instantly resolves to “off” after removing the delay off/on and reloading.
70.1 - 68.1 | abs > 2
2.0 > 2
False
off
So did something about the update break delay_on and delay_off? That would be most unfortunate given how heavily I use those in templates to get more refined behaviors (and nearly all of my similar binary_sensor templates are “unknown” post update regardless of input source)
The temp sensors update every ~15 seconds so I don’t see how that could cause 30+ minutes of being stuck.
I have also tried some stuff and it looks like if I remove delay_on it instantly populates with on or off as soon as the first temp update hits (even if its “off” and I have a delay_off configured)
Ok, it just got more strange…after putting back the code the way I had it with delay on/off (so I don’t forget, I’m calling it a night) and reloading just templates (not all of home-assistant) most of them started working as expected suddenly?
Now I almost wonder if there’s something still churning post-update in the background messing with the results…maybe I should revisit this after its sat overnight or something.
My guess is that the influence of the two options wasn’t anticipated when the decision was made to implement the unknown state for Template Binary Sensors. Alternatively, it was a known factor but considered to be acceptable (i.e. the state value is truly unknown until the template is fully evaluated).
My $0.02 is on the first proposition.
The current code do an update whatever the delay if the state is None. It should very likely be replaced or augmented by “unknown”.
A restart causes the state to change from unknown to on or off when the template evaluates. Then the delay_on/off has to expire before the state is updated.
Well yeah, technically it works, but conceptually, it doesn’t really make sense to delay if the “from” state is unknown (or unavailable for that matter). You likely want an actual state asap.
It might make sense if the “to” is, though, but then again…
Probably worth opening an issue to clarify if it’s an omission or “works as designed”.
I had the same issue and solved it by adding a template for the delay value.
I’m checking the input state of the used entity. When the state value is ‘None’ there’s no delay, otherwise the delay_off in my case is 15 seconds,
delay_off: >
{{ 0 if is_state('binary_sensor.xyz','None') else 15 }}
On restart and startup the sensor is showing directly the correct value (False or True)
@Mariusthvdb has an issue open for this. We were talking about it on the beta discord.
Not really a big deal for the templates that only have delays of a few seconds or minutes but I have a couple that are 4 hours and it really buggers things up for me. It is an issue when reloading templates (which I do A LOT sometimes) as well as restarts. I’ve been having to manually change their state to the correct value after reloading.