Decluttering Card Plus Contents ↓ GitHub ↗

Defining Templates

A template is a named, reusable piece of dashboard content with holes in it. There are two places to define one, and you can use both on the same dashboard.

Method Best for Editable by clicking?
decluttering_templates at the root Most cases. Keeps every template in one place. No, YAML only
A decluttering-template-plus card Building a template visually, or keeping it next to where it is used. Yes

Both produce exactly the same thing. A template defined either way can be used by any card on that dashboard.


Method 1 — the decluttering_templates key

Add a decluttering_templates mapping at the root of the dashboard configuration — the same level as views:, not inside it.

Get there with ⋮ → Raw configuration editor while editing the dashboard.

decluttering_templates:
  room_light:
    card:
      type: tile
      entity: '[[light]]'
      name: '[[room]]'
      features:
        - type: toggle

  temperature_row:
    row:
      entity: '[[entity]]'
      name: '[[name]]'
      icon: mdi:thermometer

  power_badge:
    badge:
      type: entity
      entity: '[[entity]]'
      name: '[[name]]'
      show_name: true

views:
  - title: Home
    cards:
      - type: custom:decluttering-card-plus
        template: room_light
        variables:
          - light: light.living_room
          - room: Living Room

The shape is always:

decluttering_templates:
  <template name>:
    <card|badge|row|element|group|item|dashboard>:
      # the content, with [[variables]] in it
    default:
      # optional fallback values
    style: |
      # optional CSS

The content key says what the template builds, and a template has exactly one of them:

Content key Builds More
card a card Cards
badge a badge Badges
row a row of an entities card Rows
element an element of a picture-elements card Elements
group (v1.14.0+) several cards laid out on a sections grid as if each were written there. Its cards go under cards:; a bare list of cards is read the same way Cards
item (v2.3.0+) a block of configuration for another template to fill in. Used only through [[name|with:…]] and [[name|repeat:…]], never by a card directly List Entries
dashboard (v2.9.0+) a whole dashboard: its views and anything else a dashboard has. Used by a dashboard strategy’s page:, never by a card Page Templates
function (v2.10.0+) a step of your own, worked out from the value it is given as [[value]] and called as [[room|name]]. Never used by a card directly Templates as Steps

A template can also carry any of these keys beside its content. Every one is listed, with its type, on Configuration Reference.

Key What it is for More
variables declares the variables, for the editor’s controls and checks Describing Variables
default, defaults (v2.0.0+) fallback values; the two spellings mean the same Variables
let (v1.7.0+) values the template works out for itself, which no card can override Variables
extends (v1.8.0+) starts from one or more other templates below
description a line shown in the editors and the template picker Describing Variables
category (v1.8.0+) groups templates in the picker below
deprecated (v2.0.0+) marks a template that has been replaced below
examples (v2.0.0+) sets of variables the template is meant to work with below
on_error (v2.0.0+) what every card using it shows when it cannot be built Using Templates
suggest_for (v1.13.0+) offers it in Home Assistant’s add-card dialog for matching entities Visual Editors
publish (v1.14.0+) lists it in the card or badge picker as a card of its own Visual Editors
name (v1.14.0+) labels its cards in debug output Troubleshooting
style CSS for every card using it Styling
grid_options (v1.2.0+) its size in a sections grid Styling
source (v2.0.0+) written for you when a template is installed, so Check for updates knows where it came from Sharing a Template
author, license, help, homepage, readme, related, requires, setup (v2.6.0+) who wrote it, what it needs and what to ask when it is installed, shown to whoever installs a shared copy Sharing a Template
editor_hide (v2.6.0+) parts of the card editor to leave out for cards using it Visual Editors
checks (v2.9.0+) conditions the card’s values must pass, each with a message and a level Checks and Strict
alert (v2.9.0+) what to build instead of the content while a warn or error check fails Checks and Strict
strict (v2.9.0+) how hard every card using it takes errors and warnings; a card’s own strict: wins Checks and Strict
visibility (v2.9.0+) conditions on the variables that decide which copies are built at all Visibility
version, changes (v2.9.0+) which version the template is and what changed in each, for the health panel below
parameters (v2.10.0+) the names a function: template’s arguments take, in order Templates as Steps
language (v2.10.0+) the template’s own texts, one mapping per language, read with [[$key]] Translating a Shared Template

If you keep your dashboard in YAML mode, this goes in your ui-lovelace.yaml (or whichever file that dashboard uses) and you can split it out with !include:

