Binary Template Sensor Error After Updating

Hi everybody… my first post, so please let me know if I’ve made any mistakes.

I spent some time away from actively working on my Home Assistant setup… and getting back into it, I upgrade from v37 to current. I was surprised that most everything seemed to work without needing a tweak. The only thing that stopped working was two template binary sensors. I’m confident the problem is in my yaml indentation/format which is something I’ve never totally wrapped my head around. In the past, I would always just basically try different formats (with a dash, without a dash being the best examples) until it worked. But this time, I can’t seem to get the sensors to work using the format from the examples here:

https://home-assistant.io/components/binary_sensor.template/

Can anybody point me to something to help clarify the preferred yaml indentation / format and help me understand it once and for all?

Can you post the binary sensor config from your .yaml file using the code tags above ‘</>’ please

Hopefully I’m using the code tags appropriately… it seems to just indent the text I have highlighted. But anyways, the binary sensors are at the bottom. Like I said, they had been working in v37. The front end shows this:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: REDACTED
  longitude: REDACTED
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 143
  # metric for Metric, imperial for Imperial
  unit_system: imperial
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: America/Los_Angeles

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

http:
  # Uncomment this to add a password (recommended!)
    api_password: REDACTED

# Checks for available updates
updater:

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
# conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:

#media_player:
#  - platform: plex

mqtt:
  broker: REDACTED

#text to speech
tts:
  - platform: google

notify:
  name: pusher
  platform: pushbullet
  api_key: REDACTED

#mysensors:
#  gateways:
#    - device: 'REDACTED'

device_sun_light_trigger:
  light_group: group.living_room
  device_group: group.my_devices

influxdb:
  host: 127.0.0.1

light: !include Configs/lights.yaml

switch: !include Configs/switches.yaml

group: !include Configs/groups.yaml

sensor: !include Configs/sensors.yaml

automation: !include_dir_merge_list Configs/automation

script: !include Configs/scripts.yaml

device_tracker:
  - platform: unifi
    host: REDACTED
    username: REDACTED
    password: REDACTED
    track_new_devices: false

binary_sensor 1:
  - platform: template
    sensors:
      porch_movement:
        friendly_name: "Porch Motion"
        value_template: "{{ is_state('switch.porch_motion', 'on') }}"
        sensor_class: motion

binary_sensor 2:
  - platform: template
    sensors:
      driveway_movement:
        friendly_name: "Driveway Motion"
        value_template: "{{ states.switch.driveway_motion.state == 'on' }}"
        sensor_class: motion

Indentation looks fine.
Try changing

{{ states.switch.driveway_motion.state == 'on' }}

to

{{ is_state('switch.driveway_motion', 'on') }}

Failing that, try commenting out one of the sensors at a time to narrow down which one is giving you problems.
Also there is probably more error info in the homeassistant.log file.

As an aside, you can tidy up your code a little by changing some formatting :

binary_sensor:
  - platform: template
    sensors:
      porch_movement:
        friendly_name: "Porch Motion"
        value_template: "{{ is_state('switch.porch_motion', 'on') }}"
        sensor_class: motion

      driveway_movement:
        friendly_name: "Driveway Motion"
        value_template: "{{ is_state('switch.driveway_motion', 'on') }}"
        sensor_class: motion

The easy to access log in the newest version surely helped, as you suggested (I remember logs being a lot harder to use when I was developing last). It mentioned an invalid class for the sensor. It looks like “sensor_class” became “device_class” at some point. Fixing that put me back in business!

Thanks a lot for taking a look, I really appreciate it.