Binary Sensor Migration Error

I am following the Legacy binary_sensor template deprecation warning instructions to migrate all of my binary_sensor templates to templates.yaml from binary_sensors.yaml.

I have moved the following from binary_sensors.yaml

  - platform: template
    sensors:
      living_room_tv:
        friendly_name: 'Living Room TV'
        value_template: >-
         {%- if is_state("binary_sensor.livingroomtvping", "on") %}
         On
         {% else %}
         Off
         {%- endif %} 
        icon_template: mdi:television

and placed this in templates.yaml as instructed:

template:
- binary_sensor:
  - default_entity_id: binary_sensor.living_room_tv
    icon: mdi:television
    name: Living Room TV
    state: '{%- if is_state("binary_sensor.livingroomtvping", "on") %} On {% else %}
      Off {%- endif %}'

When I do this, the binary_sensor template error goes away, but the following error appears instead:

Invalid config for ‘template’ at templates.yaml, line 121: Entity ID ‘binary_sensor.living_room_tv’ does not belong to domain ‘sensor’ for dictionary value ‘sensor->19->default_entity_id’, got ‘binary_sensor.living_room_tv’

Can someone please explain what this means?

How did you set up the include for templates.yaml?

Also, you do realize that those are two different sensors, right?

1 Like

Yes, I copied the wrong code here. The code I’ve updated above now reflects the actual code copied in to those locations.

The include for templates & binary_sensors is:

binary_sensor: !include binary_sensors.yaml
template: !include templates.yaml

OK, your link clued me in to the answer. I had not included a binary_sensor declaration before I listed the binary sensors in templates.yaml.

Thanks for taking the time to reply. Much appreciated.