How to concatenate strings with variables in config-template-card template

Dear All,
I have a working template card like this:

  - type: 'custom:config-template-card'
    variables:
      number: states['sensor.vpnclients'].state
      timeStamp: states['sensor.vpnclients'].attributes.lastUpdated
      titlePrefix: '''Connected clients at '''
    entities:
      - sensor.vpnclients
    card:
      type: custom:list-card
      entity: sensor.vpnclients
      title: "${ vars['timeStamp'] }"
      feed_attribute: clients
      columns:
        - title: Name
          field: field1
        - title: Virtual IP
          field: field3
          style:
            - text-align: center
        - title: Remote IP
          field: field2
          style:
            - text-align: center
        - title: Bytes received
          field: field4
          style:
            - text-align: center
        - title: Bytes sent
          field: field5
          style:
            - text-align: center
        - title: Connected since
          field: field6
          style:
            - text-align: center

I would like to change the title of the card to display something like this:

Connected clients at 12:34

What is the correct way to achieve this? I tried this:

title: "${ vars['titlePrefix'] vars['timeStamp'] }"

and this:

title: "Connected clients at ${ vars['timeStamp'] }"

but it is sooo bad, that the card stopped rendering altogether…

Any pointers are much appreciated!

I think you will find your answer here:

1 Like

Thank you, it worked like this:

  - type: 'custom:config-template-card'
    variables:
      - '''Connected clients as of '''
      - states['sensor.vpnclients'].attributes.lastUpdated
    entities:
      - sensor.vpnclients
    card:
      type: custom:list-card
      entity: sensor.vpnclients
      title: '${vars[0] + vars[1]}'
      feed_attribute: clients
      columns:

What I don’t understand is why it doesn’t work like this too:

  - type: 'custom:config-template-card'
    variables:
      prefix: '''Connected clients as of '''
      timeStamp:  states['sensor.vpnclients'].attributes.lastUpdated
    entities:
      - sensor.vpnclients
    card:
      type: custom:list-card
      entity: sensor.vpnclients
      title: '${vars[prefix] + vars[timeStamp]}'
      feed_attribute: clients
      columns:

Thank you for the tip!

1 Like

Hi

Came across this when looking for a way to join two states together to overcome the 255 character limit.
Read your question on why it wasn’t working and I think this is why;

The working one

 '${vars[0] + vars[1]}'

stores the variables as (likely a string data type) and adding them together isn’t an issue.

but the second one is attempting to add a string to a datetime object. I’d guess that if anyone else has this issue, you could try forcing the datetime object to be typecast into a string.

Best of luck tho - sorry for reviving such an old thread!

1 Like

It worked for me using:

 ${[prefix] + [timeStamp]}
3 Likes