How to fix Binary Sensor Template Unavailable?

I’m struggling with template sensors.

Setup
I have two binary sensors in a room.
Motion Sensor (binary_sensor.motion_sensor)
Camera Motion Sensor (binary_sensor.camera_motion)

What do I want to achieve?
I want a single binary sensor that checks the value of both of the sensors and works as follows -
Motion Sensor (On) + Camera Motion Sensor (ON) = Room Binary Sensor (On)
Motion Sensor (Off) + Camera Motion Sensor (ON) = Room Binary Sensor (Off)
Motion Sensor (On) + Camera Motion Sensor (Off) = Room Binary Sensor (Off)
Also, if Room Binary Sensor is On or Off, I want to set a delay of 5 mins before it changes it’s value.
The goal is to switch off HVAC, Lights, TV if there’s no motion after 5 mins.

A kind gentleman on Reddit helped me create this template

template:
  - binary_sensor:
      - name: "Room Occupied"
        unique_id: room_occupied
        device_class: presence
        delay_off: '00:05:00'
        state: >-
          {% set motion = is_state('binary_sensor.motion_sensor','on') %}
          {% set cam_mot = is_state('binary_sensor.camera_motion','on') %}
          {{ motion and cam_mot }}

But when I try to display it in UI, it just says Unavailable.

Could someone be kind enough to tell me what exactly am I doing wrong?

Did you reload the template entities configuration?

I think there might be some syntax problems including the need to change “state:” to “value_template:”, try something like this (but please note I have not tested it) …

binary_sensor:
  - platform: template
    sensors:
      room_occupied:
      - friendly_name: "Room Occupied"
        device_class: presence
        delay_off: '00:05:00'
        value_template: >-
          {% set motion = is_state('binary_sensor.motion_sensor','on') %}
          {% set cam_mot = is_state('binary_sensor.camera_motion','on') %}
          {{ motion and cam_mot }}

No, the example is modern design and is working.

OK then, how about pasting the following into Developer Tools - Template to check how it evaluates:

{% set motion = is_state('binary_sensor.motion_sensor','on') %}
{% set cam_mot = is_state('binary_sensor.camera_motion','on') %}
{{ motion and cam_mot }}

You’re posting the legacy template sensor format. OP has the ‘new’ template sensor format. Both work, that shouldn’t be the problem.

@calmbuddha when you display it in the UI, what entity_id are you using? I would expect it to have an entity_id of binary_sensor.room_occupied.

Also, can you take a screenshot of developer tools / states page. Make sure to filter down to binary_sensors.

You are right! I was using the wrong entity ID /facepalm
Everyone, thank you so much for helping out a stranger on the internet.
@Jonah1970 @pedolsky