How to properly create binary sensors from included file?

I am trying to create a binary sensor from a guide on this page:

Virtual Energy Meters with PowerCalc | Sean Blanchfield

This is the code I am trying to get in to my HA:

template:
  binary_sensor:
  - name: fridge_always_on
    state: on

This works when I put it in configuration.yaml file. But to keep my file clean I tried doing this:

binary_sensor: !include binary_sensors.yaml

Then in file “binary_sensors.yaml” I tried adding this:

template:
  binary_sensor:
  - name: fridge_always_on
    state: on

But it gives me an error. I am lost and need help :slight_smile:

It’s a template sensor - so you need to be doing:

template: !include template_sensors.yaml

And then in the template_sensors.yaml file:

  binary_sensor:
  - name: fridge_always_on
    state: on
1 Like