mini-graph-card
mini-graph-card copied to clipboard
bug: state_map rendering should not use indexes when a value is provided
Not sure if this is a bug or a misconfiguration. If have this mini-graph with following config.
type: custom:mini-graph-card
name: Status
points_per_hour: 30
hours_to_show: 12
hour24: true
height: 150
line_width: 3
lower_bound: 0
state_map:
- value: CHARGE
label: Laden
- value: ABSORPTION PHASE
label: Ladeschlussphase
- value: DISCHARGE
label: Entladen
- value: PV + DISCHARGE
label: PV & Entladen
- value: GRID + DISCHARGE
label: Netz & Entladen
- value: BATTERY EMPTY
label: Akku leer
- value: BATTERY FULL
label: Akku voll
show:
points: false
icon: false
fill: fade
entities:
- entity: sensor.senec_system_state
name: Status
show_graph: false
- entity: sensor.senec_house_power
name: Verbrauch
color: '#AAAAAA'
show_state: true
show_indicator: true
- entity: sensor.senec_battery_charge_power
name: Laden
color: '#F06292'
show_state: true
show_indicator: true
- entity: sensor.senec_grid_exported_power
name: Einspeisung
color: '#A280DB'
show_indicator: true
show_state: true
My issue is that the label on primary y-axis shows the (first) value of the state_map
even when the sensor with mapped values isn't on the graph. In my case sensor.senec_system_state
has text values I want to display as main state without graph.
Even lower_bound
or setting that sensor on secondary y-axis doensn't make any difference to that lower label.
Looks like this is a side effect of the way state_map has been implemented in computeState()
: if the value is an integer smaller than the amount of items in state_map, it will find a corresponding item in the state_map and show that instead.
As a workaround, you could simply have - label: 0
as the first state_map
As a workaround, you could simply have
- label: 0
as the first state_map
Thanks for that. I will use that workaround in the meantime.
Another thing in this context I've noticed is a flood of warnings (in browser console) from your card when using state_map
.
In my case that are values from other sensors in the graph, which could be rendered without state_map
.
Not sure if this is possible: Maybe state_map
should be defined within an entity? That would possibly avoid that values from other entities are searched in the state-map.
EDIT: Just took a look at the milestone and saw that this is exacly what you're planning to do. Thanks!
I reached the same problem today when trying to show switch and cover states on the same chart:
state_map:
- value: off
label: 0
- value: on
label: 1
- value: closed
label: 0
- value: open
label: 1
No matter how I rearrange the values, half of them are out of the 0-1 range. I suspect this could be solved either by actually taking label:
's into account (this issue) or with #398.
I also see the same bunch of warnings for temperature sensors (which are on a different Y axis), but this is due to #271.