iantrich / config-template-card

πŸ“ Templatable Lovelace Configurations
MIT License
425 stars 55 forks source link

Secrets support #116

Closed alanmilinovic closed 1 year ago

alanmilinovic commented 1 year ago

Hi, is it possible to use secret. I tried following in my iframe card but it is not working:

type: custom:config-template-card
entities:
  - input_select.password
card:
  type: iframe
  style: |
    #root {
      height: calc(100vh - 48.5px);
      padding-top: 0 !important;
    }
  url: >-
    ${'http://'+window.location.hostname+':20530/sysmanager.php?username=amilino&password='+secret! password}

This is working alternative, but not what I wanted:

url: >-
    ${'http://'+window.location.hostname+':20530/sysmanager.php?username=amilino&password='+states['input_select.password'].state}
ildar170975 commented 1 year ago

In HA (not talking about config-template-card) secrets may be used only for defining a key:

value_template: !secret my_secret

but not inside templates:

value_template: >-
  {{ "some_value" + !secret my_secret}}

And the same (almost) is about config-template-card. Consider an example:

      - type: custom:config-template-card
        variables:
          ENTITY: states['input_boolean.test_boolean']
          TEXT: '''some text'''
        entities:
          - ${ENTITY.entity_id}
        card:
          type: entity
          entity: sun.sun
          name: ${"State is " + ENTITY.state + " (" + TEXT + ")"}

ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

Assume you need to keep "'some text" as a secret:

my_secret: "some_text"

and then trying to use it here:

      - type: custom:config-template-card
        variables:
          ENTITY: states['input_boolean.test_boolean']
        entities:
          - ${ENTITY.entity_id}
        card:
          type: entity
          entity: sun.sun
          name: ${"State is " + ENTITY.state + " (" + !secret my_secret + ")"}

which will not work.

Then - following the logic described above - you decide to use the secret to define a variable:

      - type: custom:config-template-card
        variables:
          ENTITY: states['input_boolean.test_boolean']
          TEXT: !secret my_secret
        entities:
          - ${ENTITY.entity_id}
        card:
          type: entity
          entity: sun.sun
          name: ${"State is " + ENTITY.state + " (" + TEXT + ")"}

and again it will not work. This is all about defining string variables in the card - you have to specify a string variable as:

TEXT: '''some text'''

or

TEXT: >-
  'some text'

and NOT as it usually works in other places in HA:

TEXT: some text

or

TEXT: "some text"

I call it "inconsistency".

Unfortunately, the card seems to be abandoned.

alanmilinovic commented 1 year ago

Thank you for your reply, but I lost you somewhere in the middle. :)

I stayed with using alternative solution in the end with input.select and used secret there.

input_select:
  password:
    name: Password
    options:
      - !secret password
    icon: mdi:account-key
alanmilinovic commented 1 year ago

Is there any alternative that replaces this card as it is abandoned?

ildar170975 commented 1 year ago
  1. The card still may be used for some cases. I am still using it. Yes, there are issues which are not even reviewed by the card's author during a very long time - that is why I am saying that the card is abandoned.

  2. As for alternatives - it depends on what you need. Some results may be achieved by other custom cards like template-entity-row, some by using template sensors, some - by using templates with card-mod. In you particular case I suggest you to use a template sensor for the url option.

ildar170975 commented 1 year ago

but I lost you somewhere in the middle. :)

no problem)

alanmilinovic commented 1 year ago

Isn't it too much to use template sensor for a static value? I am trying to avoid filling database with history records.

ildar170975 commented 1 year ago

DB is filled mainly by CHANGING values.