Error message when creating light counter

I’m really new to home assistant and I’m trying to use templates to create a counter to display how many lights are currently turned on. Here is what I’ve tried:

platform: template
  sensors:
  current_lights_on:
  friendly_name: Current lights on
  unit_of_measurement: 'on'
  value_template: >
  {% set lights = [ states.light.lamp, states.light.light_strip,
  states.light.patio, ] %}  {{ lights | selectattr('state','eq','on') | list |
  count }}

It keeps returning the error message “Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/configuration.yaml”, line 20, column 10”

Any help would be greatly appreciated. Thankyou so much!

- platform: template
  sensors:
    current_lights_on:
      friendly_name: Current lights on
      unit_of_measurement: 'on'
      value_template: >
        {% set lights = [ states.light.lamp, states.light.light_strip, states.light.patio, ] %} 
        {{ lights | selectattr('state','eq','on') | list | count }}

There’s an example here https://www.home-assistant.io/integrations/template/#legacy-sensor-configuration-format

Note however that you should not be using the legacy format for new sensors. Use the new format.

configuration.yaml

template:
  - sensor:
      - name: Current lights on
        unit_of_measurement: 'on'
        state: >
          {% set lights = [ states.light.lamp, states.light.light_strip, states.light.patio, ] %} 
          {{ lights | selectattr('state','eq','on') | list | count }}

Hey man, thanks so much for the reply!

I tried the new format code you sent through and got the following error message: Error loading /config/configuration.yaml: while scanning a simple key in “/config/configuration.yaml”, line 19, column 1 could not find expected ‘:’ in “/config/configuration.yaml”, line 20, column 11

Not sure what I’m doing wrong?

Typo. Sorry. This

Should be

template:

That works now! Thanks again mate.