I’m trying to make the color change dynamically on a apexcharts-card radialBar.
In order to do that I use this template:
sensor:
- name: PM2_5 AQI Color
unique_id: e415238b-cc6d-4aa5-a894-0e83cbd0a7ed
state: >-
{% set pm2_5 = states('sensor.voorhaven_haren_belgium_pm2_5') | int %}
{% set r, g, b = 0, 0, 0 %}
{% if pm2_5 < 50 %}
{% set r = 255 %}
{% set g = (5.1 * pm2_5) | int %}
{% else %}
{% set g = 255 %}
{% set r = (510 - 5.1 * pm2_5) | int %}
{% endif %}
{% set hex_color = '{:02x}{:02x}{:02x}'.format(r, g, b) %}
{{ '#' + hex_color }}
Testing the template looks fine:
But using this code for a radialBar:
type: custom:apexcharts-card
header:
show: false
title: AQI
show_states: false
colorize_states: false
chart_type: radialBar
series:
- entity: sensor.voorhaven_haren_belgium_pm2_5
name: PM 2,5
apex_config:
plotOptions:
radialBar:
offsetY: 0
startAngle: -130
endAngle: 130
hollow:
size: 50%
dataLabels:
name:
show: true
offsetY: -10
value:
show: true
offsetY: 0
fontSize: 26px
fontWeight: 500
color: white
total:
show: true
offsetY: 0
label: AQI
fontSize: 12px
fontWeight: 500
color: white
formatter: |
EVAL:(w) => {
return w.globals.series[0] + '';
}
fill:
colors:
- "{{ states('sensor.pm2_5_aqi_color') }}"
Only gets this:
Is there something wrong with this approach?