Entity state colour if power consumption above level

Hi, have searched the forum before asking here.

I have an entity which measures power. I would like to create another entity (template?) that acts as a switch and bases its colour (on/off) based on the power consumtion.

Thus:
off if power <10w
on if power >10w

where should I start?

Any examples?

This is the entity name:
sensor.wallswitch16_watt

Currently showing:
image

I would like to have another entity with that icon mdi:tumble-dryer following the state colour (yellow in my theme?) when power consumption is above 10w…

Trying this but no color changing:


  - entity: sensor.wallswitch16_watt
    templates:
      icon: >
      rgb_color: "if (state < 10) return [251, 210, 41]; else return [54, 95, 140];"
  - entity: sensor.wallswitch16_watt
    templates:
      icon: >
      rgb_color: "if (state > 10) return [251, 210, 41]; else return [54, 95, 140];"

This may be the kind of template you’re looking for - the icon changes depending on the state of the entity:

sensor:
  - platform: template
    sensors:
      sw_battery:
        value_template: >-
          {% if is_state('binary_sensor.study_window_low_battery', 'on') %}
            low
          {% else %}
            normal
          {% endif %}
        icon_template: >-
          {% if is_state('binary_sensor.study_window_low_battery', 'on') %}
            mdi:battery-alert
          {% elif is_state('binary_sensor.study_window_low_battery', 'off') %}
            mdi:check-bold
          {% else %}
            mdi:close-thick
          {% endif %}

but I don’t think it’s possible to change colours in the way you want without using a custom component from HACS.

sensor:
  - platform: template    
    droger:
        friendly_name: "Droger Status"
        device_class: power
        icon_template: mdi:tumble-dryer
        value_template: >-
          {% if states('sensor.wallswitch16_watt')|float > 10 %}
            on
          {% else %}
            off
          {% endif %}

This works in terms of showing on/off but colour is not yet changing… in lovelace…

Done!

this works:

binary_sensor:
  - platform: template
    sensors:
      droger:
        friendly_name: "Droger Status"
        device_class: power
        icon_template: mdi:tumble-dryer
        value_template: >-
          {% if states('sensor.wallswitch16_watt')|float > 10 %}
            on
          {% else %}
            off
          {% endif %}