decluttering_templates: !include decluttering_templates.yaml

views: !include_dir_list views/

Method 2 — a template card

Add a Custom: Decluttering Template Plus card to any view — including inside a stack or a grid, if you would rather keep your definitions together. The card defines the template and is only visible while the dashboard is in edit mode — normal users never see it.

type: custom:decluttering-template-plus
template: quick_light
card:
  type: tile
  entity: '[[light]]'
  name: '[[room]]'
  features:
    - type: toggle
default:
  - light: light.living_room
  - room: Living Room

In edit mode it renders with a blue outline and its name in the corner, showing a preview built from the default values. From v1.10.0 the preview is built the way a card using the template would be: the dashboard’s, view’s and section’s decluttering_defaults apply, and a template that extends: another shows its parent too. (decluttering_defaults is a set of values written on the dashboard, a view or a section that every card under it falls back on; it is explained under Shared default values and listed on Configuration Reference.)

A template card in edit mode, outlined in blue and labelled quick_light

The card below it in that screenshot is an ordinary custom:decluttering-card-plus using the same template with different variables.

Leave edit mode and the outlined card disappears entirely, leaving no gap.

Template cards are found in any view of the dashboard, including inside the sections of a sections view — so you can keep them all together on a hidden “templates” view if you prefer.

See Visual Editors for building one of these by clicking rather than typing.


A template built on another: extends: (v1.8.0+)

The parent tile beside a child that extends it and turns it grey

When templates in a family differ by a line, extends: lets one start from another and say only what is different:

decluttering_templates:
  room_tile:
    default:
      - colour: amber
    card:
      type: tile
      entity: '[[entity]]'
      features: [{ type: toggle }]
  dim_tile:
    extends: room_tile
    default:
      - colour: slate          # only the difference
    card:
      color: grey              # merged into the parent's card

dim_tile is room_tile with a different default colour and one extra key on the card.

It works the same with template cards: put extends: at the top level, beside template:. The parent can be a template card, in decluttering_templates:, or borrowed from another dashboard.

A template that is only ever extended counts as used, so dashboard health does not call it unused.

Several parents at once (v2.0.0+)

Three tiles: tile_base on its own, then with with_toggle added in amber, then with teal added as well, which turns the colour and icon teal

tile_base alone, [tile_base, with_toggle], and [tile_base, with_toggle, teal] with vertical: true.

extends: also takes a list, so a template can be put together from small pieces that each add one thing:

decluttering_templates:
  tile_base:
    card:
      type: tile
      entity: '[[entity]]'
      name: '[[name]]'
  with_toggle:
    card:
      color: amber
      features:
        - type: toggle
  teal:
    card:
      color: teal
      icon: mdi:lamp
  toggle_tile:
    extends: [tile_base, with_toggle]
  lamp_tile:
    extends: [tile_base, with_toggle, teal]
    card:
      vertical: true

The parents fold left to right, and the child goes on top of them all. In lamp_tile that is tile_base, then with_toggle over it, then teal over both, then the template’s own card:. So a name later in the list has the last word over the ones before it: both with_toggle and teal set color, and teal wins because it comes later.

Each parent resolves its own extends: first, and the usual rules hold in every one of them: mappings merge, a null takes a key away, defaults stack. If any name in the list is a template nobody defines, the child is left exactly as written rather than built from the parents that are there, because folding a missing parent in later would put it on top of ones written after it. Renaming a template in the editor rewrites the lists that name it, and dashboard health says when templates extend each other in a loop, naming the path round it.

A child that wants one more row in an Entities card, or one item fewer, does not have to copy out the parent’s whole list. From v2.0.0 it can edit it with __append__, __prepend__, __update__ and __remove__:

decluttering_templates:
  room_list:
    card:
      type: entities
      entities:
        - entity: light.living_room
        - entity: light.kitchen
        - entity: light.bedroom
  room_list_more:
    extends: room_list
    card:
      entities:
        __append__:
          - entity: light.hallway

These are the same list edits a card’s own card: block understands, described in Using Templates.

(v2.11.0+) The parent’s list can be a placeholder, and so can what is appended. extends: merges templates before anything is filled in, so the edit waits until both lists are filled, then joins them. A whole-list placeholder appended this way adds its items one by one, not as one entry:

decluttering_templates:
  ml1:
    item:
      list: '[[my_list1]]'
  ml2:
    extends: ml1
    item:
      list:
        __append__: '[[my_list2]]'

