Allowing to define state color for template sensors

Most cards and badges accept state as an argument for the color.
Yet, very few sensors actually have a state color.

I’d like to be able to define the state color of any template sensor. It would look something like this:

    - name: "Salon target temp" 
      unique_id: "salon_radiateur_target_temperature"
      device_class: temperature
      state_class: measurement
      unit_of_measurement: "°C"
      state: "{{ state_attr('climate.radiateur_salon', 'temperature') | float }}"
      icon: >
        {% if (state_attr('climate.radiateur_salon', 'temperature') | float) < 14 %}
          mdi:snowflake
        {% elif (state_attr('climate.radiateur_salon', 'temperature') | float) == 21 %}
          mdi:fire
        {% else %}
          mdi:thermometer-alert
        {% endif %}

      state-color: >
        {% if (state_attr('climate.radiateur_salon', 'temperature') | float) < 14 %}
          light-blue
        {% elif (state_attr('climate.radiateur_salon', 'temperature') | float) == 21 %}
          red
        {% else %}
          purple
        {% endif %}

And the result would be:

image

vs

image

Not saying this will never happen but in my opinion it is unlikely.

Home Assistant has a well defined separation between backend (e.g. integration configuration) and frontend (e.g. dashboards and cards).

You have just mixed the two.

A better way to approach this would be to ask for this configuration in card configs rather than the sensor config. Or just vote for this as the request already exists: Entity Icon color & custom icon color based on state (customise icon_color)

I’m not sure I have. I understand why you say that but hear me out.

What I’m asking for is a state-color parameter for template sensors that would override the domain, device_class, and state.

Of course you could argue that the color is necessarily a frontend element because it’s meant to be displayed by the GUI but I’m only suggesting a sensor should be able to define its state color, not that the state color would necessarily be shown on the frontend: it would be only if color: state is defined at the card level, the frontent still being able to display it in pink if wanted. It’s not dissimilar from the icon: argument: you can define the icon of a template sensor in the backend but the frontend can still override it and show another icon.

Is it better? Having to modify every card available to take a new argument vs adding one thing in the backend?
The FR is 5 years old and no progress has been made, maybe a new approach would encounter less resistance?

There’s no doubt about it. It is.

You can use card-mod themes globally for all cards.

And an icon isn’t graphical?

Yeah but it’s a mod

Indeed, but if this happens to your FR as well:

Then you have an alternative. i.e. It was not meant to negate your FR, just highlighting it can be done an alternative way in the mean time.

The devs have made it very clear that color will not be added to the backend outside of themes.