Change input_number icon depending on sensor state?

Hi,

I’m trying to change icon for an input_number helper depending on a sensor state, but so far having no luck with it. I found good working solutions to do it for sensors, but struggling with input_number.

My current code doesn’t produce any icon at all, so wonder if somebody could either offer a solution or at least point me in the right direction. I’m new to homeassistant so don’t fully understand how it all works under the hood.
Ideally I’d like to do it in vanilla without using any card mods etc.

This is what I have at the moment in customize.yaml

  input_number.newvol:
    templates:
    icon: |
          {% if is_state("sensor.matt_audio_default_device_muted", "False") %}
            mdi:volume-high
          {% else %}
            mdi:volume-mute
          {% endif %}

any help will be greatly appreciated

The icon of an input number does not accept templates. Not in the original config, not via customize.

That is your only option.

1 Like

any suggestions which HACS to look for/how to tackle this?

This would say “template” instead of “icon” if it was supported:

https://www.home-assistant.io/integrations/input_number/#configuration-variables
brave_screenshot_www.home-assistant.io

Install card-mod. Then read/ask in the card-mod topic.

thanks, done it with card-mod.
this is the code that worked for me:

card_mod:
  style: |
    :host {
      --card-mod-icon: 
        {% if is_state("sensor.matt_audio_default_device_muted", "False") %}
          mdi:volume-high
        {% elif is_state("sensor.matt_audio_default_device_muted", "True") %}
          mdi:volume-off
        {% endif %}
    }