WTH, where are the floor_entities()

saw this WTH are floors and areas useless - #5 by Mariusthvdb in another WTH, and made me look for floor_entities().

but, they’re still not there… seem to remember core dev talk about adding that essential functionality to the template engine, must have gotten lower on the priority list.

Please up that, it would truly be very welcome.

I am aware we can do hacky things like

{{['dorm','aanbouw','woongedeelte']|map('floor_areas')|sum(start=[])
            |map('area_entities')|sum(start=[])
            |select('in',label_entities('binnenlamp'))
            |select('is_state','on')|list|sort}}

to list the entities in all areas that make up that floor…but how much better would it be to do


{{ floor_entities('begane_grond')
            |select('in',label_entities('binnenlamp'))
            |select('is_state','on')|list|sort}}
1 Like

great!
looking forward to that, thanks!

Hi both, thanks for your efforts to realise the above! I see it has been merged, so waiting for it to be part of a next release :slight_smile:

As you are more experienced in templating than I am, I have a question:

Do you see any opportunity to improve the following template? I have a group of lights and I want to count all the lights of that group that are on, on a specific floor.

{{ floor_areas('ground_floor') | map('area_entities') | sum(start=[])   | select('in',expand(states.light.all_lights) | selectattr('state','eq','on') | map(attribute='entity_id') | list ) | list | count }}
with in the future:
{{ floor_entities('ground_floor') | select('in',expand(states.light.all_lights) | selectattr('state','eq','on') | map(attribute='entity_id') | list ) | list | count }}

yeah, see the example in my post above, use labels.

You now are using the states which is always a thing to prevent if possible. If you’d add labels to those lights, you can do away with the light group altogether (which is also 1 less group to maintain)

Thanks. I’ve been looking into using labels instead of groups like you mentioned. What would you say is a good equivalent of the following?

{{ expand( states.light.all_lights) |selectattr('state','eq','on')|list|count }}

The label_entities() function returns the entity_id’s as strings, which will make it more complex to check whether they are turned on?
Only thing I can come up with:

{{ expand( states.light) |selectattr('state','eq','on') | map(attribute='entity_id') | select('in',label_entities('lights'))| list|count }}

dont know how to say, Ive pointed you to that template several times now… it just does what you want, and until you set those labels, you can not test, so no point re-iterating the same question.

Besides, this is no longer about the WTH request, but more about template support, so I’d suggest to take it to the appropriate thread in this community. or simply search for the answer, because it has been posted many times.