With my_list1: [l1_1, l1_2] and my_list2: [l2_1, l2_2], [[ml2|with]] gives list: [l1_1, l1_2, l2_1, l2_2]. Before v2.11.0 the __append__ key was left in the output and the parent’s list was lost.

Template cards that extend another (v1.10.0+)

Two template cards in edit mode: lamp_tile in amber, and dim_lamp, which only says extends and a colour, previewing as the full tile in grey

- type: custom:decluttering-template-plus
  template: lamp_tile
  default:
    - entity: light.kitchen
  card:
    type: tile
    entity: '[[entity]]'
    color: '[[colour]]'
    features:
      - type: toggle
- type: custom:decluttering-template-plus
  template: dim_lamp
  extends: lamp_tile
  default:
    - colour: grey

dim_lamp has no card of its own, and its preview is the whole tile. lamp_tile leaves colour to the dashboard’s decluttering_defaults: {colour: amber}, and its preview picks that up. Before v1.10.0, dim_lamp showed You must define one card… and lamp_tile previewed without its colour.

Grouping a big collection: category: (v1.8.0+)

The template picker listing Lighting · light_panel with its description, beside templates with no category

room_tile:
  category: Lighting
  description: One tile per room.
  card: {}

The template picker shows it as Lighting · room_tile — One tile per room., and because the category leads the label, alphabetical order brings each category’s templates together. Worth it once a dashboard has more templates than fit on a screen.

Templates that are only there to be extended: base: (v2.11.0+)

A template that other templates extends:, and that is never used on a card by itself, can say base: true. The card editor’s template picker then leaves it out, and so does the choice by domain:

The template picker listing camera_full and camera_simple under Cameras, with camera_base and the mix-in it extends left out

decluttering_templates:
  camera_base:
    base: true
    card:
      type: vertical-stack
      cards:
        - type: heading
          heading: '[[camera_name]]'
  camera_simple:
    extends: camera_base
    card: {}

base: is not inherited, so camera_simple shows as normal. A mix-in that extends a base can say base: true itself and stay hidden too. A card already using a base template keeps it in its picker, so nothing that works changes. The template still builds the same everywhere; base: is the editor’s business only.

Templates inside templates: inherit_variables (v1.13.0+)

A template can hold decluttering cards of its own, a stack of two lights say. Each of those gets only the variables written on it, so a stack that needs the same values in both cards has to pass every one down by name.

inherit_variables: true on the nested card hands it everything the card around it has: what that card was given, what its view sets and what its template defaults to. Anything the nested card writes for itself still wins.

decluttering_templates:
  room_tile:
    card:
      type: tile
      entity: '[[light]]'
      name: '[[room?]]'
      features:
        - type: '[[control?]]'
  light_pair:
    card:
      type: vertical-stack
      cards:
        - type: custom:decluttering-card-plus
          template: room_tile
          inherit_variables: true
        - type: custom:decluttering-card-plus
          template: room_tile
          inherit_variables: true
          variables:          # this one differs
            - light: light.kitchen
            - room: Kitchen
type: custom:decluttering-card-plus
template: light_pair
variables:
  - light: light.living_room
  - room: Lounge
  - control: toggle

Both tiles get the toggle; the second keeps its own light and name:

Two tiles from one card, the second overriding the light and name it was handed

Placeholders in the values are filled in by the outer card before they are handed down, and it works through any number of levels as long as each nested card asks. Two things stay behind: the outer template’s let: values, which are its own internals, and the dashboard’s decluttering_defaults, which every card reads for itself anyway. It is off unless asked for, because a value handed down beats the nested template’s own default for the same name.

Retiring a template: deprecated: (v2.0.0+)

The card editor for a card using room_tile, with a warning above the form: This template is deprecated: Use room_tile_v2, which has the toggle

The card still renders as it always did; the note is in the editor.

When a template has been replaced but cards still use it, mark it rather than delete it:

decluttering_templates:
  room_tile:
    deprecated: Use room_tile_v2, which has the toggle
    card:
      type: tile
      entity: '[[entity]]'

deprecated: true works too, without a message. Nothing about the cards using it changes, they render exactly as before. The note goes where whoever keeps the dashboard will see it:

Dashboard health: room_tile is deprecated (Use room_tile_v2, which has the toggle) and still used by: Deprecated (1), the template room_tile_child

