ApexCharts card - A highly customizable graph card

Sorted out my own challenge here…
image

  • the different energy series are using sensors which return null when their value is zero, and apexcharts ignores them for drawing the series when they are null
  • I have automation which sets the active tariff (off-peak, shoulder, peak) into an input_helper at the correct times, and I have 1 of 3 conditional cards displaying depending on which tariff is active, so it always shows the current tariff’s draw and ignores the others

(Solar panels are zero because we are in the middle of an upgrade and they are disconnected)

Looking for a little help here with an annoying (and probably easy to fix!) issue that I am having with my charts. I will paste the code below… but the problem is that the Gravity line isn’t showing the correct data and updating (I can look at another chart of that variable and it is updating properly - steadily dropping from 1.045 to current 1.039). There is also no chart line for the battery or the thermTemp… can anyone spot what is wrong with this? I’m trying to get the 2 temp sensors using the same y axis, the fridge and heaters are just boolean step charts for on/off
The naming is correct in the code below (including the batterry typo!).
I suspect a very small change could fix this, but I cant work out what!
image


type: custom:apexcharts-card
header:
  show: true
  title: iSpindel Temperature & Battery
apex_config:
  chart:
    zoom:
      enabled: true
    height: 450
  yaxis:
    - id: tTemp
      min: 5
      max: 25
      opposite: true
      seriesName: tTemp
      decimalsInFloat: 1
      forceNiceScale: true
      name: Temp
      title:
        text: Temp
    - id: Battery
      min: 3.2
      max: 4.3
      opposite: false
      seriesName: Battery
      decimalsInFloat: 2
      name: Battery
      title:
        text: Battery
      forceNiceScale: true
    - id: Gravity
      min: 1.010
      max: 1.050
      opposite: false
      seriesName: Gravity
      decimalsInFloat: 3
      forceNiceScale: true
      name: Gravity
      title:
        text: Gravity
    - show: false
  stroke:
    width: 1
series:
  - entity: sensor.ispindle_temp
    name: iTemp
    group_by:
      func: avg
      duration: 8min
    float_precision: 1
    curve: smooth
    yaxis_id: tTemp
  - entity: sensor.brewtherm_temperature
    name: thermTemp
    group_by:
      func: avg
      duration: 8min
    float_precision: 1
    curve: smooth
    yaxis_id: tTemp
  - entity: sensor.ispindle_batterry
    name: Battery
    group_by:
      func: avg
      duration: 12min
    float_precision: 2
    curve: smooth
  - entity: sensor.ispindle_gravity
    name: Gravity
    yaxis_id: Gravity
    group_by:
      func: avg
      duration: 15min
    float_precision: 3
    curve: smooth
  - entity: sensor.brew_fridge_template
    type: area
    curve: stepline
    name: Fridge
  - entity: sensor.brew_heater_template
    type: area
    curve: stepline
    name: Heater
