How to use a template to change the Icon colour when its a negative or positive number?

Look that worked, i lost the kWh at the end of the number but as i said i dont know what im doing, i only learn by examples i see. I dont know code or how to read it, so thank you again! really appreciate it

if you want the kw back…

- type: template
  icon: "{{ state_attr('sensor.power_to_from_grid', 'icon') }}"
  icon_color: >
    {% set state = states('sensor.power_to_from_grid') %}
    {% if state | is_number and 0 < state | float < 1 %}
      green
    {% elif state | is_number and state | float < 0 %}
      blue
    {% else %}
      red
    {% endif %}
  content: "{{ states('sensor.power_to_from_grid') }} {{ state_attr('sensor.power_to_from_grid', 'unit_of_measurement') }}"
1 Like

thank, now i can go and read up on how this as the example makes sense to me.

Thankyou and if i could id crack open a beer with ya mate

1 Like

then penny just dropped on the the whole type: template!! sigh

1 Like

Can you help me with this one ?

              - type: custom:mushroom-chips-card
                chips:
                  - type: template
                    entity: climate.eetplaats
                    icon: |-
                      {{ iif(is_state('climate.eetplaats', 'cool'), 'mdi:air-conditioner','mdi:air-conditioner' ) }}
                    icon_color: >
                      {% if is_state('climate.eetplaats', 'heat') %}
                        rgb(235,194,194)
                      {% elif is_state('climate.eetplaats', 'cool') %}
                        rgb(0,255,255)
                      {% else %}
                        rgb(84,84,84)
                      {% endif %}

Why doesn’t the icon change from colour ?