Skip to content
cataseven edited this page Jul 29, 2026 · 1 revision

Templates

🏷️ Template Names

Entity names support HA-style {{ }} templates that resolve dynamically from live entity states:

name: "{{ state_attr('sensor.room', 'friendly_name') }}"
name: "{{ states('sensor.power') }} W"
name: "{{ state_attr('sensor.temperature', 'device_class') | capitalize }}"
name: "Room: {{ state_attr('sensor.room', 'friendly_name') | upper }}"

Supported functions

Function Description
states('entity_id') Current state value
state_attr('entity_id', 'attribute') Entity attribute value
is_state('entity_id', 'value') Returns "true" or "false"

Supported filters

Filters are chained with |, just like Jinja2:

Filter Example Result
capitalize temperature Temperature
upper salon SALON
lower SALON salon
title living room Living Room
trim " text " "text"
int "22.5" "22"
float "22" "22"
round(n) 22.567 | round(1) "22.6"
replace('a','b') replace('_',' ') Replaces all occurrences
default('val') Fallback if empty/unknown
truncate(n) Cuts to n chars +

Multiple filters can be chained: {{ state_attr('sensor.x', 'type') | replace('_', ' ') | title }}

🧩 Template Toggles (Boolean Templates)

Most boolean display toggles accept a Jinja2 {{ }} template string instead of a fixed true / false — the same mechanism color already uses. Templates are evaluated server-side by HA via render_template WebSocket subscriptions, so the toggle flips live the moment its dependencies change — no polling, no reload.

type: custom:statistics-graph-chart-card
show_legend: "{{ states('input_boolean.show_legend') == 'on' }}"
entities:
  - entity: sensor.temperature
    show_state: "{{ states('input_boolean.show_state') == 'on' }}"

Templatable keys

Card level: show_legend, show_grid, show_tooltip, show_tooltip_total, tooltip_stacked_total, show_now_line, show_x_axis, show_y_axis, show_y2_axis, show_x_ticks, show_y_ticks, show_y_axis_label, stacked, period_highlight, logarithmic, state_timeline_show_labels, show_export.

Entity level: show_state, show_in_legend, show_graph, show_line, show_fill, show_points, smooth, gradient, show_data_labels, show_average, show_trend_icon, show_color_dot, show_timestamp, show_range_values, show_extrema_min, show_extrema_max, extrema_show_timestamp, state_adaptive_color.

The entity variable (new in v3.29)

Inside entity-level templates, the row's own entity id is available as a ready-made entity variable — so one generic template can be copy-pasted across every entity unchanged. It works in the display toggles and in the entity-level string fields: color, name, tooltip_name, icon, icon_color, state_color:

entities:
  - entity: sensor.temp_kitchen
    show_graph: "{{ area_id(entity) == states('input_select.selected_zone') }}"
  - entity: sensor.temp_livingroom
    show_graph: "{{ area_id(entity) == states('input_select.selected_zone') }}"   # same text, no edits

Two popular uses — per-entity names and colors from one central place:

entities:
  # every row shows its DEVICE name instead of the sensor name
  - entity: sensor.refrigerateur_power
    name: "{{ device_attr(entity, 'name_by_user') or device_attr(entity, 'name') }}"
  # every row pulls its color from a central color-registry sensor
  - entity: sensor.refrigerateur_power
    color: >-
      {{ state_attr('sensor.entity_colors', 'entities')[device_attr(entity, 'name')] | default('red') }}

No more {% set entity = 'sensor.…' %} boilerplate at the top of every template (templates that still do keep working — their own set simply wins). Templates that mention entity are evaluated once per entity; templates that don't keep sharing a single subscription as before. Card-level templates (title, axis colors, …) have no single-entity context and do not receive the variable.

Accepted template output

The rendered result is interpreted loosely, so templates can return whatever is convenient:

Template output Interpreted as
true / false boolean
on / off boolean
yes / no boolean
numbers "0" → false, any other number → true
unknown / unavailable / none false

Behavior

  • Results update live — the card subscribes to the template and re-renders on every new result.
  • Until the first result arrives, the option uses its default value.
  • Unrecognized template output falls back to the option's default.

Editor

A templated toggle is locked in the visual editor — dimmed, with a {…} badge, and a tooltip showing the template — and is never overwritten by other edits. Remove the template from YAML to unlock the checkbox again.

Not templatable

Data-source and sync booleans are intentionally not templatable — e.g. cache, show_range_band, invert, break_on_null, show_full_period, tooltip_sync / zoom_sync / scroll_sync, energy_date_sync, show_date_picker, sparkline. These change what data is fetched or how cards talk to each other, not just how things are displayed.

Clone this wiki locally