Categories equivalent of label_entities()

I’ve been using categories to categorize my scenes. I’m writing a template to filter some scenes by area and category but I can’t seem to find a way to filter by category. For example, for labels it’s possible to use label_entities() Templating - labels, is there an equivalent for listing entities for a category?

Or the alternative is to rely on labels for this (for the time being)?

Categories is purely a UI thing as I understand it. Not sure why yet another thing was introduced instead of making is easy to group/filter by labels instead.

1 Like

Items can have multiple labels, but only 1 category. Categories don’t span tabs either. They do not have the same functionality.

Thanks, I’ll add labels to my categorized scenes. :yawning_face:

Here’s a working example of the template I’m building:

{% set area = "Sala jantar" %}
{% set label = "luz" %}
{{
  expand(area_entities(area))
    | selectattr('domain', 'eq', 'scene')
    | selectattr('entity_id', 'in', label_entities(label))
    | selectattr('name', 'match', '[0-9] .+')
    | map(attribute='name')
    | list
    | sort
}}

You should avoid expand if you can.

{% set area = "Sala jantar" %}
{% set label = "luz" %}
{{
  area_entities(area)
    | select('in', label_entities(label))
    | select('search', '^scene.')
    | map('state_attr', 'friendly_name')
    | select('match', '[0-9] .+')
    | sort
}}
1 Like

That worked, thanks for the optimization.

@petro , can you expand on why we shouldn’t expand()? It shows up in many examples.

if you can avoid expand you should. This is because expand resolves everything in the list that is supplied to it, where as other methods only resolve the ending result. In layman terms, expand is slower and not optimized.

1 Like

Kinda-sorta related: Is there some way to detect whether an entity is a group without simply expanding it and see what comes out?

Looking at for example a light group in developer tools there is no literal group attribute at least. While it does have an entity_id attribute listing the lights in the group, other entities (scenes for example) may for sure have such an attribute without being a group so that isn’t really foolproof.

Reject entities from the group integration

1 Like