Dashboard entitity icon from sensor value

Hi all, first post here, thanks for having me.

I am trying to set up icons on my dashboard to be dynamic, based on a sensor value.

I have a sensor called ‘sensor.melbourne_mdi_icon_0’ which currently has a value of ‘mdi:weather-sunny’

In my dashboard config, I am trying this:

  - entity: sensor.melbourne_short_text_0
    name: Today
    icon: {{ state_attr("sensor.melbourne_mdi_icon_0")}}

but as soon as I hit save, it changes to:

  - entity: sensor.melbourne_short_text_0
    name: Today
    icon:
      '[object Object]': null

Can somebody help me with the syntax to get the icon updated?

With very few exceptions core dashboard cards do not support templates. Unless specifically stated in the documentation that an option supports templates, then it does not.

You have a few options:

  1. Use a 3rd party card that does support templates
  2. Use Card-Mod
  3. Use the 100% Templateable Lovelace frontend resource.
2 Likes

Card-Mod worked well, thank you @tom_l

1 Like

Mind sharing what your solution looks like / code?
Thx!