Help with config-template-card need

Hi guys,

I would also need a bit of help with this card.
I intend to use it with the apexcharts card in the graph_span attribute. The thing is that this card is expecting something like 10d or 5h. But my variable is an input_number so it does not work (yet).
Any clue how to solve this?

  - type: 'custom:config-template-card'
    variables:
      NB_JOURS: 'states[''input_number.nb_jours_elec''].state'
    entities:
      - input_number.nb_jours_elec
    card:
      type: 'custom:apexcharts-card'
      graph_span: '${NB_JOURS}'
[...]

Hi,

I am using the custom:config-template-card for this card

type: entities
title: Status & Information
entities:
  - entity: vacuum.dreamed9
    name: Dreame D9
    icon: mdi:robot-vacuum
    tap_action: null
    action: more-info
  - type: custom:template-entity-row
    name: Water Container
    state: >-
      {% if  is_state_attr('vacuum.dreamed9', 'waterbox','removed')%} Removed {%
      else %} Present {% endif %}
    icon: mdi:watering-can
    entity: vacuum.dreamed9
    tap_action: none
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      entity: vacuum.dreamed9
      type: attribute
      name: Cleaned Area
      attribute: cleaning_area
      suffix: m²
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      icon: mdi:timer-outline
      entity: vacuum.dreamed9
      type: attribute
      name: Time
      attribute: cleaning_time
      suffix: m
  - entity: vacuum.dreamed9
    icon: mdi:ruler-square
    type: attribute
    name: Total Cleaned Area
    attribute: total_cleaning_area
    suffix: m²
    tap_action: none
  - type: custom:config-template-card
    variables:
      - states['vacuum.dreamed9']
    entities:
      - ${vars[0].entity_id}
    card:
      type: entities
      entities:
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: filter_life_percent
          icon: mdi:air-filter
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: main_brush_life_percent
          icon: mdi:car-defrost-front
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: >-
            ${ "Main Brush  -  " +  vars[0].attributes['main_brush_time_left']+"
            h"}
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: side_brush_life_percent
          icon: mdi:fan
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: >-
            ${ "Main Brush  -  " +  vars[0].attributes['side_brush_time_left']+"
            h"}

Is there any way I can extract/generalize this part

        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: filter_life_percent
          icon: mdi:air-filter
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}

So I don’t have to repeat myself and only have to call a kind of own template with two parameters for

attribute: filter_life_percent

and

name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}

so that it looks like something like that

