Unable to include binary sensor template

Hi

I cannot add a binary sensor in the configuration.yaml with the !include option. It seems there were few changes along the way with the correct format. What helped people in the past seems not working today. I followed the documentation but it doesn’t work. The syntax is OK but the entity is not being added. It does work however if I add the template directly in the configuration.yaml

What am I doing wrong?

configuration.yaml:

template: !include template_sensors.yaml

template_sensors.yaml:

binary_sensor:
  - name: "Why it's not working sensor"
    state: >
      {{ is_state('binary_sensor.presence_sensor_dinging_room_presence_sensor_1', 'on') }}
    device_class: "presence"
    icon: >
      {% if is_state('binary_sensor.presence_sensor_dinging_room_presence_sensor_1', 'on') %}
        mdi:motion-sensor
      {% else %}
        mdi:motion-sensor-off
      {% endif %}

Template requires a list.

outside that, why are you even making a template sensor? If you change binary_sensor.presence_sensor_dinging_room_presence_sensor_1 via the UI to show as a presence sensor, you don’t even need a template.

Also, if you REALLY want a template entity, you can create this via the UI and select presence too. Just use {{ is_state('binary_sensor.presence_sensor_dinging_room_presence_sensor_1', 'on') }} as the value that goes in the template.

Lastly lastly, if you really want to use yaml, you’ll want to make sure your naming convention for your includes reflects what’s actually in the file. Template section accepts, sensors, binary_sensors, buttons, selects, and a plethora of other template entities, not just sensors.

template: !include template.yaml

template.yaml

- binary_sensor:
  - name: "Why it's not working sensor"
    state: >
      {{ is_state('binary_sensor.presence_sensor_dinging_room_presence_sensor_1', 'on') }}
    device_class: "presence"
    icon: >
      {% if is_state('binary_sensor.presence_sensor_dinging_room_presence_sensor_1', 'on') %}
        mdi:motion-sensor
      {% else %}
        mdi:motion-sensor-off
      {% endif %}
1 Like

Thanks for the reply!

It does works now. I tried before with the dash (list) as well but… I guess I had something wrong. Works. Thanks.

I am creating a template because I want the name to be different in the glance card.

The name of the sensor is usually “Presence sensor - Office” but because I don’t have much space, in this case I want just the word Office. Not sure if there is a better way to do that.

You can just edit the card in the dashboard and change the name there. It won’t change the name on the entity_id. It’s like a display name. But if you do that, your UI won’t auto generate.

Thanks! I will try