Help creating a template sensor

Hi,

I’m trying to create a boolean-type template sensor. I tested the template in developer’s tools and it seems to be working, when I added the code to the configuration.yaml file, I get validation errors. Here is what I added:

template:
    - sensor:
            - name: "Anyone_home"
            - unique_id: template.anyone_home
            - state: <
{{ if 
states('device_tracker.moto_z4') == 'home' or
states('device_tracker.lm_g710vm') == 'home' or 
states('device_tracker.sm_g781v') == 'home' }} 
true 
{{ else }} 
false 
{{ endif }}

And here is the error messages I receive:

Error loading /config/configuration.yaml: while scanning a simple key
in “/config/configuration.yaml”, line 109, column 1
could not find expected ‘:’
in “/config/configuration.yaml”, line 112, column 45

Line 109 is the beginning of the actual template.

Any help would be appreciated.

Mike.

template:
  - binary_sensor:
      - name: "Anyone_home"
        unique_id: template.anyone_home
        state: >
          {{ states('device_tracker.moto_z4') == 'home' or
            states('device_tracker.lm_g710vm') == 'home' or 
            states('device_tracker.sm_g781v') == 'home' }} 

EDIT

If you’re interested, here’s another way to compose the template:

template:
  - binary_sensor:
      - name: "Anyone_home"
        unique_id: template.anyone_home
        state: >
          {{ 'on' in ['device_tracker.moto_z4', 'device_tracker.lm_g710vm', 'device_tracker.sm_g781v'] | map('states') }}