Can I set a binary Sensor as "unkown" with a value_template?

When I do this:

{% if state_attr('binary_sensor.elias_zimmer_occupied_bayes', 'probability')|float > 0.9 %}
          on
{% elif state_attr('binary_sensor.elias_zimmer_occupied_bayes', 'probability')|float < 0.1 %}
          off
{% else %}
          unknown
{% endif %}

the Sensor says: “off” when the neither conditions are met. Is there a way to change this?

Not unknown but you can set it to unavailable using availability:

availability: >-
  {% set probability = state_attr('binary_sensor.elias_zimmer_occupied_bayes', 'probability')|float(0.5) %}
  {{ probability < 0.1 or probability > 0.9 }}
state: >-
  {{ state_attr('binary_sensor.elias_zimmer_occupied_bayes', 'probability')|float > 0.9 }}

if probability > 0.9 → on
if probability < 0.1 → off
anything else → unavailable

Thx, and for the cleanup too!
Didn’t see that in the docs. In my situation it was availability_template because i’m using the template inside a sensor.

Well they actually changed that. It’s availability in sensors too unless you’re using the legacy format. But same idea either way, glad it works for you :+1: