Describing Variables
A template can say what each of its variables is, not just what it defaults to. Do that, and every card using the template gets a real control for it — an entity picker, a dropdown, an icon picker — instead of a box of hand-typed YAML.

Describing variables is entirely optional. A template that describes nothing works exactly as it always has.
Declaring them
variables: on the template is a list, one entry per variable, or a
mapping keyed by name:
type: custom:decluttering-template-plus
template: room_tile
description: A tile for one room's light.
variables:
- name: entity
label: Light
description: Which entity this tile shows
selector:
entity:
domain: light
- name: colour
label: Colour
selector:
select:
options: [red, blue, amber]
default: red
card:
type: tile
entity: '[[entity]]'
name: '[[label]] ([[colour]])'
| Key | Type | Required | Description |
|---|---|---|---|
name |
string | ✅ | The variable’s name, as written in [[name]] |
label |
string | — | What the editor calls it. Defaults to the name |
description |
string | — | Helper text under the control |
selector |
mapping | — | Any Home Assistant selector. Defaults to a plain text box |
type (v2.0.0+) |
string | — | A shorter way to ask for a control: entity, number, boolean, icon, color, text or select. See Saying what kind of value it takes |
default |
any | — | The value to use when a card does not set one. defaults (v2.0.0+) means the same |
required (v1.1.0+) |
boolean | — | Whether the template is unusable without it. See Insisting on a value |
The checks (pattern:, allowed:), the type: extras (domain:, min:, multiline:…),
group:, and show_if:/hide_if: (v2.6.0+) are covered further down this page. Every declaration key is listed in one table
on Configuration Reference.
description: on the template itself is shown above the controls, so whoever uses it
can see what it is for. It travels with the template when you
share it.
An entry with no name, or a name that repeats an earlier one, is ignored rather than
breaking the card.
Written as a mapping (v2.3.0+)
The same declarations can be a mapping keyed by name, which is shorter when most of them only need a default:
variables:
colour: red # declares colour, with red as its default
entity: # the whole declaration, as in the list form
label: Light
selector:
entity:
domain: light
room: # declares the name and nothing else
A plain value is the default. A mapping is always read as the declaration itself, so a
default that is a mapping has to go under default::
variables:
action:
default:
action: toggle
Both shapes mean exactly the same thing, and decluttering_variables takes either too. The
editor’s suggestions and setting to variable add to a mapping as a mapping.
Insisting on a value (v1.1.0+)
required: true says the template cannot do its job without that variable:
variables:
- name: entity
label: Light
required: true
selector:
entity:
domain: light
It does two things.
In the card editor, the field is marked required, and a card that leaves it unset is told so as an error rather than a warning — This template needs a variable you have not set: entity. Like every other message here, it still does not stop you saving.
In a repeat, an item that leaves it empty is skipped rather than rendered broken. That
is what lets one for_each cover a room with three lights and a room with one, without a
dummy entity id standing in for the lights that are not there — see
Repeating a Template.
Empty means unset, null or ''; a 0 and a false are values. For example, with this
template repeated over a list of lights:
decluttering_templates:
light_row:
variables:
light: { type: entity, domain: light, required: true }
card:
type: tile
entity: '[[light]]'
type: custom:decluttering-card-plus
template: light_row
for_each:
- light: light.kitchen_ceiling
- light: '' # dropped: required and empty
- light: light.kitchen_pendant
the card shows two tiles, not three. This is the card’s own for_each and for_each_from;
the view and dashboard strategies do not drop copies this way. On a
single card, outside a repeat, required: changes nothing about what is built; it only shows
in the editor.
required: true alongside a default contradicts itself, since a variable with a default
can never be unset, and the template editor says so.
If what you want is the opposite — a variable the card can simply do without — that is the
? marker on the placeholder rather than anything in the declaration. See
Variables.
Checking the value: pattern: and allowed: (v1.8.0+)