The same template in dashboard health, used by one card on the Deprecated view and by a template that extends it.

A template that extends: a deprecated one is not deprecated itself. It can say so for itself if it is.

Showing how it is used: examples: (v2.0.0+)

examples: is a list of variable sets the template is meant to work with, each written the way a card writes its variables::

decluttering_templates:
  climate_tile:
    description: Temperature and humidity for one room
    examples:
      - room: Living Room
        temperature: sensor.living_room_temperature
        humidity: sensor.living_room_humidity
      - room: Bedroom
        temperature: sensor.bedroom_temperature
        humidity: sensor.bedroom_humidity
    card:
      type: entities
      title: '[[room]]'
      entities:
        - entity: '[[temperature]]'
          name: Temperature
        - entity: '[[humidity]]'
          name: Humidity

Each entry of the list is one whole example. To write one in the list form, it is a list inside the list:

examples:
  - - room: Bedroom
    - temperature: sensor.bedroom_temperature

They are used in three places. The template editor gets a Preview with dropdown listing the defaults and each example, and draws its preview with the one you pick. The pick is not saved, it only changes the preview:

The template editor with Preview with set to Example 1: Living Room, 2 of 2 pass, and the preview showing the Living Room tile

Preview with set to Example 1 draws the Living Room.

From v2.6.0 the dropdown sits in the example strip above the editor’s tabs, with a count of how many examples build cleanly and a + that adds the values the preview is using as a new example.

The card editor offers the examples as presets, see below. Before v2.9.0 it offered Start from example 1, 2 and so on, and only for a card that set no variables yet.

And dashboard health builds every example of every template on the dashboard and reports the ones that do not build cleanly, saying why: a nested template that does not exist, templates using each other in a loop, a variable left unset, a value its declaration will not take, or a template defining two things or none. That makes the examples a small test of the template, run every time you open the panel.

Dashboard health: Example 2 of door_tile does not build cleanly: Leaves [[entity]] unset, so it shows as written and a strict card refuses it

An example that leaves out a value the template needs.

A template made with extends: does not take its parent’s examples, since they were never checked against what the child builds.

Examples as presets (v2.9.0+)

The card editor's Preset dropdown listing Living room, Bedroom and Example 3, and below it the question asked before a preset changes a value set by hand

The card editor shows a template’s examples in a Preset dropdown, for any card using it, not only a new one. Picking a preset writes its values into the card’s variables. A variable the preset does not name keeps the value the card has.

An example can carry a name for the dropdown. Write it as a mapping of exactly name and values:

decluttering_templates:
  climate_tile:
    description: Temperature and humidity for one room
    examples:
      - name: Living room
        values:
          room: Living Room
          temperature: sensor.living_room_temperature
          humidity: sensor.living_room_humidity
      - name: Bedroom
        values:
          room: Bedroom
          temperature: sensor.bedroom_temperature
          humidity: sensor.bedroom_humidity
      - room: Kitchen
        temperature: sensor.kitchen_temperature
    card:
      type: entities
      title: '[[room]]'
      entities:
        - entity: '[[temperature]]'
          name: Temperature
        - entity: '[[humidity]]'
          name: Humidity

An example without a name is listed as Example 3, by its place. Only a mapping with both keys and nothing else is read as a named example, so an example that sets a variable called name is still a whole example of its own.

When a preset would change a value you set by hand, the editor asks first, naming the variables: Apply it anyway or Keep my values. The preset is not saved on the card. The dropdown shows a preset’s name while every value it sets matches the card, and None matches the values set once you change one.

Saying which version a template is: version: and changes: (v2.9.0+)

A template many cards use changes over time: a variable is renamed, one is dropped. Give the template a version: and a changes: note per version, and the health panel can explain the change to the cards still written for an older one:

decluttering_templates:
  room_light_tile:
    version: 3
    changes:
      3: show_brightness is now brightness_mode
      2: icon defaults to the entity's own
    variables:
      - name: entity
      - name: brightness_mode
        default: slider
    card: ...

A card still passing show_brightness is already listed in Dashboard health as passing a variable the template never reads. With the note, the panel adds when and why: Dropped in version 3: “show_brightness is now brightness_mode”. Because the note says what the variable became, a Rename to brightness_mode button rewrites those cards in that view, carrying each card’s value across as it was:

Dashboard health: cards passing show_brightness, dropped in version 3, with a Rename to brightness_mode button, and a note that the copy on another dashboard is version 2

