Help needed creating Binary Template Sensor

Hi guys,
I’m trying to create Template Sensors that represent my Window states in the UI, hass --script check_config gives an error I cannot decode. Can you help?

Snippet from “customize.yaml”

binary_sensor:
  - platform: template
    sensors:
      terrassenfenster:
        friendly_name: "Terrassenfenster"
        value_template: >-
          {% if is_state('binary_sensor.livingroom_door_opening_sensor_1', 'on') %}
            offen
          {% else %}
            geschlossen
          {% endif %}

Error Meesage:

homeassistant:
- extra keys not allowed @ data[‘customize’][‘binary_sensor’]
- customize: [source /home/homeassistant/.homeassistant/configuration.yaml:13]
binary_sensor: [source /home/homeassistant/.homeassistant/customize.yaml:1]
- platform: template

Thanks

I found the customization option in the UI and changed the “Device Class”. That suits my needs as well. Nevertheless, I would be interested in what I did wrong in the approach above!

Thanks!

So the problem with your binary sensor is that you aren’t returning True/False, On/Off, ''/'xxx', or 0/1.

It would have worked if you put your sensor in template sensor, not template binary_sensor. Binary sensor expects A boolean response. If your response is a string, and the string isn’t empty, it considers it ‘on’.

Acceptable boonlean responses:

True or False (No quotes)
On / Off (Not 100% on this one, but I think it works in home assistant land)
0 / 1
'' (empty string) / 'ldkjlskajf' (populated string)

EDIT:

And just to clarify, your template sensor is returning 2 populated strings, meaning always on.

That’s a full sensor definition, not a customize.

customize:
  binary_sensor.livingroom_door_opening_sensor_1:
    device_class: window

That’s all you need

Thanks petro and Tinkerer.