JavaScript templates¶
Use a JavaScript template when a configured value should respond to an entity state, attribute, user, locale, or another value available to the card.
You do not need JavaScript templates for fixed layouts. Use normal YAML, ref(), or calc() when the value does not change at runtime.
Change a style from the current state¶
A template is enclosed by [[[ and ]]] and returns the value used by that YAML field.
Read another card entity¶
Slots keep the expression readable when the entity list changes.
Read a Home Assistant entity¶
Include entities used by the template in the card entities list so their state changes update the card.
Available values¶
| Value | What it gives you |
|---|---|
state | State or selected attribute of the entity connected to the current item |
entity | Complete connected entity |
entities | Entities listed by the card |
entity_slots | Entity indexes grouped by slot |
states | Home Assistant entity states |
hass | Home Assistant frontend values |
constants | Card constants |
item | Current configured item |
user | Current Home Assistant user |
Keep templates readable¶
Use a few linear statements and return the configured value. Put repeated templates in constants and insert them with ref().