ApexCharts card - A highly customizable graph card

what If I don’t want the 0 value to be seen ?

I use null to remove any graph
transform: "return x >= 0 ? x : null ;"

1 Like

I am trying to visualize what you want but … if you have a x with timeseries on regular distance and filter out the negative/zero value than you graph will probably show gaps …

I have a chart in gradient blue. When it goes below zero I want the chart in gradient green…
It was told that you cannot change color when you want it in gradient.
So I made 2 charts. 1 with values above 0, 1 with values below zero. But it doesnt look nice to have 0 zero value, so I want it removed…

that is what I want ! Top. Thanks

I have red a few questions here about wind plots of some kind, I can’t answers these questions but if you are looking for a way to plot wind speed and direction I have had good luck with this card.

Is it possible to show multiple entities at once in the tooltip when using the line graph?

In the apexchart documentation there is the “shared” keyword für the tooltip. I tried it but no success. I am either doing it wrongly or it is not implemented. I seen to remember seeing it done though.

I’m using the color_threshold in an Octopus Price chart so different price thresholds change the bar colour.

Would it be possible to template the value?

Hey everyone,

Is there an actual way to share the tooltip? A viable way that actually functions in every single way, without a bug of some sort?

Cause i’ve been really trying do figure this out for the last couple days and couldn’t find anything.

Thank you.

When scrubbing/hovering over the graphs, the pop-up says “Today”. But as you can see that temperature is from two days earlier (Today is Dec 1st). Is it supposed to be like that?

Screenshot 2023-12-01 at 01.04.37

1 Like

Hi - I want to exclude in my apex chart entitites, that are not available. Current the charts is only display information, when all entities are available.

I used therefore the following script:

type: custom:apexcharts-card
graph_span: 8h
update_interval: 60sec
header:
  show: true
  title: Docker Memory Overview -8h
  show_states: false
  colorize_states: true
series:
  - entity: sensor.docker_audiobookshelf_memory
    stroke_width: 2
  - entity: sensor.docker_icarus_memory
    stroke_width: 2
  - entity: sensor.docker_minecraft_bedrock_2_memory
    stroke_width: 2
  - entity: sensor.docker_minecraft_bedrock_memory
    stroke_width: 2
  - entity: sensor.docker_omada_controller_memory
    stroke_width: 2
  - entity: sensor.docker_valheim_server_memory
    stroke_width: 2
state_filter:
  - operator: template
    template: '{{ states[entity].state != "unavailable" }}'
    entities:
      - sensor.docker_valheim_server_memory
      - sensor.docker_icarus_memory
      - sensor.docker_minecraft_bedrock_2_memory
      - sensor.docker_minecraft_bedrock_memory

But I get this error: /// apexcharts-card version 2.0.4 /// value.state_filter is extraneous

If for example the entity is not there, because the docker container is shutdown, it should be exluded from the graph.
image

I am greatful for any help :slight_smile: Thanks a lot,
Mark

Hi guys, i need some help

My main goal is this:

  • Compare today usage with last year usage on the same day, if possible that it shows if im using more or less…

But i try to understand how this works so i wnted to create a sort of total from last month.
When i use this code it works, however it adds the hours from today to the total as well…
How can i only show just only last month without calculating the value from today?

type: custom:apexcharts-card
header:
  show: true
  title: Energy usage
  show_states: true
  colorize_states: true
span:
  end: month
  offset: -8h
show:
  last_updated: false
series:
  - entity: sensor.p1_energytotal
    type: column
    group_by:
      func: delta
      duration: 1month
      start_with_last: false
    offset: '-1month'

For this you would need to compare statistics. Unless you have configured a huge-mother-of-all-db, that data is not kept in normal history. I am on ht emove so cannto provide example

Here’s one for you, I use Apexcharts to graph my heating, but noticed it wasn’t working completely for a couple of rooms. After some trial and error it would appear that it is now not liking ‘null’.

Here is an example where I’ve reversed it to show idle times as opposed to heating for the ease of demonstrating.

Original code

  - entity: sensor.climate_lounge_hvac_action
    transform: 'return x === ''idle'' ? 20: null;'
    curve: stepline
    type: area
    opacity: 1
    stroke_width: 1
    show:
      in_header: false

Demo code

  - entity: sensor.climate_lounge_hvac_action
    transform: 'return x === ''idle'' ? 20: 0;'
    curve: stepline
    type: area
    opacity: 1
    stroke_width: 1
    show:
      in_header: false

So you can see the only difference between the code is the transform to 0 from null. But on the second graph I get 3 bars, vs only the last instance from my original code. Any ideas or suggestions?

Hi Vinger,
My db is on mariaDB its not that big tho.
Remember the conversion back then, i still using it.
I found out a way to compare and it works, however i don’t need the graphs only the numeric value.

here is the code i use, this compares this month with the same month last year:

type: custom:apexcharts-card
header:
  show: true
  title: Energy usage TOTAL MONTH
  show_states: true
  colorize_states: true
span:
  end: month
  offset: '-8h'
show:
  last_updated: false
