Light group sensor template config issue

I’m making a sensor to detect/inform me how many lights are on in a given light group. I’ve developed the following template sensor that works in the developer tools template engine, however when I go to add it to my config file using the following yaml it returns the error ‘missed comma between flow collection entries’

Is anyone able to help me out? I’m entering the following as the template in my config:

 template:
  - sensor:
    - name: Downstairs_Lights_On
      state: {{ expand('light.downstairs_lights') | selectattr('state', 'eq', 'on') | list | count }}

As I said it works fine in the template engine in dev tools but won’t play ball in the config folder!

Single line templates must be enclosed in quotes.

state: "{{ expand('light.downstairs_lights') | selectattr('state', 'eq', 'on') | list | count }}"

You sir are a scholar and a gentleman, thank you. Still relatively new playing with the yaml side of HA, it’s a love/hate relationship but learning a tonne, thanks for helping me on the journey.

1 Like