šŸ“ 100% Templatable Lovelace Configurations

Wonder if your states[ā€˜sensor.bom_hobart_wind_gust_ktā€™].state is returning numbers. My coloring-changing temperature template uses parseInt() or parseFloat() for numeric conditions, maybe try

parseInt(vars[0]) <= 10

Solution (thanks to Thomas Loven):

- type: 'custom:config-template-card'
  entities: sensor.bom_hobart_wind_gust_kt
  variables:
    - states['sensor.bom_hobart_wind_gust_kt'].state
  card:
    type: 'custom:hui-picture-entity-card'
    entity: sensor.bom_hobart_wind_direction
    show_name: false
    show_state: false
    state_image:
      CALM: /local/icons/wind/CALM.png 
      E: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'E-blu.png' : vars[0] <= 20 ? 'E-grn.png' : vars[0] <= 30 ? 'E-yel.png' : 'E-red.png' ) }"
      ENE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'ENE-blu.png' : vars[0] <= 20 ? 'ENE-grn.png' : vars[0] <= 30 ? 'ENE-yel.png' : 'ENE-red.png' ) }"
      ESE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'ESE-blu.png' : vars[0] <= 20 ? 'ESE-grn.png' : vars[0] <= 30 ? 'ESE-yel.png' : 'ESE-red.png' ) }"
      'N': "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'N-blu.png' : vars[0] <= 20 ? 'N-grn.png' : vars[0] <= 30 ? 'N-yel.png' : 'N-red.png' ) }"
      NE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'NE-blu.png' : vars[0] <= 20 ? 'NE-grn.png' : vars[0] <= 30 ? 'NE-yel.png' : 'NE-red.png' ) }"
      NNE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'NNE-blu.png' : vars[0] <= 20 ? 'NNE-grn.png' : vars[0] <= 30 ? 'NNE-yel.png' : 'NNE-red.png' ) }"
      NNW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'NNW-blu.png' : vars[0] <= 20 ? 'NNW-grn.png' : vars[0] <= 30 ? 'NNW-yel.png' : 'NNW-red.png' ) }"
      NW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'NW-blu.png' : vars[0] <= 20 ? 'NW-grn.png' : vars[0] <= 30 ? 'NW-yel.png' : 'NW-red.png' ) }"
      S: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'S-blu.png' : vars[0] <= 20 ? 'S-grn.png' : vars[0] <= 30 ? 'S-yel.png' : 'S-red.png' ) }"
      SE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'SE-blu.png' : vars[0] <= 20 ? 'SE-grn.png' : vars[0] <= 30 ? 'SE-yel.png' : 'SE-red.png' ) }"
      SSE: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'SSE-blu.png' : vars[0] <= 20 ? 'SSE-grn.png' : vars[0] <= 30 ? 'SSE-yel.png' : 'SSE-red.png' ) }"
      SSW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'SSW-blu.png' : vars[0] <= 20 ? 'SSW-grn.png' : vars[0] <= 30 ? 'SSW-yel.png' : 'SSW-red.png' ) }"
      SW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'SW-blu.png' : vars[0] <= 20 ? 'SW-grn.png' : vars[0] <= 30 ? 'SW-yel.png' : 'SW-red.png' ) }"
      W: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'W-blu.png' : vars[0] <= 20 ? 'W-grn.png' : vars[0] <= 30 ? 'W-yel.png' : 'W-red.png' ) }"
      WNW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'WNW-blu.png' : vars[0] <= 20 ? 'WNW-grn.png' : vars[0] <= 30 ? 'WNW-yel.png' : 'WNw-red.png' ) }"
      WSW: "${'/local/icons/wind/' + ( vars[0] <= 10 ? 'WSW-blu.png ': vars[0] <= 20 ? 'WSW-grn.png' : vars[0] <= 30 ? 'WSW-yel.png' : 'WSw-red.png' ) }"

You canā€™t chain m < x < n comparisons like I did.

Grab the file from the release or use HACS

1 Like

Hey Ian, This appears to be stopping firefox from responding (Chrome seems to ignore it):

Not sure if itā€™s my config (which seems to be working) or the card.

