button-card
button-card copied to clipboard
template support for area_name, area_id
HASS release 2021.9.0 introduced new area-based template functions. These are area_name()
and area_id()
. Please see the docs.
An implementation of this in button-card's javascript templating would be great. Another option would be to expose it as a property on the entity
variable.
I am unsure how to implement this in JS.... I've tried adding a Jinja2-style template, but that displays as plain text (as expected).
Last time I checked, the area of an entity was not available in the frontend (unless using specific api calls which I don't want to do).
I'll check again if this has changed and if home assistant exposes that information directly now.
Last time I checked, the area of an entity was not available in the frontend (unless using specific api calls which I don't want to do).
I'll check again if this has changed and if home assistant exposes that information directly now.
I believe this has recently changed; this is based on the fact I can use area_name(entity_id)
in fields which support Jinja2 templates, and the information updates on the frontend immediately.
My use-case: I have a template for Zigbee sensors, and it would be great if the template could auto-populate the sensor's area (i.e. it's location in the house).
button_card_templates:
sensor:
show_name: true
# This will not work
name: "{{ area_name(entity.id) }}"
show_last_changed: true
tap_action:
action: more-info
hold_action:
action: none
state:
- value: 'on'
id: state_on
color: var(--paper-item-icon-active-color)
- operator: default
color: var(--paper-item-icon-color)
styles:
label:
- font-size: 80%
- color: var(--disabled-text-color)
I can't think of a more efficient way of doing this via the template. Thanks!
I believe this has recently changed; this is based on the fact I can use
area_name(entity_id)
in fields which support Jinja2 templates, and the information updates on the frontend immediately.
Jinja2 is rendered on the backend (ie by home assistant, not by the browser) and the backend has access to that information.
Any update on that or maybe a workaround?