Lovelace: View icon template not possible?

HI,

in regular HA i use custom-ui to change my menu/view icons like this:

customize:

group.personal:
  templates:
    icon: >
      if (entities['sensor.family_home'].state === '0') return 'mdi:account-off';
      if (entities['sensor.family_home'].state === '1') return 'mdi:account';
      if (entities['sensor.family_home'].state === '2') return 'mdi:account-multiple';
      if (entities['sensor.family_home'].state === '3') return 'mdi:account-multiple-check';
      return 'mdi:account-group';

41
3d icon.

this doesn’t work in Lovelace, and the title is showing:
03

I’ve tried to use the custom-ui template, but it didnt work, so tried regular jinja:

  - title: Phones & Tablets
    icon_template: >
      {% if is_state('sensor.family_home','0') %} mdi:account-off
      {% elif is_state('sensor.family_home','1') %} mdi:account
      {% elif is_state('sensor.family_home','2') %} mdi:account-multiple
      {% elif is_state('sensor.family_home','3') %}  mdi:account-multiple-check
      {% else %}} mdi:account-group
      {% endif %}

no such luck.
Am I using incorrect Lovelace syntax, or is this simply not supported yet?

thanks for having a look

made this fancier mapper template, but still no luck.

title: Phones & Tablets
id: phones_tablets
icon_template: >
  {% set state = states('sensor.family_home') %}
  {% set mapper = {'0': 'mdi:account-off',
                   '1': 'mdi:account',
                   '2': 'mdi:account-multiple',
                   '3': 'mdi:account-multiple-check'} %}
  {{ mapper[state] if state in mapper else 'mdi:account-group'}}

This isn’t possible in Lovelace.

There are no built-in cards that accept any kind of template either (jinja or js). You’d need to develop a custom view. I’m not even sure if that is possible.

Thanks… Ill stop trying then, though that is an enormous let down…The current cards aren’t adjustable enough just yet, and it would certainly benefit the Frontend if we could use templates. Unless I am missing the obvious here, coming from the ‘old’ paradigm, which in itself was stil in pre-release Beta of course.:wink: Cant I use a state as condition anywhere?

Using custom-ui still works here and there, but it seems less supported on Lovelace, albeit in its Alpha stage.

Well you need to remember that templates also don’t work in the old interface. They only did because of customUI which is a custom package. Over time some icon customization was added to template components like sensor and light but other than that templating isn’t aloud. You’re just used to CustomUI. @thomasloven added templating to his markdown card, so others could incorporate it in the future. I wouldn’t be surprised if there was a way to make the custom view, I personally haven’t seen it.

yes, in understand and appreciate that.
Still, I would have thought, custom-ui being so popular and basic to the Front-end experience, this would have been incorporated ground up in Lovelace.

Still have my hopes up for that.

nevermind, please ignore

Just to add, and maybe it’s old news - if based off a binary_sensor then icon-template does work, below is one of my examples:

  - platform: template
    sensors:
      amazfit_home_or_away_icon_status:
        friendly_name: "Amazfit Watch"
        value_template: >-
            {% if states.binary_sensor.amazfit_home_or_away_boolean.state == "on" %}
              Home
            {% else %}
              Away
            {% endif %}
        icon_template: >-
          {% if states.binary_sensor.amazfit_home_or_away_boolean.state == "on" %}
            mdi:watch-vibrate
          {% else %}
            mdi:watch-vibrate-off
          {% endif %}

sure, thanks.
That has nothing to do with Lovelace though, but the definition of a regular (binary) template sensor. That hasn’t changed.

My search was to template the view (tabs in the menu) icons. Which I now do with CCH as follows: Compact Custom Header

btw you could also reference the sensor itself for the icon_template:

      amazfit_home_or_away_icon_status:
        friendly_name: "Amazfit Watch"
        value_template: >
          {% is_state('binary_sensor.amazfit_home_or_away_boolean', 'on') %} Home
          {% else %} Away
          {% endif %}
        icon_template: >
          {% is_state('sensor.amazfit_home_or_away_icon_status','Home') %} mdi:watch-vibrate
          {% else %} mdi:watch-vibrate-off
          {% endif %}

Hello everyone, how do you go about placing icons instead of names on the views? I can’t find the answer anywhere. Thanks in advance.

https://www.home-assistant.io/lovelace/views/#view-icon