The panel finds a replacement in a note that says old is now new, old became new, old renamed to new, old replaced by new, or old -> new, with or without backticks round the names. A note that only mentions the variable is still shown, without the button. A version’s note can be a list of lines; the newest note naming the variable is the one shown.

version: is a number (3, or '3'). When a dashboard defines a template that it also borrows from another dashboard, and the copy there has a lower version, the panel says so, as in the second line above. That needs a version on both copies.

Nothing is enforced. A card written for version 1 still builds; the version is there to explain, not to refuse. The shared-templates store does not read version:: it compares posts, not versions.


Checking YAML as you type: the JSON schemas (v2.9.0+)

A dashboard kept as YAML can be checked while you write it. The card publishes JSON schemas for its configuration on the documentation site, and any editor running the YAML language server, such as VS Code with Red Hat’s YAML extension or the Studio Code Server add-on, uses them to complete keys, show what each key is for, and underline a value the card would not take.

Schema Covers
https://tempus2016.github.io/decluttering-card-plus/schema/dashboard.json a whole dashboard file: decluttering_templates, decluttering_defaults, decluttering_variables, decluttering_let, decluttering_strict, decluttering_templates_from, a dashboard strategy: with its page:, and the decluttering_* keys and strategies of views and sections
https://tempus2016.github.io/decluttering-card-plus/schema/template.json one template, as in a file of its own
https://tempus2016.github.io/decluttering-card-plus/schema/card.json a custom:decluttering-card-plus card, or a template card

Point the editor at one with a line at the top of the file:

# yaml-language-server: $schema=https://tempus2016.github.io/decluttering-card-plus/schema/dashboard.json
decluttering_templates:
  ...

Or once for every dashboard file, in VS Code’s settings.json. Home Assistant’s own tags need declaring at the same time, or the extension underlines every !include:

{
  "yaml.schemas": {
    "https://tempus2016.github.io/decluttering-card-plus/schema/dashboard.json": [
      "ui-lovelace.yaml",
      "dashboards/*.yaml"
    ]
  },
  "yaml.customTags": [
    "!include scalar",
    "!include_dir_named scalar",
    "!include_dir_merge_named scalar",
    "!include_dir_list scalar",
    "!include_dir_merge_list scalar",
    "!secret scalar"
  ]
}

What it checks: the card’s own keys and the shape of their values, the conditions of a template’s visibility: (exist: true is underlined), and the shape of a placeholder: brackets that come in pairs, and a step that takes a value written name:value, so [[entity|default]] is underlined and [[entity|default:x]] passes.

(v2.10.0+) A malformed placeholder is underlined with a plain message rather than the schema’s raw pattern: A [[placeholder]] here is not well formed. Check that the brackets come in pairs and that a step with a value is written name:value, as in if:name or default:x. Misspelt step names are not checked here: the card editor and lint name them. Since a template can be used as a step, any step name is let through, so [[entity|frendly_name]] is no longer underlined; the card editor and the command-line lint still name it.

What it does not: a key it does not know on a card or a template is let through rather than underlined, so a misspelt key is not caught; the card’s health panel and its console warnings still are. It cannot know your template names, so template: takes any text. A view, a section or a card that is not a decluttering card is not checked beyond its decluttering_* keys: a tile’s own keys are Home Assistant’s to check. The schemas are generated from the card’s code at every release, so a new key is in the schema the release it ships in. The File editor add-on does not run a language server, so it shows none of this.


Rules

One content type per template. A template used by a card must have exactly one of card, badge, row, element or group. A template with dashboard: (v2.9.0+) is a page template, used by a dashboard strategy’s page: rather than by a card. With none of them, the card reports:

You must define one card, badge, element, or row in the template

A card that uses an item template directly gets the same message, since an item template is only for with: and repeat:. With two of them, it names the first two, in the order card, row, element, badge, group:

This template defines both “card” and “badge”. A template can only define one of card, badge, element or row.

Names must be unique. If the same name is defined twice on one dashboard, the last one found wins, and which that is depends on config order. Don’t do it.

Templates are per dashboard. A template defined on dashboard A is not visible to dashboard B unless B explicitly borrows it, or A is the library dashboard every dashboard borrows from — see Sharing Templates Between Dashboards.

Naming. Anything valid as a YAML key works. snake_case is conventional and easy to read in the template dropdown.


Next

→ Using Templates — putting them on the dashboard → Variables — filling in the holes