type: entities
title: Status & Information
entities:
  - entity: vacuum.dreamed9
    name: Dreame D9
    icon: mdi:robot-vacuum
    tap_action: null
    action: more-info
  - type: custom:template-entity-row
    name: Water Container
    state: >-
      {% if  is_state_attr('vacuum.dreamed9', 'waterbox','removed')%} Removed {%
      else %} Present {% endif %}
    icon: mdi:watering-can
    entity: vacuum.dreamed9
    tap_action: none
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      entity: vacuum.dreamed9
      type: attribute
      name: Cleaned Area
      attribute: cleaning_area
      suffix: m²
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      icon: mdi:timer-outline
      entity: vacuum.dreamed9
      type: attribute
      name: Time
      attribute: cleaning_time
      suffix: m
  - entity: vacuum.dreamed9
    icon: mdi:ruler-square
    type: attribute
    name: Total Cleaned Area
    attribute: total_cleaning_area
    suffix: m²
    tap_action: none
  - type: custom:config-template-card
    variables:
      - states['vacuum.dreamed9']
    entities:
      - ${vars[0].entity_id}
    card:
      type: entities
      entities:
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: filter_life_percent
          icon: mdi:air-filter
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: main_brush_life_percent
          icon: mdi:car-defrost-front
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: >-
            ${ "Main Brush  -  " +  vars[0].attributes['main_brush_time_left']+"
            h"}
        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: side_brush_life_percent
          icon: mdi:fan
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: >-
            ${ "Main Brush  -  " +  vars[0].attributes['side_brush_time_left']+"
            h"}

Is there any way I can extract/generalize this part

        - type: custom:bar-card
          entity: vacuum.dreamed9
          attribute: <param1>
          icon: mdi:air-filter
          unit_of_measurement: ' %'
          width: 55%
          height: 2em
          decimal: 0
          positions:
            icon: outside
            indicator: 'off'
            name: outside
          severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
          name: ${ <label> + "  -  " +  <param2> +" h"}

Thank you!

Yes. You can use anchors but they need to be in the same file.

declaring it

        - entity: vacuum.dreamed9
          attribute: filter_life_percent
          <<: &my_bar_card
            type: custom:bar-card
            icon: mdi:air-filter
            unit_of_measurement: ' %'
            width: 55%
            height: 2em
            decimal: 0
            positions:
              icon: outside
              indicator: 'off'
              name: outside
            severity:
            - color: Red
              from: 0
              to: 25
            - color: Orange
              from: 26
              to: 50
            - color: Green
              from: 51
              to: 100
            name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}

using it later…

        - entity: vacuum.dreamed9
          attribute: main_brush_life_percent
          <<: *my_bar_card

Hi,

will try that!

and how can pass/define the value for name:

Thank you! :slight_smile:

You can’t pass values to anchors. You have to exclude the fields from the anchor and supply them separately, like I did in the example above.

Thank you! Will try that.

Hi @petro,

that worked perfectly! Thank you!

In any case someone wants know, here the reworked config of my card

type: entities
title: Status & Information
entities:
  - entity: vacuum.dreamed9
    name: Dreame D9
    icon: mdi:robot-vacuum
    tap_action: null
    action: more-info
  - type: custom:template-entity-row
    name: Water Container
    state: >-
      {% if  is_state_attr('vacuum.dreamed9', 'waterbox','removed')%} Removed {%
      else %} Present {% endif %}
    icon: mdi:watering-can
    entity: vacuum.dreamed9
    tap_action: none
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      entity: vacuum.dreamed9
      type: attribute
      name: Cleaned Area
      attribute: cleaning_area
      suffix: m²
  - type: conditional
    conditions:
      - entity: binary_sensor.d9_active
        state: 'on'
    tap_action: none
    row:
      icon: mdi:timer-outline
      entity: vacuum.dreamed9
      type: attribute
      name: Time
      attribute: cleaning_time
      suffix: m
  - entity: vacuum.dreamed9
    icon: mdi:ruler-square
    type: attribute
    name: Total Cleaned Area
    attribute: total_cleaning_area
    suffix: m²
    tap_action: none
  - type: custom:config-template-card
    variables:
      - states['vacuum.dreamed9']
    entities:
      - ${vars[0].entity_id}
    card:
      type: entities
      entities:
        - entity: vacuum.dreamed9
          attribute: filter_life_percent
          icon: mdi:air-filter
          name: ${ "Filter  -  " +  vars[0].attributes['filter_time_left']+" h"}
          <<: &my_bar_card
            type: custom:bar-card
            unit_of_measurement: ' %'
            width: 55%
            height: 2.1em
            decimal: 0
            positions:
              icon: outside
              indicator: 'off'
              name: outside
            severity:
              - color: Red
                from: 0
                to: 33
              - color: Orange
                from: 34
                to: 66
              - color: Green
                from: 67
                to: 100
        - entity: vacuum.dreamed9
          attribute: main_brush_life_percent
          icon: mdi:car-defrost-front
          name: >-
            ${ "Main Brush  -  " +  vars[0].attributes['main_brush_time_left']+"
            h"}
          <<: *my_bar_card
        - entity: vacuum.dreamed9
          attribute: side_brush_life_percent
          icon: mdi:fan
          name: >-
            ${ "Side Brush  -  " +  vars[0].attributes['side_brush_time_left']+"
            h"}
          <<: *my_bar_card