📝 100% Templatable Lovelace Configurations

Man you are a sniper, thank you!

1 Like

Should this work with the UI editor and a manual card?

The editor keeps on completely screwing the YAML up when it loads the card for editing.

[edit]

Is there a list of hui_ cards to use anywhere?

Yes it should work, the UI editor might look it look “weird” but it should work

I should probably update to use the new helpers so you don’t have to use the hui_

This is the view I see when I try to re-edit a component that sort of worked last night. (no idea why it doesn’t like the card name today).

It has reordered everything and added in extraneous single quotes.

The >- already says it is a string, so you can remove your leading/trailing double quotes I think

What is the right card name?

So, just before saving I have

Save and reopen

image

Note the extra quotes in the variable.

Apparently past-Ian might have already fixed this; don’t actually remember.

Can you try type: markdown

1 Like

Yes that works - thanks @iantrich.

This is the card, once the card has been created, saved and then opened again. Note the extra single quotes that have been added.

This does’t quite do what I want, but is a good example that anyone can try (which was what I was looking for).

type: 'custom:config-template-card'
entities: weather.home
variables:
  - 'states[''weather.home''].attributes[''forecast'']'
card:
  content: >-
    ${function forecast(item){var options={ weekday:'long'}; var day = '**' +
    new Date(item.datetime).toLocaleDateString('en-GB', options) + '**';
    if(!item.daytime){var day = day + ' **Night**';} return  day + '<br/>' +
    item.temperature;} var text=''; for(var i=0; i<5; i++){var
    text=text+forecast(vars[0][i]) + '<br/>';} text}
  title: Weather Forecast
  type: markdown
1 Like

Try double quotes on the variable
- "states['weather.home'].attributes['forecast']"

Nope on re-editing it it just goes back to

'states[''weather.home''].attributes[''forecast'']'

It works, just isn’t consistent :upside_down_face:

If you scroll way up in this thread, I have a very similar example, although this may be what you used. But now I use the built-in markdown card like this. It allowed me to drop this custom card from my config. No offense intended, it is great, I just don’t want to use custom stuff if I can get the same result with the built in cards.

 - type: markdown
   content: |-
     # Weather Forecast
     {% for s in state_attr('weather.home', 'forecast'\
)[:4] %}
     **{{strptime(s.datetime[:10], '%Y-%m-%d').strftim\
e('%A')}}** {% if not s.daytime %}**Night**{%  endif %}
     {{s.detailed_description}}
     {% endfor %}

Yes it was :grinning:. My weather was slightly different and it didn’t like the card name. I was just trying to understand where the extra quotes came from and if that was a bug.

I’ve never used the visual editor, which is most likely causing the issues. Not sure.

1 Like

Hi @iantrich - your card has been great to solve the problem of the webpage(iframe) card not being able to show new content due to browser caching - without having to hit CTRL-F5. This custom card updates the URL with a version incorporating a unique timestamp, thus forcing the browser to refresh automatically.

However, I have run into a really weird problem. For some reason, I have to include a “stock” webpage/iframe card in addition to the separate config-template-card to make it work. If I remove the webpage card (which I don’t need), the config-template-card fails with : Custom element doesn’t exist: hui-iframe-card.

      - card:
          type: 'custom:hui-iframe-card'
          url: >-
            ${'https://myhassio.duckdns.org:8123/local/recordings/doorbell.mp4?v='+states['input_text.mp4_timestamp'].state}
        entities:
          - input_text.mp4_timestamp
        type: 'custom:config-template-card'


If I just add a dummy webpage card, even the demo example, it will work! Refreshing the page, Ctrl-F5, nothing else works that I have found, other than to include an extra webpage card I don’t want.

      - type: iframe
        url: 'https://www.home-assistant.io'
        aspect_ratio: 50%

EDIT: Just now discovered that the exact same issue occurs with the hui-picture-elements-card.

try just type: iframe in my card

1 Like

Sweet! That fixed it! for both iframe & picture-elements modded by this card.

Thought the custom:hui-*-card prefix/suffix was required, but very happy to see it working now without it, and without the dummy extra cards.

I updated it awhile back to not require the custom prefix but forgot to update the readme

Is there a list of the right card names anywhere @iantrich?

Oh! OK, thanks for clearing that up @iantrich. I also had read in a post from 5 days ago that the same issue was raised for custom:hui-markdown-card that you had replied to just try “markdown”. It wasn’t clear then why that was suggested.

At first, I thought my issue was only with iframe, but now I understand that the removal of the custom prefix/suffix applies to ANY card. While this is a welcome change to simplify the configuration, it can be a breaking change if no other matching card by the “normal” name isn’t already loaded.

1 Like