Decluttering Card Plus Contents ↓ GitHub ↗

Elements

An element template holds a single element of a Picture Elements card — an icon, a state icon, a state label, an image, a button and so on.

This is the one that saves the most typing, because floorplans repeat the same marker over and over with nothing different but the entity and the coordinates.

decluttering_templates:
  room_marker:
    element:
      type: state-icon
      entity: '[[light]]'
      tap_action:
        action: toggle
      style:
        '--paper-item-icon-color': white
        background-color: rgba(30, 41, 59, 0.75)
        border-radius: 50%
        padding: 6px

Use it in a Picture Elements card’s elements: list. Positioning goes on the instance, in its own style: mapping:

- type: picture-elements
  image: /local/floorplan.svg
  elements:
    - type: custom:decluttering-card-plus
      template: room_marker
      variables:
        - light: light.living_room
      style:
        top: 32%
        left: 26%
    - type: custom:decluttering-card-plus
      template: room_marker
      variables:
        - light: light.kitchen
      style:
        top: 32%
        left: 72%
    - type: custom:decluttering-card-plus
      template: room_marker
      variables:
        - light: light.bedroom
      style:
        top: 84%
        left: 26%
    - type: custom:decluttering-card-plus
      template: room_marker
      variables:
        - light: light.hallway
      style:
        top: 84%
        left: 72%

A floorplan with four templated state-icon markers, two lit and two off

Four markers, one appearance to maintain. The icons pick up their on/off colours from the entity, and tapping one toggles the light.


style means two different things here

This is the one genuinely confusing corner of the card, because Picture Elements uses style for positioning while this card uses style for CSS injection.

Where Type What it does
style: on the instance, inside elements: mapping Positioning. Consumed by the Picture Elements card — top, left, transform, and so on.
style: inside the template’s element: mapping Appearance of the element itself, applied on top of the positioning.
style: on the template, next to element: string CSS injection — see Styling.

In practice: put the look in the template, the coordinates on each instance.

decluttering_templates:
  room_marker:
    element:
      type: state-icon
      entity: '[[light]]'
      style:                     # <- appearance, a mapping
        border-radius: 50%
        padding: 6px
    style: |                     # <- CSS injection, a string
      :host { --mdc-icon-size: 28px; }

Centring on a point

Picture Elements positions by the element’s top-left corner. To centre it on the coordinates instead, add a transform — and make it part of the template so every marker gets it:

decluttering_templates:
  room_marker:
    element:
      type: state-icon
      entity: '[[light]]'
      style:
        transform: translate(-50%, -50%)
        border-radius: 50%

Element types

element: accepts any Picture Elements element:

decluttering_templates:
  temp_label:
    element:
      type: state-label
      entity: '[[entity]]'
      prefix: '[[prefix]]'
    default:
      - prefix: ''

  room_button:
    element:
      type: icon
      icon: '[[icon]]'
      title: '[[title]]'
      tap_action:
        action: navigate
        navigation_path: '[[path]]'

On the floorplan, two labels and two buttons from those:

- type: picture-elements
  image: /local/floorplan.svg
  elements:
    - type: custom:decluttering-card-plus
      template: temp_label
      variables:
        - entity: sensor.living_room_temperature
      style:
        top: 40%
        left: 26%
    - type: custom:decluttering-card-plus
      template: temp_label
      variables:
        - entity: sensor.kitchen_temperature
        - prefix: 'Kitchen '
      style:
        top: 40%
        left: 72%
    - type: custom:decluttering-card-plus
      template: room_button
      variables:
        - icon: mdi:bed
        - title: Bedroom
        - path: /lovelace/bedroom
      style:
        top: 80%
        left: 26%
    - type: custom:decluttering-card-plus
      template: room_button
      variables:
        - icon: mdi:coat-rack
        - title: Hallway
        - path: /lovelace/hallway
      style:
        top: 80%
        left: 72%

A floorplan with a temperature label in the living room and the kitchen, and an icon in the bedroom and the hallway

The kitchen label has a prefix; the living room one takes the empty default.

An element template, or repeat: inside one card

An element template is for a marker reused on different pictures, or placed by hand at its own coordinates, as above. When one card carries many of the same marker, a floorplan with an icon per light, one entry can repeat instead, with the coordinates in each item. A card template with '[[marker|repeat:lights]]' in its elements: list does the same from inside the template; see List Entries. The rule of thumb is the same as for rows: a template per element when the element is reused or hand-placed, a repeat when one card lists many of the same thing.

In other cards’ elements: lists

An element template is not limited to Picture Elements. Any card that draws its overlay with Home Assistant’s own picture-elements code will accept it, because that code accepts any custom: element. Advanced Camera Card is one, including inside its custom:advanced-camera-card-conditional:

type: custom:advanced-camera-card
cameras:
  - camera_entity: camera.kitchen
elements:
  - type: custom:advanced-camera-card-conditional
    conditions:
      - condition: view
        views: [live]
    elements:
      - type: custom:decluttering-card-plus
        template: ptz_button
        variables:
          - camera: camera.kitchen
          - movement: up
        style:
          right: 25px
          bottom: 50px

Positioning still goes on the instance’s style:, just as it does in a Picture Elements card.

One entry can stand for several elements (v2.9.0+): see One entry, many elements. To hand a card a whole list that changes from one dashboard to the next, put the card in a card template and pass the list in as a variable. A placeholder that is the entire value is replaced with the list itself:

decluttering_templates:
  camera_view:
    card:
      type: custom:advanced-camera-card
      cameras: '[[cameras]]'
      elements: '[[elements]]'

One entry, many elements (v2.9.0+)

An element template can repeat. One entry with for_each or for_each_from becomes an element per item, so a floor plan gets an icon per light from one entry. Each element is placed by its own values, so put the position in the template’s style: and give each item its own:

decluttering_templates:
  light_marker:
    element:
      type: state-icon
      entity: '[[entity]]'
      tap_action:
        action: toggle
      style:
        left: '[[x]]%'
        top: '[[y]]%'
type: picture-elements
image: /local/floorplan.svg
elements:
  - type: custom:decluttering-card-plus
    template: light_marker
    for_each:
      - entity: light.kitchen
        x: 73
        y: 36
      - entity: light.bedroom
        x: 26
        y: 80

See Repeating a Template for the options a repeat takes, and the picture this builds.


Reference

The keys this page uses, and the common ones beside them.

Key Where Type Description
element: template mapping The element configuration, with [[variables]]
default: template list or mapping Fallback variable values
style: template string CSS to inject
on_error: (v2.0.0+) template or instance hide or mapping An element to show, or hide, when building fails — see Using Templates
template: instance string Name of the template
variables: instance list or mapping Values to substitute
style: instance mapping Position within the Picture Elements card, or any card that uses its elements
element: (v1.12.0+) instance mapping Laid over what the template builds, as written — see Using Templates
for_each:, for_each_from: (v2.9.0+) instance list or mapping An element per item; see One entry, many elements

Every key, with an example of each, is in the Configuration Reference.


→ Cards · Badges · Rows