Skip to content

Using Templates

tempus2016 edited this page Aug 20, 2026 · 2 revisions

Using Templates

Once a template exists (Defining Templates), you instantiate it with custom:decluttering-card-plus.

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

That is the whole syntax. template: names the template, variables: fills in its holes.

Option Type Required Description
type string custom:decluttering-card-plus
template string Name of the template to use
variables list Values to substitute. See Variables.
style string CSS to inject. See Styling.

variables is a list of single-key mappings, each starting with -:

variables:
  - light: light.kitchen     #
  - room: Kitchen

not

variables:
  light: light.kitchen       # ❌ rejected
  room: Kitchen

Where it goes

The same custom:decluttering-card-plus type is used everywhere. What matters is that the template's content type suits the place you put it.

Templated badges above two templated cards and an Entities card of templated rows

Three places, one card type: the badges, the two tiles and the three rows are each custom:decluttering-card-plus pointing at a badge, card and row template.

As a card

Anywhere a card goes — a view, a stack, a grid, a section:

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

As a badge

In a view's badges: list (sections views):

views:
  - type: sections
    badges:
      - type: custom:decluttering-card-plus
        template: power_badge
        variables:
          - entity: sensor.solar_power
          - name: Solar

As an entity row

In an Entities card's entities: list:

- type: entities
  title: Temperatures
  entities:
    - type: custom:decluttering-card-plus
      template: temperature_row
      variables:
        - entity: sensor.living_room_temperature
        - name: Living Room

As a picture element

In a Picture Elements card's elements: list, where style carries the positioning:

- type: picture-elements
  image: /local/floorplan.png
  elements:
    - type: custom:decluttering-card-plus
      template: room_marker
      variables:
        - light: light.living_room
      style:
        top: 32%
        left: 26%

See Cards, Badges, Rows and Elements for the detail of each.


Nesting

A template's content can itself contain custom:decluttering-card-plus cards, so templates can build on each other:

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

  room_pair:
    card:
      type: horizontal-stack
      cards:
        - type: custom:decluttering-card-plus
          template: room_light
          variables:
            - light: '[[light_a]]'
            - room: '[[room_a]]'
        - type: custom:decluttering-card-plus
          template: room_light
          variables:
            - light: '[[light_b]]'
            - room: '[[room_b]]'

Variables pass straight through — '[[light_a]]' is substituted in room_pair, and the result is handed to room_light as its light.

Using a template in a place it was not meant for

Nothing stops you putting a row template into a view as a card, or a card template into an Entities card. It will usually render, but it will not look right — rows expect the layout an Entities card gives them, cards expect to be cards. Match the content type to the place.


What the card does around your content

Instantiating a template is not just a copy-and-paste. The card wraps your content in Home Assistant's own machinery, so templated content behaves like content written inline:

  • visibility conditions work inside the template, and the wrapper collapses when the card hides — see Visibility.
  • Grid options are forwarded, so a card that asks for a particular width in a sections view still gets it — see Cards.
  • A card that hides itself leaves no gap in the layout.
  • Rebuilds are handled, so cards that ask to be recreated are.

Next

Variables — defaults, types, and the rules of substitution

Clone this wiki locally