kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
3.08k stars 238 forks source link

bug(color_thresholds): no longer appearing after introducing a `state_map` #780

Open Tamas-Toth-ebola opened 2 years ago

Tamas-Toth-ebola commented 2 years ago

Hi!

First of all I would like to throw a very big 'thanks' for your work(s) as this card is almost the only card type in my HA config and I really love it. So really lot of thanks for your efforts so far!

But from another aspect I got a soft problem/bug at my use cases.

Environment:

If we use state_maps we can not use color_thresholds with them (and I do not really see the reason of that), as the result is always the usage of the defined color in the thresholds object. Check the following sample.

The config:

type: custom:mini-graph-card
entities:
  - entity: sensor.u_s_air_pollution_level
    name: Air quality
font_size_header: 10
font_size: 66
hour24: true
height: 50
line_width: 1
hours_to_show: 168
align_state: center
show:
  labels: false
color_thresholds:
  - value: hazardous
    color: '#ff3d00'
  - value: very unhealthy
    color: '#ffff00'
  - value: unhealthy
    color: '#ffff00'
  - value: unhealthy for sensitive groups
    color: '#ffff00'
  - value: moderate
    color: '#ffff00'
  - value: good
    color: '#64dd17'
state_map:
  - value: hazardous
    label: Hazardous
  - value: very unhealthy
    label: Very unhealthy
  - value: unhealthy
    label: Unhealthy
  - value: unhealthy for sensitive groups
    label: Unhealthy for sensitive groups
  - value: moderate
    label: Moderate
  - value: good
    label: Good

And the result: image

Could anybody please help on it? Thanks for it in advance!

jlsjonas commented 2 years ago

Hey, could you try using the label value instead of the incoming value? It shouldn't do that though :)

badewanne1234 commented 1 year ago

Hi, I can confirm the same, I also have the described problem. Is there any progress on this? @jlsjonas what do you mean to use label instead of incoming value? do you mean in the colour_thresholds using label instead of value? If so, I tried it and it throws an error...

jlsjonas commented 1 year ago

Hey, I meant to use the label as value (f.e. Hazardous instead of hazardous) as we're not using the raw values.

For backwards compatibility, we'll have to support both when(/if) fixing this

badewanne1234 commented 1 year ago

I tried to use the label value as well (however one must still indicate the label value as value: Hazardous instead of label: Hazardous - the color thresholds requires a value, if using label as an indicator, it throws an error. Regardless of the test, it did not work anyway unfortunately...

new-xmon-df commented 5 months ago

Hi, any solution for this? thanks

new-xmon-df commented 5 months ago

Hi again,

I have already managed to get it to work, I think what happens is that you have to use the keys of the values ​​as defined in the state_map

This is my working setup:

type: custom:mini-graph-card
name: Estado del aire últimas 24h
entities:
  - entity: sensor.sensores_salon_bme680_iaq_clasificaci_n
    name: Calidad
font_size_header: 10
font_size: 56
hours_to_show: 24
hour24: true
points_per_hour: 60
update_interval: 30
line_width: 1
show:
  labels: true
color_thresholds_transition: hard
color_thresholds:
  - value: 0
    color: '#7DFF00'
  - value: 1
    color: '#00FF00'
  - value: 2
    color: '#8FEE8F'
  - value: 3
    color: '#FFD500'
  - value: 4
    color: '#FFA500'
  - value: 5
    color: '#FF8C00'
  - value: 6
    color: '#FF4500'
state_map:
  - value: Excelente
    label: Excelente
  - value: Buena
    label: Buena
  - value: Ligeramente contaminado
    label: Ligeramente contaminado
  - value: Moderadamente contaminado
    label: Moderadamente contaminado
  - value: Muy contaminado
    label: Muy contaminado
  - value: Severamente contaminado
    label: Severamente contaminado
  - value: Extrem. contaminado
    label: Extremadamente contaminado

imagen