#Badge Icon Color

1 messages · Page 1 of 1 (latest)

shell verge
#

Hi, I want the small badge icon to change its color, depending on the data.

This should work, but doesnt:

type: custom:mushroom-template-badge
entity: sensor.humidity
name: Humidity
icon: mdi:water-percent
icon_color: >
{% set h = states('sensor.humidity') | float(0) %}
{% if h < 30 %}
blue
{% elif h < 50 %}
green
{% elif h < 60 %}
orange
{% else %}
red
{% endif %}

shell verge
#

Another version I tried:

type: custom:mushroom-template-badge
entity: sensor.humidity
icon: mdi:water-percent
color: |
{% if states(sensor.humidity) | float > 25 %}
red
{% else %}
blue
{% endif %}
label: Wohnzimmer
content: "{{ states(sensor.humidity) }} °C"
tap_action:
action: more-info

sullen mountain
#

This is what I’m using now and it works.

icon: mdi:water-percent
color: |
  {% set hum = states('sensor.home_humidity') | float(0) %} {% if hum < 30 %}
    blue
  {% elif hum <= 55 %}
    green
  {% elif hum <= 65 %}
    orange
  {% else %}
    red
  {% endif %}
content: "{{ states('sensor.home_humidity') }} %"
tap_action:
  action: more-info
entity: sensor.home_humidity
outer groveBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

rich pumice
#

Instead of states('sensor.home_humidity') you should be able to use {{ states(entity) }}

sullen mountain
#

Hi @rich pumice can you exaplain more? sensor.home_humidity is my entity id. thanks

rich pumice
#

The entity variable will contain the value you have assinged to the entity key of the card. Saves you from double work.