Templates dont work after update

I have updated Hassio from v0.86 to v0.93.2 after a SD crash!

After this my templates in Customize.yaml dont work anymore. I have templates for changing icons and colors depending on state… I have tried hs_color instead of icon_color with no luck.

Changing icon depending on state dont work either.

Dont really know what to do? Any help is appreciated…

    icon: 'if (state === ''on'') return ''mdi:server-network''; return ''mdi:server-network-off'';

    icon_color: 'if (state === ''on'') return ''rgb(59, 169, 31)''; return ''rgb(119,
      119, 119)'';

Did you install customUI? Those templates require a custom component called CustomUI. Also, note that customUI doesn’t always play well with the new interface (Lovelace).

Well, I have not made any new installation of customUI. Only copied my backuped folder of what I managed to save… But all seems to be there, I have the customUI folder with the state cards.

Also in the configuration.yaml I have

    - /local/custom_ui/state-card-custom-ui.html
    - /local/custom_ui/state-card-custom-ui-es5.html

That should be it?

Anyway, is there any other way to change icon and icon color depending on states in the new releases? Or is customUI still the way to go?

Ok, I now updated the customUI.

Still dont work.

I’ve never used custom UI so I cant speak for that. I only know about it. Personally I think lovelace is much easier. It’s a different way of doing things though. Changing the icon / icon color depends on the card you use.

If you don’t want to use lovelace and you want to go back to your old interface, switch back to the old interface. Don’t remember where that swap is. @Mariusthvdb has alot of experience with this, he may be able to help.

Give me a hint on how to do it with Lovelace please.

It depends on the card. I have no idea what your interface looks like so I can’t really suggest an equivalent.

your using incorrect double single quotes, don’t know where they come from… :wink:
using multiline notation helps getting rid of quoting issues.
Provided you have installed and activated custom-ui correctly this should work, both regular (legacy) HA and Lovelace.


    icon: >
      if (state === 'on') return 'mdi:server-network';
      return 'mdi:server-network-off';
    icon_color: >
      if (state === 'on') return 'rgb(59, 169, 31)';
      return 'rgb(119,119, 119)';

Double single quotes are fine FWIW… it’s just a valid way of escaping a single quote.

well, I have never seen it work in HA custom-ui, and each time people post templates or yaml with double single quotes they have issues…

either use single or double quotes when needing to escape single quotes seems the prescribed way, (there’s a doc somewhere online but can’t find it this quickly)

the customization I posted is correct, (others can be too, but this is what I use all through the setups) so hope helps the OP

The strange thing is that the template editor doesn’t like them but I have a bunch of automations and they work perfectly well. I did recently change to using double quotes outside and single quotes inside but double single quotes inside when you use single quotes outside work.

yes, I see. Ive long ago started using multiline wherever possible, to prevent issues, and, tbh, have the template look nice in 1 view in the editor. This is the link I referred to above: https://developers.home-assistant.io/docs/en/documentation_standards.html#single-vs-double-quotation-marks

only double quotes I use are where json requires them, and where I need to using special characters in eg a name or friendly name…

all that being said, I hope OP has got this to work, or it might be something else than the template format he’s got to change, and check custom-ui setup itself.


Single Quotes Outside, Double Quotes Inside (Invalid)

I’m going to call bullshit on that… I have automations with that

Oh… I also like the multi line templates. You’re right - much easier to read.

Actually, also… the multi-line example there is invalid I believe… ‘Dale’s room’ is not going to work!

single quote escaping is a part of yaml. it should work regardless of the template style.

EDIT: I do have to clarify that quotes will matter in the template language. So while escaping the characters in yaml may work, it may not work when handing over to the template langauge. It should always work with jinja. Not so sure about JS though, which is the language used for customUI’s templates.