Accessing a floor's level in a template

With the 2024.04 release, we got floors as an added feature. The floor has a level attribute, but it doesn’t seem like there’s a way to access that in templates.

Before this, I had some configuration defining floors and their level/area_ids, so this new feature is close to replacing all of that. The only thing I need access to is the level in templates.

Is there any way to do this or should I open a feature request?

Have you tried to go for the “Floor ID” ?
I have the Impression that the “Level” is just a sort-order “attribute” , if one can call it an attribute

Yup, that just returned the identifier, i.e. main for the floor named Main.

And yes, the docs did seem to indicate that it was for sorting and it appears to sort the floors in the UI. Even getting them back sorted from floors would suffice for my purposes. Unfortunately, they appear to come back in a different order. (It’s perhaps creation order which I could probably hack to make work for my purposes, but that may not be stable long term and I’d prefer not to rely on it.)

I think my main use case for this at the moment is to turn all the lights off on the floors above (or below) the switch that activates an automation.

Ok, Well im sure above make sense to you, but im not inside your head :wink: , a visual example of your “attempts” might share a light on “things”

PS: Just for the record, Floors don’t contain “Entities”, They contains “Areas” ( Areas w/ Devices- Entities )

{{ floor_areas('Basement') 
   | map('area_devices') | sum(start=[]) 
   | map('device_entities') | sum(start=[]) 
   | unique | sort }}

Yeah, from areas, I can get the entities.

I’m on my phone right now, so this is from memory on syntax, but I want to do something like this:

service: light.turn_off
target:
  entity_id: >
    {{ floors_as_objects_with_levels
      |selectattr('level', 'gt', 1)
      |map(attribute='area_ids')
      |sum(start=[])
      |area_entities
      |sum(start=[])
      |list }}

Where the 1 would actually be a variable. That’s the idea, but without the level attribute, I have to hard code things and probably duplicate values (which will eventually down the line lead me to making a mistake most likely).

OK, Good luck with your FR :wink:

That is if you can’t use the Floor_ID, and are concerned whether you might “mixed up” your “areas” , “labels” or “Entities”, or Group of same, or i.e domain.light !

I don’t know where you got the idea that Floors, or Areas for that matter, has attributes ?

Whats the difference between a Floor_ID and a Floor_ID_Level_Attributes , in the end ain’t it just an Unique Identifier for the same “object” ?

Ok, thou i doubt an FR can help you on that part

Ofcause i don’t know how many Floors(or Levels, if you only use it as physical objects) you have, but people use i.e the (UI) level-sort-order in variation ways.
You Accessing a Floor by it’s unique_id ( Floor_ID )

{{floors()}}

{{ floor_areas('1st_floor') 
  | map('area_devices') | sum(start=[]) 
  | map('device_entities') | sum(start=[])
  | select('match', 'light') | list }}

{{ floor_id('light.your_light') }}
{{ floor_id('light.your_light_group') }}

PS: The syntax
Templating - Home Assistant.

Or you could use a “for - loop” ( for lights in light, select floor_id ) Where ID = Variable(somewhere from)
Or simple name your Floor Level_1, Level_2 etc, Thou Any Name would be the Unique_ID anyways
Or You could also just make a light-group for each floors, if that is your “Major” purpose