šŸ“ 100% Templatable Lovelace Configurations

Post a screenshot from Dev tools ā†’ state for this sensor.

Here you go

Do you see anything after pressing a SAVE button?

do you mean on the edit UI screen? nope just this

Well, I am a bit happier.

type: vertical-stack
cards:
  - type: entities
    entities:
      - input_number.test_number
      - input_number.test_number_2
      - type: section
      - entity: sensor.test_ctc
        name: state
      - entity: sensor.test_ctc
        type: attribute
        attribute: days
        name: attribute
  - type: custom:config-template-card
    entities:
      - sensor.test_ctc
    variables:
      DAYS: states['sensor.test_ctc'].attributes['days'] + ' days'
    card:
      type: picture-entity
      entity: sensor.test_ctc
      name: ${DAYS}
      show_name: true
      show_state: false
      state_image:
        '0': /local/images/test/blue.jpg
        '1': /local/images/test/orange.jpg
        '2': /local/images/test/pink.jpg
template:
  - sensor:
      - name: test_ctc
        state: >-
          {{ states("input_number.test_number")|int(0) }}
        attributes:
          days: >-
            {{ states("input_number.test_number_2")|int(0) }}

Gotta be something with the installation then. Did you install it through hacs?

Hi all, probably doing something stupid here but I canā€™t figure it out. I want to detect the hass.user and then pass a url variable to an iframe card. My config below is not working. I have tried a few different configs but no success:

  - type: "custom:config-template-card"
    variables:
      biuser: |
        biuser => {
          if (hass.user.name == 'officedashboard') {
            return 'user=officepc'
          } else if (hass.user.name == 'Sebastian') {
            return 'user=Sebastian'
          } else {
            return 'user=ipad'
          }
        }
    entities:
      - hass.user.name
    card:
      type: iframe
      url: ${"http://192.168.20.100:81/ui3.htm?" + biuser + "&maximize=1"}

Solved with the below:

  - type: "custom:config-template-card"
    variables:
      biuser: |
        user.name == 'officedashboard' ? 'user=officepc : (user.name == 'Sebastian' ? 'user=sebastian' : ' ')
    entities:
      - user.name
    card:
      type: iframe
      url: ${"http://192.168.20.100:81/ui3.htm?" + biuser + "&maximize=1"}

Hello,

The code for the card is working, but i have a strange thing happening.

Whenever i change the message in the input helper, this card keeps sending previous message one more time, and after that it sends the new message.

When i check in develop tools, the status of the: input_txt.tss is giving the new message. But this card sends first the old message, and after that the second time, it sends the new message.

Someone any idea what this could be?

type: custom:config-template-card
variables:
  Message: states['input_text.tts'].state
entities:
  - media_player.junior
card:
  type: button
  show_name: true
  show_icon: false
  entity: media_player.junior
  name: TTS SEND
  tap_action:
    action: call-service
    service: tts.cloud_say
    target: {}
    data:
      message: ${Message}
      entity_id: media_player.junior

Why am entity which is used inside the CTC is not defined as ā€œmonitoredā€ inside the ā€œentitiesā€ option?

A note about using macros in config-template-card (CTC):

Consider this card:

type: config-template-card
entities:
  - sun.sun
  - sensor.some_sensor
card:
  type: ....
  ... something with sun.sun & sensor.some_sensor

All entities used in an ā€œinner cardā€ should be defined as ā€œmonitoredā€ in the ā€œentitiesā€ option - otherwise the ā€œinner cardā€ will be not updated when some of these entities are changed (unless a user have not defined them as ā€œmonitoredā€ by some purpose).

In HA 2023.4 a support for macros was added.
Consider this (useless) macro:

{% macro DO_SOMETHING(input_SENSOR) -%}
  {{ state_attr(input_SENSOR,'elevation') | float(default=0) + states('zone.home') | int(default=0) }}
{%- endmacro %}

The ā€œinner cardā€ uses this macro like:

DO_SOMETHING('sun.sun')

Here the macro uses the ā€œzone.homeā€ entity - and this entity is not defined as ā€œmonitoredā€.
Means - if the ā€œzone.homeā€ is changed, the ā€œinner cardā€ will be not updated.

Conclusion: when using macros inside CTC - check if any entities are used inside these macros; all (or some) of them should be defined as ā€œmonitoredā€.

Hiā€¦

Trivial question, I want to add this manually, but I canā€™t find ā€œconfig-template-card.jsā€ within the repository on git? ā€¦ Iā€™ve added quite a few custom Lovelace packages, all manually by copying the .jsā€¦ yet I canā€™t find config-template-card.js as per the readme / instructions?

yeeeaaā€¦ where did this come from? ā€¦ Iā€™m not keen to add a random .js from a random link, from a random guy :smiley:

but I appreciate you going to the effort of providing a link if itā€™s legit.

Thank you)

1 Like

Hello everyone I need help because I have a problem. Iā€™m trying to use a template to define the position of a button but I canā€™t get the code to work. Could anyone help me? Thank you.
The code is as follows:

    - type: custom:config-template-card
      entities:
        - light.board_01_rgb_01
      card:
        type: custom:button-card
        entity: light.board_01_rgb_01
        show_icon: true
        show_name: false
        show_state: false
        tap_action:
          haptic: selection
        action: toggle
        hold_action:
          action: more-info
      style:
        left: $"{ states['input_number.light_position_left_01_01'].state }%"
        top: $"{ states['input_number.light_position_top_01_01'].state }%"
        width: $"{ states['input_number.light_width_01_01'].state }%"
left: ${ states['input_number.light_position_left_01_01'].state }

But this is merely a correction of JS code; rest is yours.

I think I need to add the ā€˜%ā€™ symbol as well. How do you think I can add it correctly to the input number?

left: ${ states['input_number.light_position_left_01_01'].state + "%"}

Sorry, missed that that you are trying to place CTC in picture-entities.

1 Like

The code works perfectly. Thank you very much. :+1:

Or you may use card-mod:

  - type: picture-elements
    card_mod:
      style: |
        ha-card {
          --my-left: {{states('input_number.test_level_1')}}%;
          --my-top: {{states('input_number.test_level_2')}}%;
        }
    elements:
      - type: custom:button-card
        entity: sun.sun
        style:
          left: var(--my-left)
          top: var(--my-top)
    image: /local/images/test/orange.jpg

which removes one ā€œextra layerā€.