Template for identifying all light entity_id's in an area

Hello - All templating gurus. Hopefully this is a simple question that I just don’t get.

I use the below for counting the lights in an area:


          {{ states.light 
            | rejectattr('entity_id', 'search', 'screen')  
            | map(attribute='entity_id') 
            | map('area_name')
            | select('in', [ 'Back Yard','Front Yard'])
            | list 
            | count
          }}

this works great . But I want entity_id of these lights - mapping back to entity_id after the select doesn’t work. How do I do this? This to create a dynamic group of those lights via an automation.

There’s no need for the template to start with all lights (states.light) if you already know that you only want the lights in two specific areas.

{{ ['Back Yard', 'Front Yard']
  | map('area_entities')
  | sum(start=[])
  | select('match', 'light')
  | reject('search', 'screen')
  | list }}
1 Like

Thank You!

what does this line do - | sum(start=[])?

Is it assigning an empty list and sum is to append items to the array/list?

Is there good template tutorial reference that would help beginners like me and also a place to see what all attributes homeassistant entities have?

1 Like

Developer-Tools /States , search, there’s no List, as all installation is individual, as for tutorial, i think i’ve seen a link to one somewhere in a commend.
But it’s jinja, here’s 1 ( maybe i bookmarked it from the url i saw :slight_smile:
https://jinja.palletsprojects.com/en/latest/templates/#

Yeah - familiar with both and have been using it and it is helpful but the jinja docs are not very beginner friendly in my opinion.

If there is a better resource to learn jinja templating than this one then please do share that.

Another question - groups created via the UI - is there anywhere in the config folder I see a yaml version of that? Like automations created via the ui shows up in automations.yaml.

UI made groups and helpers, just anoy me, ones they are made, i have no idea where they are(beside as an entity) So i only have old yaml-groups
Beside, Groups made in helpers, will always show as Off/Away, if 1 member is off/away( Pretty odd )

Agree, I like the functionality of creating them via the UI sometimes. Especially if I am on my phone or tablet and can’t open my IDE. But would love to see the end product in the config somewhere, like automations that is perfect, get the initial code created via UI and then edit if necessary manually via an editor. But I guess that is not possible with UI groups and helpers.

1 Like

helpers defined are in /config/.storage in json format.

although i see the groups entries, i don’t see the enumeration of their entities.

1 Like

i am pretty sure this is just the opposite actually. at least for lights. a group is ‘on’ if one member is on.

i believe that converts

[ [ a ], [ b ], [ c, d, e] ] into [a, b, c, d, e]

wasn’t an obvious thing that it would do… at least i didn’t find it obvous.

You are right, i just checked the DOCs, don’t know why/where i got this from, maybe it was template-helpers i made ( because i needed a mix of lights/switches/sensors ), which then always showed as off. , so i dropped it, as i also couldn’t easily see which was added.
Anyway, maybe eventually one can create mixed-entity groups, And device-trackers groups, in UI
EDIT: was/must have been a template-helper :flushed: , because i “grouped” entities from an integration.
Old Group Style:

I haven’t seen a groups related file there. There is input_boolean, input_select, input_button but nothing for groups.

right, i found the entries in entity_registry but i didn’t find their definitions.