What are the difference between light- and switch groups?

Hi,
I can’t understand the difference between light and switch groups.
I have created to groups ‘light.kitchen_lights’ and ‘switch.kitchen_swithces’.

If I then try:
{{ expand(state_attr('light.kitchen_lights', 'entity_id')) }}
and
{{ expand(state_attr('switch.kitchen_swithces', 'entity_id')) }}

Then the fist group expands fine like this:

[<template TemplateState(<state light.kitchen_inner_spots=off; supported_color_modes=[<ColorMode.BRIGHTNESS: 'brightness'>], off_with_transition=False, off_brightness=29, friendly_name=KITCHEN-Inner Spots, supported_features=LightEntityFeature.TRANSITION|FLASH @ 2023-02-01T12:10:49.713830+01:00>)>, <template TemplateState(<state light.kitchen_outer_spots=off; supported_color_modes=[<ColorMode.BRIGHTNESS: 'brightness'>], off_with_transition=False, off_brightness=0, friendly_name=KITCHEN-Outer Spots, supported_features=LightEntityFeature.TRANSITION|FLASH @ 2023-02-01T11:43:46.689054+01:00>)>]

but the switch group expands to:
[]

What I really like is to get the number of switches that are on in the group. I works perfect in the light group using this template:

{{ expand(state_attr('light.kitchen_lights', 'entity_id') )
        | selectattr('state', 'eq', 'on') 
        | list 
        | count
      }}

Any ideas?

Isn’t this a typo on “swithces”?

{{ expand(state_attr('switch.kitchen_switches', 'entity_id')) }}

Also, I believe this will work:

{{ expand('switch.kitchen_switches') }}

So, you can simplify a bit more like like this as you don’t have to cover into a list to be able to count:

{{ expand('light.kitchen_lights')
        | selectattr('state', 'eq', 'on') 
        | count
      }}
{{ expand('switch.kitchen_switches')
        | selectattr('state', 'eq', 'on') 
        | count
      }}
1 Like

Perfect! Thanks.
It looks like I still need the list, else it returns:
TypeError: object of type 'generator' has no len()

1 Like