Decluttering Card Plus Contents ↓ GitHub ↗

Repeating Sections and Badges (v1.11.0+)

for_each repeats a template inside one card, and one card only ever fills the slot it was given. A repeat over the rooms of the house therefore lands in a single section: it never reflows on a narrow screen, and the rooms cannot have a heading or a background of their own.

The card can also write a whole view. Give a view a strategy of custom:decluttering-card-plus and its sections: and badges: can repeat: one section, or one badge, per item. Home Assistant then lays the view out like any other sections view.

views:
  - title: Rooms
    path: rooms
    strategy:
      type: custom:decluttering-card-plus
      max_columns: 3
      badges:
        - for_each_from: { domain: light }
          badge:
            type: entity
            entity: '[[entity]]'
            show_name: true
      sections:
        - for_each_from: { areas: true }
          section:
            type: grid
            background: true
            cards:
              - type: heading
                heading: '[[area]]'
              - type: custom:decluttering-card-plus
                template: room_entities

with a template that tiles whatever the area holds:

decluttering_templates:
  room_entities:
    card:
      type: custom:decluttering-card-plus
      template: entity_tile
      for_each_from:
        area: '[[area_id]]'
  entity_tile:
    card:
      type: tile
      entity: '[[entity]]'

One section per area, each with its own heading and background, and a badge per light

A section per area and a badge per light, from one view definition.

On a phone the same view drops to a single column, which a repeat inside one card cannot do:

The same view on a phone, one section under another


How an entry repeats

Each entry of sections: or badges: is either a section or badge as you would normally write it, or a repeat:

Key Description
for_each A written-out list. Each item is that copy’s values, exactly as in Repeating a Template
for_each_from What Home Assistant knows: entities, areas, devices, floors, labels, with every filter, sort, limit and group_by the card’s own repeat takes. See Repeating over what Home Assistant knows
section / badge What each copy is, with [[placeholders]] filled from that copy’s values
variables Values every copy of this entry gets. A copy’s own values win
empty A section or badge to show instead when the repeat matches nothing

An entry without for_each or for_each_from goes through exactly as written, so ordinary sections and badges sit among the repeated ones in the order you list them.

Every copy also gets index, index0, count, first and last, so '[[area]] ([[index]] of [[count]])' works as a heading.

Values handed to templated cards

A custom:decluttering-card-plus card inside a repeated section is handed that copy’s values, after its own. In the example, room_entities uses [[area_id]] without the card passing it: the area being repeated over supplies it. Anything the card sets in its own variables still wins.

The health panel counts those values as set, so it does not report them as missing.

Values for the whole view

variables: at the top of the strategy go to every repeated entry, underneath each entry’s own. decluttering_defaults works too, written inside the strategy:

strategy:
  type: custom:decluttering-card-plus
  decluttering_defaults:
    colour: amber
  sections: ...

Everything else is the view’s

Any other key in the strategy (max_columns, dense_section_placement, background, top_margin) is passed through to the view. Asking for sections: makes it a sections view unless the strategy says otherwise.


Keeping up to date

The view is written out again when Home Assistant’s entity, device, area or floor registry changes. An area added in Settings appears as a new section within a couple of seconds, without a reload.

Like the card’s own repeat, it does not follow live state. A section per light that is currently on is not something this does. See Where this card is going.


Editing a generated view

Home Assistant shows a generated view in edit mode, but the sections and badges in it are not individually editable. The + in a generated section does nothing. Edit the view itself: the pencil beside the view’s name, then ⋮ → Edit in YAML.

From a card that already repeats

A card repeating inside a section can be converted from its editor with Give each copy its own section. It moves the view into the strategy for you: the card’s section is repeated once per copy, and everything else in the view goes along unchanged. Home Assistant’s undo button reverts it.


When to use which

You want Use
Copies side by side inside one card or section for_each on the card, with min_column_width so it narrows on a phone
A heading, a background or a reflowing block per copy A repeated section, here
A badge per person, per light, per anything A repeated badge, here. A badge template on its own cannot repeat

Next

→ Repeating a Template · Visual Editors → Configuration Reference