viktak
(viktak)
March 30, 2022, 1:54pm
1
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!
browetd
(Browet Didier)
March 30, 2022, 2:34pm
2
I think you will find your answer here:
opened 10:07PM - 17 Apr 19 UTC
closed 12:01AM - 19 Apr 19 UTC
I'm trying to create a custom card for my blinds.
I need to view entity name as… "friendly_name (percentage %)".
(I'm getting % number from another entity)
This is my card
```
entities:
- input_number.posizione_tapparella_camera
- cover.matrimoniale
variables:
- 'states["cover.matrimoniale"].name'
- 'states["input_number.posizione_tapparella_camera"].state'
card:
entities:
- name: '${vars[0] + " (" + vars[1] + " %)"}'
entity: cover.matrimoniale
type: '${''custom:hui-entities-card''}'
type: 'custom:config-template-card'
```
But this is the result
![image](https://user-images.githubusercontent.com/7205371/56323965-c838b580-616d-11e9-97cb-5f61286dac71.png)
How can I solve this ?
If I use this template for entity name it shows the correct name
` - name: '${vars[0]}'`
Another question...
How can I cast % value as integer ?
{vars[1] | int} not works
1 Like
viktak
(viktak)
March 30, 2022, 3:06pm
3
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]}
2 Likes