Template binary sensors unavailable?

Hi!
I have used a template binary sensor for precence tracking which has worked just fine for a long time. But suddenly, they just became unavailable. I have tested the template statement in the developer tools, and it works just as it should. But the binary sensors just does not seem to exist any more. It just says “Entity not found”…

binary_sensor:
  - platform: template
    sensors:
      jonas_home_sensor:
        friendly_name: Jonas Hemma
        device_class: occupancy
        value_template: '{{ True if is_state("input_boolean.jonas_hemma", "on") else False }}'

I’m on version 2024.1.5 and it has worked fine on that one up until today…

Any help will be most appreciated!

It’s a legacy template binary sensor but it should still be supported. BTW your template can be simplified to:

binary_sensor:
  - platform: template
    sensors:
      jonas_home_sensor:
        friendly_name: Jonas Hemma
        device_class: occupancy
        value_template: '{{ is_state("input_boolean.jonas_hemma", "on")  }}'

This template will return true or false.

To add it in the new format (in configuration.yaml) it would be:

template
  - binary_sensor:
      - name: Jonas Hemma
        device_class: occupancy
        state: '{{ is_state("input_boolean.jonas_hemma", "on")  }}'

Also if you are only using this for display in a dashboard (so no one can change the state manually) you no longer need a template sensor for this. You can use the simple-entity option in an entities card:

type: entities
entities:
  - type: simple-entity
    entity: input_boolean.dnd

Screenshot 2024-01-29 at 09-01-10 Administration – Home Assistant

It can still be editied from the more info pop up though.

Thanks for the response!

I changed the declaration of the binary sensors to the new format. With just a YAML reload it did not help. After some fiddling, I tried full restart instead and just as suddenly as the binary sensors disappeared, the not reappeared. I’m not sure what was the reason, as I tried restart several times yesterday to no avail.

Whenever you add a new integration you need to restart.

Go to Developer Tools → Templates. What does this return:

{{ states("input_boolean.jonas_hemma")  }}