I opened an issue.

Davidā€™s ā€˜minutes agoā€™ conversion is a good start, but has anyone come up with a good way of converting attr last_changed to relative time?

image

Hey @tom_l
Would you mind sharing the outcome of that?
I am curious to see what it does :slight_smile:

Thanks

More here: Yet another wind compass - with wind speed indication

4 Likes

Hi @iantrich, itā€™s a great component you created! I used it already once and it works great. I want to use it again to display a card to control the fan speed, which is an attribute of a fan.
What is the syntax to follow to access the attribute please? This does not work obviously as I want to control the value, not just know the current state.

Thereā€™s an example in the docs

Hi @iantrich, I am sorry, but I have double read the docs and I canā€™t find the answer. Are you talking about the doc under this link? https://github.com/iantrich/config-template-card

name: "${states['climate.ecobee'].attributes.current_temperature > 22 ? 'Cozy' : 'Too Hot/Cold'}"
This is not Jinja. Checkout templater-card if you want to use jinja

What do you mean by This is not Jinja?
The example you gave is to check the value of an attribute but not to control it, isnā€™t it?

Service calls are used to control entities. You donā€™t need this card to do that, you just need to figure out the correct service call for your fan.

1 Like

Ok thank you.

@iantrich

I have a few questions regarding this card:

  1. I have read on your repo (at the issues) that the card polls constantly if nothing is filled. Is this still the case? I use input text a lot with your card, but I wonder if that counts as ā€œhaving something filled inā€ or if it will keep polling regardless.

  2. If I wrap your card around an auto-entities card that has a button-card in it, the states of the button no longer updates unless I refresh, is there something I can do about it?

  3. The same is true for example dbuits popup card, it will take the config nicely, but the popup is unresponsive when this card is wrapped around it

Thanks for this amazing card btw!

  1. I assume you mean the entities option? Then yes and always will be. It needs to know what entities to watch so it is not updating on every state change in the HA.
  2. I donā€™t really test things that deep or with custom cards, only core, so couldnā€™t say where the bottleneck is.
  3. Same as above
1 Like

I think I figured out question 2. The reason I ask is because I get tons of ā€œmax pending messagesā€ errors and I saw somewhere this card had a relation with it. I need to debug when I have a pc around.

Though I do have another question. What is the difference between entities and variables? To me it looks the same, either it monitors the entity or it monitors the state. Not exactly sure how that works. Been reading through your documentation over and over but to me it seems both methods results are the same. I know I am terribly wrong here that is why I ask.

Thanks for replying

variables are just handy additions to make it easier to create templates. entities is a list of entities that, when their state changes, cause the card to update.

a lot of ā€œmax pending messagesā€ sounds like youā€™re using a jinja2 template somewhere that is being re-evaluated far too often

Hello @iantrich,

Iā€™m trying to get a png overlay opacity dynamically changing while the outside brightness changes (in a picture-elements card). I ended up with this:

    cards:
      - type: "custom:config-template-card"
        entities:
          - sensor.brightness_opacity
        # variables:
        #   - states['sensor.brightness_opacity'].state
        card:
          - type: "custom:hui-picture-elements-card"
            image: /local/plan/0_n_no.png?v=2
            elements:
                  - entity: sun.sun
                    hold_action:
                      action: none
                    state_image:
                      above_horizon: /local/plan/0_g_no.png?v=2
                      below_horizon: /local/plan/alphamini.png
                    style:
                      height: 100%
                      left: 50%
                      mix-blend-mode: lighten
                      opacity: >-
                        ${ states['sensor.brightness_opacity'].state }
                      top: 50%
                      width: 100%
                    tap_action:
                      action: none
                    type: image
                  - entity: media_player.samsungtv_tizen
[...]

I checked it and read all the paper a lot of times but I canā€™t figure out why I get

No card type defined

error in Lovelace.

Funny thing is if I comment out the config-template-card bit of code all works, all but the dynamic opacity indeed.

Please help me figure this out.
Thank you,
R.

I presume because itā€™s

so you donā€™t need a list here

you need just one card. remove the dash :wink: