iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
449 stars 59 forks source link

How to concatenate 2 vars #10

Closed snakuzzo closed 5 years ago

snakuzzo commented 5 years ago

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

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

iantrich commented 5 years ago

I'm guessing you want the friendly name. You should try the following:

'states["cover.matrimoniale"].attributes.friendly_name'
snakuzzo commented 5 years ago

I tried with friendly_name and name...same result If I join name and percentage number, the name is showed as undefined

iantrich commented 5 years ago

attributes is the key thing

snakuzzo commented 5 years ago

Thank you! This solved first problem. Now I can see friendly_name and percentage.

This is new code...

variables:
  - 'states["cover.matrimoniale"].attributes.friendly_name'
  - 'states["input_number.posizione_tapparella_camera"].state'
type: 'custom:config-template-card'
card:
  type: '${''custom:hui-entities-card''}'
  entities:
    - entity: cover.matrimoniale
      name: '${vars[0] + " (" + vars[1] + " %)"}'
entities:
  - input_number.posizione_tapparella_camera
  - cover.matrimoniale

image

Second problem... is it possible to cast percentage number as integer ???