Allow for multiple labels/areas in label_entities/area_entities

Currently, if you want to list all entities in a given area or all entities having a given label, you do this:

{{ area_entities('kitchen') }}

{{ label_entities('kitchen') }}

If you want all entities in multiple given areas you can do this:

{{ ['kitchen', 'bedroom', 'bathroom']
   | map('area_entities')
   | sum(start=[]) }}

(Practical example shown here).

Similarly, to get all entities having multiple given labels, you would do this:

{{ ['outdoor', 'battery', 'temperature']
   | map('label_entities')
   | sum(start=[]) }}

This Feature Request proposes simplifying the process by enhancing area_entities and label_entities so they support multiple entities as arguments.

{{ area_entities('kitchen', 'bedroom', 'bathroom') }}

{{ label_entities('outdoor', 'battery', 'temperature') }}

In effect, this FR asks to have them behave like expand which, when used as a function, can accept a comma-separated string or a list:

{{ ['group.doors_exterior', 'group.doors_interior'] | expand | list }}
{{ expand(['group.doors_exterior', 'group.doors_interior']) | list }}
{{ expand('group.doors_exterior', 'group.doors_interior') | list }}

2 posts were split to a new topic: Enhanced way to pass arguments

You can also use a + operator:

{{ area_entities('kitchen') 
  + area_entities('bedroom') 
  + area_entities('bathroom') }}

Or several other inelegant ways which is why this FR was created

1 Like

especially useful for iterating over combined sets of label_entities, an aspect not yet mentioned.
eg

{%- for s in ['binnen_lamp','buiten_lamp']
   | map('label_entities')
   | sum(start=[])
    |select('is_state','on') %}
{%- if states[s].last_changed.day == now().day %}
{%- set stamp ='%H:%M' %}
{%- else %} {% set stamp = '%d/%m - %H:%M' %}
{%- endif %}
{%- if loop.first %} {% else %}, {% endif -%}
{{states[s].entity_id}} ({{as_local(states[s].last_changed).strftime(stamp)}})
{%- endfor %}

it does work like this, but a

{{ label_entities('binnen_lamp','buiten_lamp') }}

would be so much cleaner.

adding my support here since the linked/split topic seems to be focussing on introducing new functions, while this is an enhancement of the current.

Also because the suggested

label_entities('bedroom') + label_entities('kitchen')

is no solution for the use case I showed above, cant be done like that

thx for opening it