series:
  - entity: sensor.p1_electricity_consumed_off_peak_cumulative
    type: column
    name: now
    color: orange
    group_by:
      func: delta
      duration: 1month
      start_with_last: false
  - entity: sensor.p1_electricity_consumed_peak_cumulative
    type: column
    name: now
    color: orange
    group_by:
      func: delta
      duration: 1month
      start_with_last: false
  - entity: sensor.p1_electricity_consumed_off_peak_cumulative
    type: column
    name: last year
    color: purple
    group_by:
      func: delta
      duration: 1month
      start_with_last: false
    offset: '-365.25 days'
  - entity: sensor.p1_electricity_consumed_peak_cumulative
    type: column
    name: last year
    color: purple
    group_by:
      func: delta
      duration: 1month
      start_with_last: false
    offset: '-365.25 days'

image

and this for daily:

type: custom:apexcharts-card
header:
  show: true
  title: Energy usage compare today with last year
  show_states: true
  colorize_states: true
graph_span: 1day
span:
  end: day
show:
  last_updated: false
series:
  - entity: sensor.p1_electricity_consumed_off_peak_cumulative
    type: column
    name: now Offpeak
    color: green
    show:
      header_color_threshold: true
      extremas: false
    group_by:
      func: delta
      duration: 1day
      start_with_last: false
  - entity: sensor.p1_electricity_consumed_peak_cumulative
    type: column
    name: now Peak
    color: green
    show:
      header_color_threshold: true
      extremas: false
    group_by:
      func: delta
      duration: 1day
      start_with_last: false
  - entity: sensor.p1_electricity_consumed_off_peak_cumulative
    type: column
    name: last OffPeak
    color: blue
    show:
      header_color_threshold: true
      extremas: false
    group_by:
      func: delta
      duration: 1day
      start_with_last: false
    offset: '-365.25 days'
  - entity: sensor.p1_electricity_consumed_peak_cumulative
    type: column
    name: Last peak
    color: blue
    show:
      header_color_threshold: true
      extremas: false
    group_by:
      func: delta
      duration: 1day
      start_with_last: false
    offset: '-365.25 days'

image

sadly there is no way to even read the long-term data with a template so it stores these numbers in a separate sensor/entity…
thats what i wanted, to get those values in a sensor.

I must admit to be surprised that you got data, whatever I do with such offset, it runs dead … as I expect since the db does not have that data(if not using statistics)… what is sensor.p1_electricity_consumed_off_peak_cumulative containing?

I really returns the data fast, in 2 seconds.
I have hosted it on my 2 proxmox servers, 2x active and 1 backup
It’s really fast and works great with mariaDB.

That specific device is my off peak usage, it will record ever time it changes.
Same for the other sensors.

I only keep like (all temperature/humid sensors and electricity consume + gas)
It does not make the database any big at all.

For example i also use google sheets integration and imported it into grafana.
On sheets i have 2 year data of all my temp sensors and electricity and gas usage, nothing else, it writes every time it changes value, so it has tons of data on that sheet.

But whole sheet is only 7mb for 1 year.

Hi all

I’m working on a graph for my solar system to show the current solar power coming through my panels and compares against the estimated maximum power I can get from the sun assuming the charge controller can accept it all.

I have the graph looking quite nice, however I would love it if the solar (PV) power would change color according to the charge controller state (eg. red for bulk charging, orange for absorption, then green for float)

Below is my current code:

type: custom:apexcharts-card
header:
  show: true
  title: Solar Power
  show_states: true
  colorize_states: true
series:
  - entity: sensor.solar_power
    data_generator: ''
    type: column
    stroke_width: 1
    group_by:
      func: avg
      duration: 5min
    yaxis_id: power
  - entity: sensor.solcast_pv_forecast_power_now
    type: column
    data_generator: ''
    stroke_width: 1
    offset: '-30m'
    yaxis_id: power
  - entity: sensor.battery_soc
    type: line
    stroke_width: 1
    yaxis_id: percentage
graph_span: 14h
span:
  start: day
  offset: +6h
now:
  show: true
  color: red
  label: Now
yaxis:
  - id: power
    decimals: 1
    apex_config:
      tickAmount: 5
  - id: percentage
    min: 0
    max: 100
    opposite: true
    decimals: 1
    apex_config:
      tickAmount: 5

image

Does anyone have a suggestion on how i could get this to work?
I was thinking something along the lines of an if statement alongside “color:”.

if "sensor.pv_charger_state" = Bulk, color = red
if "sensor.pv_charger_state" = absorbtion, color = orange
if "sensor.pv_charger_state" = float, color = green

My attempts along those lines haven’t worked yet though.

Any help would be appreciated!

I’ve googled and search these forums and read through peoples code but I cannot for the life of me to get my apexchart-card in Homeassistant to fill the width of the screen. They appear to be fixed but I’ve seen posts of graphs showing them much wider?

type: custom:apexcharts-card
header:
  title: Flow Temp History
  show: true
  show_states: true
  colorize_states: true
apex_config:
  chart:
    type: area
    height: 300
    fill:
      type: gradient
series:
  - entity: sensor.current_flow_temperature_in_circuit_0
    name: ^^ Flow Temperature Now
    stroke_width: 1
    show:
      datalabels: true
      extremas: true