Skip to content

Template System

Use dynamic templates to create intelligent, context-aware displays.

Template Syntax

Templates use double curly braces syntax. Expressions are evaluated at runtime based on entity state and attributes.

yaml
rules:
  - state: "on"
    title: "Status: {{ state }}"
    subtitle: "Value: {{ attr.temperature }}°C"

Available Variables

VariableDescriptionExample
stateEntity state valueon, 42%, running
attr.nameEntity attributeattr.temperature
states('entity_id')Other entity's statestates('sensor.temp')
state_attr('id', 'attr')Other entity's attributestate_attr('sensor.weather', 'temp')

State

Primary entity's current state:

yaml
rules:
  - state: "/.*/"
    title: "BATTERY: {{ state }}"

Result: BATTERY: 45%

Attributes

Access entity attributes by name:

yaml
rules:
  - state: "/.*/"
    title: "TEMPERATURE"
    subtitle: "{{ attr.temperature }}°C ({{ attr.humidity }}%)"

Result: TEMPERATURE, 24°C (45%)

Cross-Entity Templates

Reference other entities in your templates:

states()

Get another entity's state:

yaml
rules:
  - state: "on"
    subtitle: "Living room: {{ states('light.living_room') }}"

state_attr()

Get another entity's attribute:

yaml
rules:
  - state: "/.*/"
    subtitle: "Outdoor: {{ state_attr('sensor.weather', 'temperature') }}°C"

Filters

Apply transformations to values using pipe | syntax:

yaml
subtitle: "{{ attr.temperature | round(1) }}°C"

String Filters

FilterDescriptionInputOutput
upperConvert to uppercaserunningRUNNING
lowerConvert to lowercaseRUNNINGrunning
capitalizeCapitalize first letterhelloHello
titleTitle casehello worldHello World
replace(a, b)Replace texterror_codeerror code

Logic Filters

FilterDescription
default(val)Use fallback value if empty/unknown/unavailable

Numeric Filters

FilterDescription
round(n)Round to n decimal places
intConvert to integer
floatConvert to float

Date/Time Filters

FilterDescription
as_timestampConvert to Unix timestamp
timestamp_custom(fmt)Format timestamp using strftime

Format Specifiers:

SpecifierDescriptionExample
%Y4-digit year2024
%mMonth (01-12)01
%dDay (01-31)15
%HHour (00-23)14
%MMinute (00-59)35
%SSecond (00-59)42
%pAM/PMPM
%AWeekday nameMonday
%BMonth nameJanuary

Custom Filters

color_map

Use value as key in color_map configuration:

yaml
color_map:
  on: "#4CAF50"
  off: "#9E9E9E"
  running: "#2196F3"
  error: "#F44336"

rules:
  - state: "/.*/"
    color: "{{ state | color_map }}"
    title: "DYNAMIC COLOR"

Chaining Filters

Multiple filters can be chained:

yaml
subtitle: "{{ attr.description | replace('_', ' ') | title | default('N/A') }}"

Error Handling

If template evaluation fails:

  • Card shows warning in browser console
  • Returns empty string ""
  • Card continues to render normally

Common causes of errors:

  1. Misspelled attribute names
  2. Undefined entities in states() or state_attr()
  3. Invalid filter syntax
  4. Missing required filter arguments

Performance Tips

  1. Cache complex expressions when possible
  2. Avoid heavy calculations in templates
  3. Use color_map instead of inline conditionals for colors
  4. Prefer simple filters over complex expressions

See Configuration for full reference.

Released under the MIT License.