A declaration can say what an acceptable value looks like, and the card editor warns when a card’s value does not fit:
variables:
- name: entity
selector: { entity: {} }
pattern: '^light\.' # a regular expression
- name: mode
allowed: [on, off, auto] # one of these exactly
The value of entity is not one the template accepts. It expects: ^light..
A few things worth knowing:
- It warns; it never blocks. The card saves and renders as it would have, the same as every other warning.
- An unset value is not a wrong one. Leaving a variable empty is what
requiredis for. - The pattern is not anchored for you.
lightmatchessensor.light_leveltoo; write^light\.to mean “starts with light.”. allowed:wins if a declaration has both, and a pattern that is not a valid regular expression is ignored rather than breaking the card.- Long patterns and long values are not checked (v1.15.1+). A pattern over 200 characters, or one shaped so that it could take the browser a very long time, is skipped, and so is any value over 1000 characters. A template shared by someone else cannot freeze the editor that way. Nothing is shown when a check is skipped.
A value with a placeholder in it (v3.2.0+)
A value such as default: '[[default_camera_view]]' is worked out first, the way the build
would, and what it becomes is checked against the type, allowed: and pattern:. A
placeholder that cannot be filled in the editor is left unchecked rather than warned about.
Before v3.2.0 the type check skipped such a value, but allowed: and pattern: compared the
brackets themselves and always warned.
The warning ends with what the value is now, in quotes, so a stray space or an invisible character shows up:
The value of mode is not one the template accepts. It expects: on, off, auto. It is now: “auto “.
allowed: as a dropdown (v1.11.0+)

A declaration with allowed: and no selector: gets a dropdown of exactly those values in
the card editor, instead of a text box that warns after the fact. A selector: of your own
still wins. Values are compared as text, so allowed: [1, 2] accepts the 2 a dropdown
hands back.
Labels for the values (v3.1.0+)

