Exclude in a template?

Hi all, i just want to know if its possible to exclude entitys in a template? I have got this and it shows me all my on lights and total lights. But I know it also counts all the groups from Philips hue Hub as lights. Just learning about template!

{{ states.light | selectattr( ‘state’, ‘eq’, ‘on’) | list | length }} of {{ states.light | count }}

best regards
Thekholm

| rejectattr('entity_id', 'in', filter)

Working out how to differentiate the entities you dont want and storing them in the variable filter is the tricky part.

See petro’s post here:

1 Like

Only Hue groups (room or zone) have an attribute called is_hue_group and its value is true.

{{ states.light | selectattr('state', 'eq', 'on')
  | rejectattr('attributes.is_hue_group', 'true')
  | map(attribute='entity_id')
  | list | count }}

They also have an attribute called hue_type, whose value is either room or zone, so another way would be like this:

{{ states.light | selectattr('state', 'eq', 'on')
  | rejectattr('attributes.hue_type', 'in', ['room', 'zone'])
  | map(attribute='entity_id')
  | list | count }}

This version gives you more flexibility if you have an application where you need to selectively reject lights that are either in a room or a zone. However, for your current needs (reject rooms and zones) the first example will do the trick.

1 Like

Thanks for your reply,

I found another thing I where looking for in that tread. Thanks :slightly_smiling_face:

Best regards
Thekholm

Wow!

Many thanks :slightly_smiling_face: That worked perfectly, but how to do the same with total light?

Best regards
Thekholm

If you mean that you want to count all lights, regardless of their current state, simply remove the selectattr filter.

Hi again,

I mean without the Philips Hue Hub (light groups), so I can get the right amount of total lights.

{{ states.light | selectattr(‘state’, ‘eq’, ‘on’)
| rejectattr(‘attributes.is_hue_group’, ‘true’)
| map(attribute=‘entity_id’)
| list | count }} Light is turned on of {{ states.light | count }}

Thanks

/Thekholm

That’s what this line in the template does. It rejects any entity that has a is_hue_group: true in its attributes. Only Philips Hue groups have this attribute.

  | rejectattr('attributes.is_hue_group', 'true')

Well i did understand that :slight_smile:

So I got the the right amount of light showing now (the on lights)! I also want the total amount of lights in my home show. Like this 24 of 82 lights are on.

I have all that showing but I know that of my 82 lights in total 15 are hue groups, them I want to get rid of.

Did I express myself better this time? Sorry for my English.

Thanks again for the help!

/Thekholm

Remove this:

| selectattr(‘state’, ‘eq’, ‘on’)

To get he number of off and on lights that are not Philips Hue.

Many Thanks!

Have a god day :slight_smile:

Best regards
Thekholm