Lovelace and area_id

Does anyone know if there’s a way to use area_id() and area_entities() in lovelace? Tried using “Lovelace Card Templater” and “Config Template Card” without any success.

Need to get the image and entities from an area using just the area name.

Thankful for any help!

Yep template example here: (all lights ‘on’ in Area ID XXX)

The question isn’t can it be used in lovelace. Templates are used all over the place but… Some cards dont support templates. (And why I’ve almost completely shifted to using the mushroom template card or custom button card for most things…

What’s your use case?

To start with area_id(), display an area with the card type: area
The reason for not using the area card is that in this case I only have the Name of the area, not the area ID

Area entities will be used to display other cards if, lets say there is any media_players in the area.
But I just realized it won’t work anyway, cause I would need this in conjunction with lovelace_gen, to be able to send the information to an included file

- !include 
  - ../views/page.yaml
  - contains_media_players: false
    contains_lights: true

In the end to show a tab using Tabbed Card since it will show empty tabs, with lovelace_gen I would be able to compleatly remove the tab

Have you considered using "custom:auto-entities" card?
The simplest example with entities in Entities card:

  - type: custom:auto-entities
    show_empty: false
    card:
      type: entities
    filter:
      template: >-
        {{ 
          states.device_tracker 
          | selectattr('entity_id','in',area_entities('kitchen'))
          | map(attribute='entity_id')
          | list
        }}

изображение
Here the code gives a list of entities which is fed to the Entities card (as a simple list, i.e. w/o additional options like "secondary_info"). But the card may also create a list of dicts (i.e. with all needed options).
The card may also create a stack (or a grid) of cards for these entities.

1 Like

Never used the Area card - but I believed that it uses “area_id” as an input parameter:

type: area
area: kitchen   ### this is area_id

And you cannot use this “area_id”, you need to use an area’s name, right?
Here the "custom:auto-entities" card is used to show ONE card (do not bother about "vertical-stack") with templated value of some option:

type: custom:auto-entities
card_param: cards
card:
  type: vertical-stack
filter:
  template: >-
    {% set AREA_ID = area_id('Кухня') -%}
    {{
      [
        {
          'type':'area',
          'area':AREA_ID
        }
      ]
    }}

i.e. you know an area’s name (“Кухня”) and may use jinjia to get an "area_id" for this name.

1 Like