An entry can be a label and a value, the way Home Assistant’s select selector writes its options. The dropdown shows the label and the card is given the value:
variables:
- name: aspect_ratio_mode
default: static
allowed:
- label: Static ratio
value: static
- label: Match media
value: dynamic
- label: Ratio unenforced
value: unconstrained
Plain values and labelled ones can be mixed, and an entry with no label shows its value. The check compares the card’s value with the values, never the labels, so a card holding Match media is warned about. An entry with no value is left out. The declarations editor has no field for labelled values, so it leaves them as written.
Picking more than one: multiple: (v3.2.0+)
![The card editor's Views to offer field holding live and clips as chips with an Add button, and the line Default: [live] under it](/decluttering-card-plus/images/v320-preview-folded.png)
multiple: true lets the field take several of the values, each shown as a chip with Add
for the next, and the card is given them as a list:
variables:
- name: views
allowed: [live, clips, snapshots, recordings]
multiple: true
default: [live]
Each entry of the list is checked against allowed:, and an empty list counts as unset. The
declarations editor has a Pick more than one switch for it.
A selector: you write yourself still wins, but a written select: with no options: now
takes them from allowed:, so selector: {select: {multiple: true}} beside allowed: is the
same as the example above. Before v3.2.0 it gave a dropdown with nothing in it.
allowed: from a placeholder (v3.2.0+)
allowed: can be a placeholder, filled in the way a default is, so a list kept in one place
can feed the dropdowns of many templates:
decluttering_templates:
camera_card:
default:
- camera_views: [live, clips, snapshots]
variables:
- name: view
allowed: '[[camera_views]]'
This happens in the card editor only. A placeholder it cannot fill leaves the field as a text box with nothing checked.
A dropdown of what Home Assistant has: options_from: (v2.9.0+)
When the choices are entities, areas or devices you already have, options_from: finds
them instead of you listing them. It takes the same source a repeat’s
for_each_from: does, and each thing it finds becomes one option
in the dropdown:
variables:
- name: zone_name
label: Zone
options_from:
entities: 'sensor.*_zone_all_count'
option_value: '[[entity|object_id|replace:_all_count:]]' # what the variable is set to
option_label: '[[name]]' # what the dropdown shows
With sensors sensor.driveway_zone_all_count and sensor.garden_zone_all_count, the
dropdown offers Driveway zone and Garden zone, and picking one sets zone_name to
driveway_zone or garden_zone.
option_value:andoption_label:are filled in once per thing found, with the same names a repeat copy gets:entity,name,area,area_id,device,indexand the rest, listed under What each copy is given.- Leave out
option_value:and an option is the thing itself: its entity id, or its area, device, floor or label id. Leave outoption_label:and the dropdown shows the value. - An option that fills in to nothing is left out, and so is one whose value is already offered: two sensors trimmed to the same name are one choice.
- A
selector: {select: ...}written beside it keeps its own settings, such asmultiple:orcustom_value:, and only its options are replaced. Any other way of setting the control is ignored whileoptions_from:is there. - The list is worked out when the card editor opens. Something added while it is open shows up the next time you open it.
- Entity patterns follow the same rules as a repeat: diagnostic and config entities are left
out unless you add
entity_category: all. Atemplate:source gives no options here. - It only changes the editor. A card still builds with whatever value it was given, and a
value that is not in the list is not warned about; add
allowed:orpattern:for that.
Saying what kind of value it takes: type: (v2.0.0+)
Spelling out a Home Assistant selector is more than most variables need. A declaration can
say type: instead, and the card editor offers the matching control:
variables:
- name: light
label: Light
type: entity
domain: light
- name: columns
label: Width
type: number
min: 3
max: 12
step: 3
unit: columns
- name: compact
label: Compact
type: boolean
- name: icon
label: Icon
type: icon
- name: accent
label: Colour
type: color
- name: note
label: Note
type: text
multiline: true

type: |
Control | Also takes |
|---|---|---|
entity |
An entity picker | domain: and device_class:, each one or a list, to narrow it. integration: and supported_features: too (v3.1.0+) |
number |
A slider when both ends are given, a number box otherwise | min:, max:, step:, unit: |
boolean |
A switch | |
icon |
An icon picker | |
color |
Home Assistant’s named colours, red, amber, primary…, which is what a tile’s color: takes |
|
text |
A text box | multiline: true for a big one |
select |
A dropdown of the allowed: values. Without allowed: it is a plain text box |
allowed: |
integration: and supported_features: only narrow the picker (v3.1.0+); the value check below still looks at the domain and the device class alone:
variables:
- name: plug
type: entity
domain: switch
integration: zha
A selector: of your own still wins over type:, as it does over allowed:. A type the card
does not know falls back to the control it would have had anyway, and the console says so
once.
The card editor also checks a card’s values against their type, the way it checks
pattern: and allowed:, warning without
blocking: an entity outside its domains or with the wrong device class (when Home Assistant
knows the entity), a number that is not one or is out of range, an icon not written like
mdi:name, and a boolean that is not one of the words bool
reads, yes/no, true/false, on/off, 1/0. A value still holding a placeholder is
left alone.
A typed boolean holding some other word, maybe above, shows its switch off, the way bool
would read it, alongside the warning. The word itself is kept when you edit another field;
only moving the switch replaces it with a real true or false.
Types of your own: decluttering_types and types: (v3.0.0+)

When several variables want the same control, a colour list offered by four of them, say, write the shape once and give it a name. Put it under decluttering_types: at the top of the dashboard (or the library dashboard), or under types: on a template, and have a declaration say type: with that name:
decluttering_types:
colour_picker:
label: Colour
default: red
selector:
select:
options: [red, amber, blue, green, grey]
mode: dropdown
percent:
type: number
min: 0
max: 100
unit: '%'
decluttering_templates:
light_tile:
types:
percent: # this template's own percent wins over the dashboard's
type: number
min: 0
max: 100
step: 5
unit: '%'
variables:
- name: light
type: entity
domain: light
- name: accent
type: colour_picker
- name: off_colour
type: colour_picker
label: Colour when off
default: grey
- name: night_level
type: percent
label: Night brightness
card:
type: tile
entity: '[[light]]'
color: '[[accent]]'
A declaration takes everything the type says, then its own keys over the top: off_colour above keeps the colour list but has its own label and default. Only top-level keys are swapped, so a declaration that writes its own selector: replaces the type’s whole selector.
A type can build on one of the built-in types, as percent does with type: number, and works exactly as that type would. It can’t build on another type of your own, and it can’t take a built-in’s name (number, entity and the rest): the built-in always wins, and the console says so. A template’s types: wins over the dashboard’s for a name both use, and extends: merges types name by name, the child’s winning.
A field of an object selector can say type: too, and takes the type’s label, required, selector and default.
A type: that matches neither a built-in type nor one of yours is left untyped, and template lint and the console name it. Exporting a template brings the types it uses into its own types:, so it still works on a dashboard that has none.
Declarations shared by many templates: decluttering_variables (v1.13.0+)
A variable used by several templates, a light or a colour, needs the same label, selector
and default written into each of them. Write it once at the top of the dashboard instead,
in the same shape as a template’s variables::
decluttering_variables:
- name: light
label: Light
selector:
entity:
domain: light
- name: colour
label: Colour
selector:
select:
options: [amber, blue, red]
default: amber
decluttering_templates:
coloured_tile:
variables:
- name: light
- name: colour
description: The colour of the icon # this template's own words win
card:
type: tile
entity: '[[light]]'
color: '[[colour]]'
A template takes a shared declaration up by declaring just its name, and anything it writes
beside the name wins. A template that never names one is left alone, so sharing a
declaration never adds a field to a template that has no use for it. The default is a
default like any other: a card passing nothing gets amber.

Like decluttering_defaults, they apply to the templates on the same dashboard. A template
borrowed from another dashboard gets this dashboard’s declarations ahead of the lender’s.
Selectors worth knowing
Any Home Assistant selector works. These are the ones that come up most:
selector: {entity: {}} # any entity
selector: {entity: {domain: light}} # lights only
selector: {text: {}} # a line of text
selector: {text: {multiline: true}} # a block of text
selector: {number: {min: 1, max: 12, mode: box}} # a number
selector: {boolean: {}} # a switch
selector: {icon: {}} # an icon picker
selector: {select: {options: [red, blue]}} # a fixed set
selector: {area: {}} # an area
selector: {ui_color: {}} # a Home Assistant colour
A selector that produces a number gives you a real number, so it works as a whole value — see value types.
An object’s fields and their defaults (v3.1.0+)
An object selector’s fields: is a mapping keyed by the field’s name. Each field can say type: and the keys that go with it, and a default:, written there or coming from a type of your own:
variables:
- name: stream
selector:
object:
fields:
url:
type: text
default: '[[camera]]_main'
fps:
selector: {number: {}}
default: 10
When the card leaves a field out, the build fills it from its default:, and when the card never sets the object at all, the whole object is made from the defaults: [[stream.fps]] is 10 either way. A field the card sets, even to nothing, is kept. A list of objects (multiple: true) has each entry filled; an unset list stays unset, as there is no entry to fill. A placeholder in a default is filled from the card’s variables, so it follows them. The debug report marks such a variable as field defaults, or this card + field defaults.
Reading the entry’s other fields: __this__ (v3.2.0+)
A field’s default can read another field of the same object with [[__this__.field]]. It gets
what the card set there, or else that field’s own default, and in a list it reads the entry it
is filling:
variables:
- name: buttons
selector:
object:
multiple: true
fields:
name: {type: text}
bg_color: {type: text, default: grey}
fg_color: {type: text, default: '[[__this__.bg_color]]'}
With buttons: [{name: Dog}, {name: Cat, bg_color: yellow}], Dog’s fg_color is grey and
Cat’s is yellow. A default can read a field whose own default reads another; they are worked
out in the order they need. Anything else in the default, such as [[suffix]], is filled from
the card’s variables as before.
The editor’s Default: line only shows for top-level variables, not for each field inside a
list entry, so it will not show what fg_color turns into; the
debug report does.
Before v3.1.0 a field’s default: was only used by Home Assistant’s own Add dialog, which put the default into the field as written.
Which value wins
A declaration’s default: is one of several places a value can come from. When more than
one of them sets the same name, the first in this order wins:
| Order | Where | Notes |
|---|---|---|
| 1 | the template’s let: (v1.7.0+) |
worked out, never overridden |
| 2–4 | the section’s, then the view’s, then the dashboard’s decluttering_let (v2.0.0+) |
worked out, never overridden |
| 5 | variables: on the card using the template |
in a repeat, the item’s own values come first, then the card’s variables:, then index and the other position names |
| 6 | the section’s decluttering_defaults (v1.10.0+) |
|
| 7 | the view’s decluttering_defaults (v1.9.0+) |
|
| 8 | default: inside a declaration |
a shared decluttering_variables default ranks here too, for names the template declares |
| 9 | the template’s default: list |
|
| 10 | the template’s defaults: list (v2.0.0+) |
default: wins a name both set |
| 11 | the dashboard’s decluttering_defaults (v1.1.0+) |
for a borrowed template, this dashboard’s, then the lender’s |
| 12 | an entity named in the card’s rebuild_on, or in the template’s (v2.10.0+), standing for itself |
only for a name nothing above sets |
| 13 | an item template, standing for its block | only for a name nothing above sets |
So a card’s own value beats every default, a view or section default beats the template’s,
and nothing beats a let:. Within one list, the first entry for a name wins. The same order
is on Placeholder Reference.
The section, view and dashboard values are covered in Sharing Templates Between Dashboards.
default: is untouched by any of this and still works on its own. You can use both — but
if the same name has a default in both places, the declaration is the one that counts, and
the template editor says so.
Which one should I use
- A value for one template: a declaration with
default:. It gets the right control in the editor and beats the template’sdefault:list. - Just a value, no control: the template’s
default:list is enough. - The same label, selector and default in several templates:
decluttering_variables, and have each template name the variable. - A value every template on the dashboard falls back on: the dashboard’s
decluttering_defaults. It is the weakest of all, so any template can still set its own. - A value for every card in one view or section: that view’s or section’s
decluttering_defaults. These beat every template default, so use them to change what a template would otherwise show. - A value for one card: the card’s own
variables:.
What you get in the editor
For a template that declares its variables, the card editor shows:
- the template’s
description, above everything - one control per declaration, with its label and helper text
- an Other variables box underneath, holding anything the template does not describe
Nothing is lost either way. Values the template never declared stay editable in that box, and a template that declares nothing shows the plain YAML box exactly as before.
Leaving a control empty sets nothing, so the template’s own default applies. Since v2.7.0 the control shows that default rather than standing empty, but showing it writes nothing into the card: writing it into every card is the duplication templates exist to remove. See Defaults shown in each field. To set a variable to an actual empty string, use the Other variables box.
A default built from an item template (v2.9.0+)
A declaration’s default: can be a whole block that an
item template fills in, with
[[name|with]] or [[name|repeat:...]]. The card editor now works it out the way the card
does, with the dashboard’s item templates, and shows what it comes to:
decluttering_templates:
temp_row:
default:
- room: '[[entity|object_id|replace:_temperature|replace:_: |title]]'
item:
entity: '[[entity]]'
name: '[[room]]'
every_temperature:
default:
- sensors:
entities: sensor.*_temperature
item:
- '[[temp_row|repeat:sensors]]'
temperatures:
variables:
- name: rows
label: Rows
selector:
object: {}
default: '[[every_temperature|with]]'
card:
type: entities
title: Temperatures
entities: '[[rows]]'

A card using temperatures with nothing set gets one row per temperature sensor, and its
editor shows those rows in the field, where before v2.9.0 the field stayed blank. Edit them
and the card keeps your rows instead; leave them and it still writes nothing.
Folding a long list: group: (v1.8.0+)

A template with a dozen variables makes for a long form. Give declarations a group: and the
card editor folds each group into its own section:
variables:
- name: entity
- name: accent
group: Style
- name: name
- name: radius
group: Style
- name: level
group: Behaviour
Ungrouped declarations come first, then each group in the order its first declaration
appears — here entity and name at the top, then Style, then Behaviour.
Showing a field only when it matters: show_if and hide_if (v2.6.0+)

Some variables only mean something once another has a certain value. show_if: and hide_if: on a declaration leave its field out of the card editor until it applies:
variables:
- name: source
type: select
allowed: [Frigate, Home Assistant]
default: Frigate
- name: use_zones
type: boolean
default: true
show_if: source=Frigate
- name: zone_prefix
show_if: use_zones
hide_if: source!=Frigate
They take the same conditions as an if: step, without the if::
| Condition | Holds when |
|---|---|
name |
it reads as a yes, the way the bool step reads it: set, and not false, off, no, 0 or empty |
!name |
it does not |
name=text |
it is exactly text |
name!=text |
it is anything else, including unset |
Write one, or a list. Any show_if holding shows the field, and any hide_if holding hides it. With both written, the field shows only while at least one show_if holds and no hide_if does. The values read are the ones the card will use, so a variable’s default counts, and the field comes and goes as you type. (v2.10.0+) A value written with placeholders, such as has_cam: '[[camera|exists]]' in default:, is read filled in, the way the card fills it, so the field shows only while the camera exists; before, it was read as its text, which always counts as a yes. A value that cannot be filled in is read as written, as before. To show a field only while two things hold, list the opposite of each under hide_if: hide_if: ['!camera', '!has_backup']. Quote any condition that starts with !, as in hide_if: '!camera': unquoted, YAML reads a leading ! as a tag, not as text. A leading if: is allowed and changes nothing. A dotted name such as room.night works as it does in if:.
It is the editor’s business only. A hidden variable keeps its value and its default, and the card builds exactly as it would without these keys. If the card still sets a variable that is now hidden, the editor says so, since that value still goes into the card; clear it in the code editor if it should not. A hidden variable is never reported as missing, even when required:.
A condition the card cannot read, such as source==Frigate, is skipped rather than treated as false, so a typo never hides a field for good. Template lint names it, and a name in a condition that the template never declares, defaults or uses.
An unset switch is drawn at its declaration’s default: true or false (v2.6.0+). Before, a switch with default: true looked off until it was touched, though the card, and now a show_if reading it, took it as on. It still writes nothing until you move it.
Settings for a whole group: groups: (v3.0.0+)

A template’s groups: says things about a whole group: of its variables at once, keyed by the group’s name:
groups:
Night mode:
show_if: night_mode
description: Only used while night mode is on
Colours:
expanded: true
variables:
- name: night_mode
type: boolean
- name: night_level
type: number
group: Night mode
- name: night_colour
group: Night mode
- name: accent
group: Colours
| Key | What it does |
|---|---|
show_if, hide_if |
The same conditions as on a declaration, for every field in the group. A group that is hidden leaves no section at all |
expanded |
true starts the group’s section open. Sections you open or close yourself stay that way |
description |
A line under the group’s title |
A group’s show_if and hide_if come first: while the group is hidden, so is every field in it, whatever the field’s own conditions say. While it shows, each field still answers to its own. A variable read only by a group’s or a field’s show_if/hide_if counts as used, so the editor no longer calls it unused.
The name has to match the variables’ group: exactly; template lint points out a groups: entry no variable uses. extends: merges groups: group by group, the child’s keys winning, and an export carries them.
A variable that takes a whole card: selector: {card: {}} (v1.8.0+)

A declaration can take an entire card as its value — a template that frames whatever card you hand it, say:
variables:
- name: inner
selector: { card: {} }
card:
type: vertical-stack
cards:
- type: markdown
content: '## [[title]]'
- '[[inner]]'
In the card editor that variable gets Home Assistant’s own card picker and card editor, the same as adding a card to a view, and Choose a different card starts again.
Warnings
Once a template describes itself, both editors can point out the mistakes that are easy to make and impossible to see:
| Where | Message | Means |
|---|---|---|
| Card editor | This template needs variables you have not set: … (v1.1.0+) | A required: true variable with no value. Shown as an error, not a warning |
| Card editor | This template uses variables with no value and no default: … | The card will render the literal text [[name]] |
| Card editor | This variable is set here but never used by the template: … | Usually a typo in the name, or a leftover from an older version of the template |
| Template editor | This variable is declared but never used in the template: … | A declaration with no matching [[name]] |
| Template editor | These variables have a default in both places… | The same name defaulted in variables: and in default: |
| Template editor | These variables are marked required but have a default… (v1.1.0+) | required: true and a default on the same variable, which contradict each other |
| Card editor, health panel, linter | Template … has variblees:, which no template reads, so it is ignored. (v3.2.0+) | A misspelt or unknown key in a template’s definition. See Keys nothing reads |
None of them stop you saving. A template can be edited after the cards that use it, so a card that looks wrong now may be right again in a moment.
A variable used only through a transform
counts as used: [[room|slug]] is a use of room.
A placeholder that only appears inside the value of a variable nothing refers to is never substituted, so it is not reported as missing either.
Letting the editor write them for you
If you already have the card, you do not have to declare anything by hand — the template editor can work it out. See Turning a card into a template.
Next
→ Variables for placeholders, defaults and value types → Visual Editors for the editors themselves → Repeating a Template for rendering one template many times