How to show area of an entity instead of name?

Hello everyone,

I would like to show the area of an entity instead of the entity’s name in a card (any card) but cannot figure out how to do it.
Is there a card that supports this and if so, how can I achieve it?

Thank you for your help :slight_smile:
Alex

templates are the only option.

{{ area_id('sensor.xyz') }}

1 Like

But in which card and then which field?

I am play with this same thing now, you should use the ‘template’ card.

1 Like

You mean custom:config-template-card and then as card type entities?

Sorry, I just realized I did this using Mushroom cards, it provides a template card and I added the code in the field named “primary”.

Tried it with template-entity-row but name says “dining_room” instead of “Dining Room” as visible in the UI.

type: entities
title: Default
entities:
  - type: custom:template-entity-row
    name: "{{ area_id('sensor.eq3_battery_dining_room') }}"

Then use area_name instead of area_id

1 Like

Thank you!
Is there a list somewhere with all the possible variables like area_id and area_name? Or is it just trial and error?

Also, I wanted to use it with auto-entities and I know that normally you would define options and then entity_id: this.entity_id
But this does not really apply here.
Might you know if it can be used with your template also?

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.eq3*
card:
  type: entities
  entities:
    - type: custom:template-entity-row
      name: '{{ area_name(''this.entity_id'') }}'

(<-- not working yet)

also tried

and

type: custom:auto-entities
filter:
include:
- entity_id: sensor.eq3*
options:
name: ‘{{ area_name(’‘this.entity_id’’) }}’
card:
type: entities
entities:
- type: custom:template-entity-row

Yes, in the templating documentation.

remove the quotes around this.entity_id

Solution found with help of @petro and @thomasloven. Thank you both!

Both name and type are options.

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.eq3_batt*
      options:
        type: custom:template-entity-row
        name: '{{ area_name(''this.entity_id'') }}'
card:
  type: entities
1 Like

if you insist on using the single line notation, you could make life easier on yourself by using the ‘correct’ quotes:

              type: custom:template-entity-row
              name: "{{ area_name('this.entity_id') }}"

multiline solves quoting issues for you:

              type: custom:template-entity-row
              name: >
                {{ area_name('this.entity_id') }}

also, for reference, as discussed in Discord:

this.entity_id works because of auto-entities. config.entity works because of template-entity-row

hence my preferred method using:

              name: >
                {{ area_name(config.entity) }}
1 Like

Is there a way to also achieve the same effect with an auto entities card type glance?
For some reason it doesn’t seem to resolve the area_name even though referencing this.entity_id works

This is the card I’m trying to add.

type: custom:auto-entities
card:
  type: glance
filter:
  include:
    - entity_id: '*sensor.*battery_level*'
      state: <50
      options:
        type: custom:template-entity-row
        name: |
          {{ area_name('this.entity_id') }}
  exclude:
    - entity_id: '*sensor.*low_battery*'
sort:
  method: state
  numeric: true
show_empty: true

The names of the entities however all end up literally showing the code for area_name and the sensor entity id like this including all brackets (example for sensor.motionsensor_livingroom_battery_level):

{{ area_name('sensor.motionsensor_livingroom_battery_level') }}

Any solution to get this working?

this.entity_id is not a name, do not put it in quotes.
And template-entity-row cannot be used in Glance.
And this.entity_id cannot be used in templates.