List all configured areas

I currently list turned on lights and switches using a marked down card, but I want to make it more readable by grouping them based on their area, but I cannot figure out how to list all configured areas. Does anyone has an idea how to do so?

The next (easy) step is to combine the output with this solution:

Unless there is a better (less “cpu intrusive”) way to achieve the goal of course.

Check “auto-entities
This:

card:
  show_header_toggle: false
  title: Lights and Switches on
  type: entities
filter:
  exclude:
    - state: 'off'
    - state: unavailable
    - domain: climate
    - domain: binary_sensor
    - domain: sensor
    - name: /[UR] Remote/
    - domain: media_player
    - name: /[B]/
  include:
    - area: Dining
    - area: Living Room
    - area: Pantry
    - area: Shower
    - area: Kitchen
show_empty: false
type: custom:auto-entities

gives me this, when light/switches (or whatever is included) is on:
image

Thanks @Joerg, but it’s not what I am looking for.
I have a satisfying solution, but just want to structure it in “area sections”, so I am wondering if there is a template “command” to list all areas, so I don’t have to create a manual lists.

1 Like

Solved it like this for now, but hope for a better solution:

# Fill namespace with areas and turned on lights and swiches that toggle a "dumb bulb"
{% set ns = namespace(areas=[], lights= expand(
  states.light|selectattr('name','ne','All'),
  states.switch|rejectattr('entity_id','match','switch.sonos')
  ) | selectattr("state","eq","on") | list) %}

{% for elm in ns.lights if not area_id(elm.entity_id) in ns.areas%}
   {% set ns.areas = ns.areas + [area_id(elm.entity_id)] %}
{%- endfor %}

{% for area in ns.areas -%}
**{{ area_name(area) }}**
{% for elm in area_entities(area) if elm in ns.lights|map(attribute="entity_id") -%}
&nbsp; - {{ state_attr(elm, "friendly_name") }}<br />
{%- endfor %}<br />

{%- endfor %}

Edit: Created a working example that can be pasted into a markdown card

Pardon me for reviving, but I think I have a easier solution.
This works for me to get all areas that have something in it (empty areas are not listed)

{% set areas = states
  | selectattr('attributes.device_class', 'defined') 
  | map(attribute='entity_id')
  | map('area_id') | unique | reject('none') | list %}
{{ areas }}
2 Likes

No worries and it’s a nice peace of code that does suit the topic. The code in my post of Dec 29th '21 does however more than just listing the areas. It lists all (wanted) entities per area.

Hi, i am trying to get your code to work in a auto entities card.
Like having a vertical stack (where the title is the area name) which is hidden when no lights in that area are turned on.
Also in every vertical stack should be every light (light entity card) which is turned on and assigned to the area.

Have you ever tried something like that?