Need help with decluttering card (template)

Hi everybody,

UPDATE: I had missed the type in my template card. However, one thing I still don’t get: how can I (or, is it possible) to have as many entities as needed instead of “entity_1”, “entity_2”, etc.? Let’s say one room has 6 entities and another room has 53, what kind of template would I use that both rooms would be able to work with?

I am trying to get into decluttering-card to make configuring my lovelace ui a bit simpler. However, I don’t quite understand how to do this when there are multiple “sub cards” involved.

Here is an example for a regular card (left) which I’d like to translate to a decluttering template (right).

OLD Screenshot

NEW Screenshot

Manual Card

type: "vertical-stack"
cards:
  - type: "custom:button-card"
    color_type: label-card
    color: rgb(44, 109, 214)
    name: Schlafzimmer
  - type: "horizontal-stack"
    cards:
    - type: "custom:button-card"
      entity: light.sz_tv
      size: 20px
    - type: "custom:button-card"
      entity: light.sz_bett
      size: 20px
    - type: "custom:button-card"
      entity: light.schlafzimmer_innr_light
      size: 20px
    - type: "custom:button-card"
      entity: switch.schlafzimmer_deckenventilator
      name: Decke
      size: 20px
    - type: "custom:button-card"
      entity: switch.schlafzimmer_klimaanlage
      name: Klima
      size: 20px

Template (in ui-lovelace.yaml)

# Decluttering Templates
decluttering_templates:
  my_first_template:     # This is the name of a template
    default:
      - icon: fire
    card:
      type: custom:button-card
      name: '[[name]]'
      icon: 'mdi:[[icon]]'
  zimmer:
    card:
      type: "vertical-stack"
      cards:
        - type: "custom:button-card"
          color_type: label-card
          color: rgb(44, 109, 214)
          name: "[[zimmer]]"
        - type:
          cards:
            - type: "custom:button-card"
              entity: "[[entity]]"
              size: 20px

and finally

Decluttering Card

type: "custom:decluttering-card"
template: zimmer
variables: 
  - zimmer: Schlafzimmer
  - entity_1: light.sz_tv
  - entity_2: light.sz_bett

As you can see, it does take the first variable, zimmer; the header displays Schlafzimmer as intended. However, those other variables are not used by the card; I know that I must be doing something wrong, but don’t quite understand what it is, as I tried using this example.

Thank you for your ideas :slight_smile:

I don’t think that the decluttering card works like this. It will not autopopulate with as many entities as you want.
Your card can not work, in the decluttering template you have a variable “entity” and then in your card that uses the template you give the variables “entity_1” and “entity_2” but not “entity”, that’s why you get an error.
I think the idea you have will not work, because (I assume) that different rooms won’t have the same number of entities.

Your template would need to look something like this:

zimmer:
    card:
      type: "vertical-stack"
      cards:
        - type: "custom:button-card"
          color_type: label-card
          color: rgb(44, 109, 214)
          name: "[[zimmer]]"
        - type:
          cards:
            - type: "custom:button-card"
              entity: "[[entity_1]]"
              size: 20px
            - type: "custom:button-card"
              entity: "[[entity_2]]"
              size: 20px
            - type: "custom:button-card"
              entity: "[[entity_3]]"
              size: 20px
            - type: "custom:button-card"
              entity: "[[entity_4]]"
              size: 20px
            - type: "custom:button-card"
              entity: "[[entity_5]]"
              size: 20px

But this template will only work if the card you want to create has exactly 5 entities.

never tried it but… you could attempt to build a list.

variables:
  - zimmer: Schlafzimmer
  - entities:
    - light.sz_tv
    - light.sz_bett

problem beyond this would be programatically creating the cards placed into it. I’m not sure if the cards: fields can be templated.

It doesn’t seem to do well with lists…
When passing

- light_list:
      - light.can_ting_tong_deng
      - light.can_ting_deng

to it.
It would either break the template inside or just replace my [[light_list]] with [[Undefined]] :joy:
Is there any workaround?

Suggest to ask these question in the already present dedicated “decluttering-card” thread.
Also this.

Templates:

  decl_test_list_1:
    card:
      type: entities
      entities: '[[LIST]]'

  decl_test_list_2:
    default:
      - LIST:
          - entity: zone.home
            name: xxxxxxx
          - entity: sun.sun
            name: sssssss
    card:
      type: entities
      entities: '[[LIST]]'

Cards:

type: vertical-stack
cards:
  - type: custom:decluttering-card
    template: decl_test_list_1
    variables:
      - LIST:
          - sun.sun

  - type: custom:decluttering-card
    template: decl_test_list_1
    variables:
      - LIST:
          - entity: sun.sun
            name: yyyyyy

  - type: custom:decluttering-card
    template: decl_test_list_2

  - type: custom:decluttering-card
    template: decl_test_list_2
    variables:
      - LIST:
          - sun.sun
          - sun.sun
          - sun.sun

image

Thanks for the reply, didn’t know there was a dedicated thread😜
But I already found a workaround by passing a string then convert it back to list😂

@myhades
Please share how to do that🙏