graph_span: 12h```

First, you are using the yaxis within the ‘apex_config:’. This does not support id’s. link

You need to format your yaxis as per the HA ApexCharts documentation. This should correct some of your problems.

Ah, thanks. Think I have now sorted it… removed the id and made sure I have a y-axis section for each series.

try - 'y': 0

OK, I am struggling with what I should use to even attempt to display this. As I have some experience with Apex I was thinking maybe, but I am not sure.

Goal: Displaying Pokemon Stats for the standard categories. Here’s a picture of what would be “nice” from Pokedex:

Since this data is driven in something I have built for randomly selecting a Pokemon, the data of course changes. All the values and categories are loaded into a sensor already. In fact I can display this data with a simple Markdown like this:

type: markdown
content: |-
  ## Stats
  {% for st in state_attr("sensor.random_pokemon","stats") -%}
    {{ st.stat.name }} {{ st.base_stat }}
  {% endfor %}

Which looks like this:

image

SO I have no issues getting the name and value to plot. Apex seem though to be more of a time-based plot and not a simple one time value. I have no care about “time” as this randomly changes during the day as Pokemon are changed. There is no “history” only a single point in time and a value and that single point has names not time (i.e. 6 series … or 7 if you count the sum). Note that the sensor has many, many things only one of which is the “stats” as an attribute and those vakue are buring deeper as you can see in the Markdown template to get to the values/names. It is not a simple single attribute for each nor would I want to create more sensors based on the master sensor as the data is there.

So is Apex charts good for this? Or something else? Does anyone have a starting point for me that can help me?

You can see the discussion here about creating the original sensor:

I would also note that I am not tied to a “bar” view, maybe a circular chart is better.

1 Like

The docs say only line, area and column are supported at the moment.

I would assume your answer then is “no”. Is there any other mini-graph card or something that could display this?

Hmmm…actually have a look here https://smarthomescene.com/guides/apexcharts-card-advanced-graphs-for-your-home-assistant-ui/ (I was looking at the series type options before not the chart type so radial bar is supported)

Understood and you are closer to what I was thinking EXCEPT … If you look at the example it is this:

type: custom:apexcharts-card
header:
  show: true
  title: Temperature Levels
  show_states: true
  colorize_states: true
chart_type: radialBar
series:
  - entity: sensor.bathroom_battery_level
    name: Bathroom
  - entity: sensor.bedroom_battery_level
    name: Bedroom
  - entity: sensor.kitchen_battery_level
    name: Kitchen

Simple entities. I need those to be an attribute hanging off a sensor that needs jinja or JS to get the value and name. But maybe it is a decent stating point

Maybe I can attempt to wrap it in a custom templatable entry or? Is “series” in that case templatable is the question.

** Update ***

Closer … still too much is canned but …

OK. See if you can come up with a solution with this card. If not, ha-floorplan will have this ability in maybe a month as a new feature.

Ultimately, this should not be this way but if I can wite it canned, I would think it could be better:

type: custom:apexcharts-card
header:
  show: false
  show_states: true
  colorize_states: true
chart_type: radialBar
all_series_config:
  max: 200
  show:
    legend_value: false
series:
  - entity: sensor.random_pokemon
    name: HP
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[0].base_stat]]
  - entity: sensor.random_pokemon
    name: Attack
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[1].base_stat]]
  - entity: sensor.random_pokemon
    name: Defense
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[2].base_stat]]
  - entity: sensor.random_pokemon
    name: Special Attack
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[3].base_stat]]
  - entity: sensor.random_pokemon
    name: Special Defense
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[4].base_stat]]
  - entity: sensor.random_pokemon
    name: Speed
    data_generator: >
      return [[new Date(entity.state).getTime(),
      entity.attributes.stats[5].base_stat]]

What does it need?
!) no one should assume that those stats are in the order, it should be able to be written as “for each stat” (maybe I use multiple entity card??"
2) The max should probably be like 110% greater than the largest value (maybe I use jinja custom template card?)
3) The display when mousing over the series should NOT display the percent, it should display the value (can’t believe this does not exist, I just must be missing something)

1 Like

Hello together,

I use mutliple yaxis (2) and use 6 series. The first one uses the first yaxis and the other 5 series uses the second yaxis.
Everything fine, but if hide the first series of the five ones, the yaxis is hidden also. The reminaing 4 series don´t have a yaxis:
grafik

grafik

Is it possible to show the yaxis all the time?

I expect its because the radial bar card expects values from 0-100%. This is from the Apex Charts docs:

Keep in mind that the value of these charts must be in percentage (between 0 and 100). You can still display the original value in labels, but the data presented in series must always be in a percentage.

What you really need is the bar chart I think but it isn’t currently available. Edit: here is the actual Apex Charts code that will drop the %. You will have to work out how to put it into the card syntax:

  plotOptions: {
    radialBar: {
      dataLabels: {
        total: {
          show: true,
          label: 'TOTAL',
          formatter: function (w) {
            return w.globals.seriesTotals.reduce((a, b) => {
                      return a + b
                    }, 0) / w.globals.series.length
          },
        },
        value: {
          show: true,
          fontSize: '14px',
          formatter: function (val) {
            return val
          },
        },
      }
    }
  },

I’ve searched for a quite a while and couldn’t find a solution for this, so wondering if it isn’t possible…

I’d like to use an entity state as a label in the chart. Basically using what’s below, but this doesn’t work (it doesn’t render the template).

now:
  show: true
  label: {{ states('sensor.mysensor')|float(0) }}

@OzGav thanks for the help but I have been completely unsuccessful as I think software is calculating deeper here. The incoming values are used with “max” to determine %. “max” is required and it doesn’t seem like I can even use a EVAL: function to set “max”, it just always errors. What I would have wanted was to simply do like Math.max(w.globals.seriesTotals) to get the “max” value and set it like 10% higher. Otherwise I am relegated to setting “max” to like 250 which is greater than the maximum value of the points in all the 1008 data points, but then it isn’t as pretty as scaling it like 10% higher than the maximum for any one of them. The HA documentation states that “many” of the properties can be set using Javascript but doesn’t say which ones. I suspect “max” is one of those.

As for the “dataLabels”, no matter where I put it (apex_config or within the series itself), nothing worked. Either it errored or they did not change and remain as “%”.

That can be done with config-template-card. You’ll find usage examples in this thread, though maybe not exactly for the label.

Sounds like you may have hit a limit on the card’s functionality. You could try filing an issue report on GitHub and see if you can get some traction for an enhancement or wait for the ha-floorplan option and see if that works for you.

Yes, it can be achieved, but I suspect not with your existing yaxis configuration. Please post your full code so I can see what you have now.

Hi,
I’m really frustrated. Half of my Apexcharts are not working anymore correctly since newest HA 2013.2 update. The problem seems that HA recorder does not save the sensor values anymore, if not changing. I have a lot of sensors which are 0 over night and not changing until morning. This results in empty ApexCharts or wrong display for area graph, for stacked …and even for line graphs. Even fill_raw is not working. Do you experience the same???

Example:
This is a sensor which 0 during night and starts producing >0 values in the morning.
image
As you see, there are no 0 displayed …and “Loading…” is written on the graph until first value >0 arrives :frowning:
Here is the code:

type: custom:apexcharts-card
header:
  show: true
  title: Value - Today
  show_states: false
  colorize_states: false
all_series_config:
  stroke_width: 2
  extend_to: false
color_list:
  - red
graph_span: 5h
span:
  start: day
  offset: +0h
series:
  - entity: sensor.input_voltage
    fill_raw: last
    name: sensorvalue
    type: line
    group_by:
      func: avg
      duration: 1min
    show:
      extremas: true

If I’m changing to e.g. graph_span: 12h … you will see the mess.
image

So, How can I fix this problem? any help is really appreciated…

Thanks