Can a custom component access the list of areas?

Is there an API to access the list of Areas? I don’t see them in the list of states or configuration.

This is too vague a question… but here is an example to extract area’s having light sensors that are ‘on’

Lights on > show area
{% set ns = namespace(areas=[], lights= expand(
      states.light|selectattr('name','ne','All')) | selectattr("state","eq","on") | list) %}
    
    {% for elm in ns.lights if not area_name(elm.entity_id) in ns.areas%}
       {% set ns.areas = ns.areas + [area_name(elm.entity_id)] %}
    {%- endfor %}
    
    {% for area in ns.areas -%}
    {{ area_id(area) }},
    
    {%- endfor %}

No, the question is precise, but you’re misunderstanding.

I’d like to know whether a custom component/integration, i.e. Python code, not a template, can access the list of Areas, e.g. Bedroom, Office, etc., not a list of states.

For example, to access a list of Person entities I can use the HomeAssistant object to call:

hass.async_entity_ids('person')

But Areas don’t have entities or states associated with them, so I’m trying to find a similar API, e.g.

hass.async_area_names()  # ['Bedroom', 'Office']

It turns out this isn’t exposed directly on the HomeAssistant object, but rather via an AreaRegistry helper:

from homeassistant.helpers.area_registry import AreaRegistry

area_registry = AreaRegistry(hass)
await area_registry.async_load()
areas = area_registry.async_list_areas()
area_names = [area.name for area in areas]
1 Like