Helper to get the number of rooms where Light is on

Hello,

i managed to get the number of lights into a helper where light is on - this gives me a fairly high number.

{{ states.light | selectattr("state","eq","on") | map(attribute="entity_id") | list | count }}

I would prefer to see the number of rooms where the light is on. Does anyone have an idea how to manage that?

Thanks for the community help!

Tom

Please post code using the </> button, so:

{{ states.light | selectattr("state","eq","on") | map(attribute="entity_id") | list | count }}

as that doesn’t mess up quotes and indentation.

How have you associated lights to rooms? Areas? If so:

{{ set(states.light
       |selectattr("state","eq","on")
       |map(attribute="entity_id")
       |map("area_name")
       |list) }}

Line breaks just for readability; and set is a Python structure like a list but with no duplicates:

Thanks for the quick help - now i am getting the list of the rooms,… i just would need the number :slight_smile: but this was fixed with a | count :slight_smile:

1 Like