ApexCharts card - A highly customizable graph card

Just when I start getting it it changes :stuck_out_tongue: that’s unfortunate.
So I need to change all my sensors for it to work? Or can I just create a Template and work from there and keep te others?

I also got another thermostat than you, maybe that’s the problme? I dont have a entity heating but I do have an attribute, dont know exactly what to do now

this is fantastic! i want to use this but im having a hard time figureing out what is what. With that coulmn in entity sensor.power_consumption. I made a utility helper and I would like the graph to display 2 hours of live demand and have the bar graph display 7 days of total power consumption for that full day using the helper. But i would like to make the columns transparent so it is nicer to see. any idea what i would need to change?

Hi there, I have a presence sensor tracking the rooms I’m in over the day. Possible states are “Bath”, “Kitchen”, “Hall”, …
Is it possible with ApexCharts and without any additional sensor to create a donut diagram showing how many percent of the day or how long I’m in certain rooms?

I am building an energy consumption card and have a few questions.

  1. Is it possible to plot the lines until to the last value (actual / current) and not until end of day?
  2. Can Apexchart show the current consumption (which I have in a separate sensor) and todays average so far, like I mocked on the chart?

Screenshot 2023-01-17 at 11.11.51

My code so far:

type: custom:apexcharts-card
stacked: true
layout: minimal
graph_span: 24h
header:
  standard_format: false
  show: true
  title: Stromverbrauch heute
span:
  start: day
series:
  - entity: sensor.shelly_3em_channel_a_power
    name: Phase 1
    color: '#560BAD'
    type: line
    group_by:
      func: last
      duration: 45m
    stroke_width: 3
    show:
      extremas: false
      header_color_threshold: true
      legend_value: false
  - entity: sensor.shelly_3em_channel_b_power
    name: Phase 2
    color: '#B5179E'
    type: line
    group_by:
      func: last
      duration: 45m
    stroke_width: 3
    show:
      extremas: false
      legend_value: false
      header_color_threshold: true
  - entity: sensor.shelly_3em_channel_c_power
    name: Phase 3
    type: line
    color: '#F72585'
    group_by:
      func: last
      duration: 45m
    stroke_width: 3
    show:
      extremas: false
      legend_value: false
      header_color_threshold: true

  1. Have a look at the extend_to option
1 Like

hey there,
I am trying to display my power usage at home. I am building some sensors by getting this data from MQTT. This is how they show up
image
and how I am creating my sensors for each day of the week (pretty sure I am doing sthing wrong here):

 #Samedi
    #% Usage
    - name: "myelectricaldata.samedi.percentage_usage"
      unique_id: "myelectricaldata.pdl#.power_usage.samedi.percentage_usage"
      state_topic: "myelectricaldata/pdl#/power_max/samedi/percentage_usage"
      unit_of_measurement: " %"
    #Depassement capacité
    - name: "myelectricaldata.samedi.threshold_exceeded"
      unique_id: "myelectricaldata.pdl#.power_usage.samedi.threshold_exceeded"
      state_topic: "myelectricaldata/pdl#/power_max/samedi/threshold_exceeded"
    #Valeur totale
    - name: "myelectricaldata.samedi.value"
      unique_id: "myelectricaldata.pdl#.power_usage.samedi.value"
      state_topic: "myelectricaldata/pdl#/power_max/samedi/value"
    #Quand ?
    - name: "myelectricaldata.samedi.date"
      unique_id: "myelectricaldata.pdl#.power_usage.samedi.date"
      state_topic: "myelectricaldata/pdl#/power_max/samedi/date"

Then trying to integrate this into apexcharts:

  type: vertical-stack
  cards:
    - type: custom:apexcharts-card
      experimental:
        color_threshold: true
      graph_span: 7d
      #offset: '-7d'
      show:
        last_updated: true
      header:
        standard_format: false
        show: true
        show_states: true
        colorize_states: true
        title: Puissance utilisée
      span:
        end: day
      series:
        - entity: sensor.myelectricaldata_lundi_percentage_usage
          fill_raw: last
          type: column
          group_by:
            func: max
            duration: 1d
          stroke_width: 5
          show:
            header_color_threshold: true
            datalabels: true
          color_threshold:
            - value: 18
              color: steelblue
            - value: 40
              color: midnightblue
            - value: 50
              color: orange
            - value: 60
              color: orangered
            - value: 80
              color: red
        - entity: sensor.myelectricaldata_mardi_percentage_usage
          type: column
          group_by:
            func: max
            duration: 1d
          stroke_width: 5
          show:
            header_color_threshold: true
            datalabels: true
          color_threshold:
            - value: 0.18
              color: steelblue
            - value: 0.21
              color: midnightblue
            - value: 0.50
              color: orange
            - value: 0.60
              color: orangered
            - value: 0.80
              color: red
        - entity: sensor.myelectricaldata_mercredi_percentage_usage
          fill_raw: last
          type: column
          group_by:
            func: max
            duration: 1d
          stroke_width: 5
          show:
            header_color_threshold: true
            datalabels: true
          color_threshold:
            - value: 0.18
              color: steelblue
            - value: 0.21
              color: midnightblue
            - value: 0.50
              color: orange
            - value: 0.60
              color: orangered
            - value: 0.80
              color: red
        - entity: sensor.myelectricaldata_jeudi_percentage_usage
          fill_raw: last          
          type: column
          group_by:
            func: max
            duration: 1d
          stroke_width: 5
          show:
            header_color_threshold: true
            datalabels: true
          color_threshold:
            - value: 0.18
              color: steelblue
            - value: 0.21
              color: midnightblue
            - value: 0.50
              color: orange
            - value: 0.60
              color: orangered
            - value: 0.80
              color: red

Outcome if really really really bad - I have read lots of post and tbh I am lost:


Would appreciate directions / code samples / anything to help me moving forward :slight_smile:

Merci !!!

Is there any way to have “1 month” chart? What to put in the “graph_span”? Because each month has their own number of days.

So far, I use 30d as workaround:

When stacking 2 series, the yaxis max auto is not calculated correctly.

image

type: custom:apexcharts-card
header:
  show: true
  title: Consumption Today
  show_states: true
  colorize_states: true
graph_span: 24h
span:
  start: day
all_series_config:
  stroke_width: 3
stacked: true
yaxis:
  - min: 0
    max: auto
    decimals: 3
series:
  - entity: sensor.helper_electricity_consumption_normal
    type: column
    name: Normal
    float_precision: 3
    unit: ' kWh'
    show:
      datalabels: false
    group_by:
      func: last
      duration: 1h
  - entity: sensor.helper_electricity_consumption_off_peak
    type: column
    float_precision: 3
    unit: ' kWh'
    name: Off peak
    show:
      datalabels: false
    group_by:
      func: last
      duration: 1h

How do you format the datalabels like this?

image

First try to create MQTT sensors like this:

mqtt:
  sensor:
    # % Usage
    - name: "My Electrical Data Samedi Percentage usage" # Friendly Name
      unique_id: "myelectricaldata.pdl#.power_usage.samedi.percentage_usage"
      state_topic: "power_max/samedi/percentage_usage"
      unit_of_measurement: '%'
      value_template: '{{ value }}'
#      device_class: ????
#      icon: mdi:???
    # Depassement capacité
    - name: "My Electrical Data Samedi Threshold exceeded" # Friendly Name
      [...]
1 Like

I have the same issue so most likely a bug. Please share if you find a solution for it.

Weekends we have only one tariff, and those days there is no problem with the total.

Still scratching my head at what can be going wrong…

This has to be one of the biggest impacting projects on the UI for some time… Thanks for all your hard work Nice one @RomRider !

Can someone help me get the line to correspond with the value from the sensor?

image

As you can see, at present, all the colors are showing at every point.

  • The sensors are device class “battery” if that helps,

However I would like it to look like this:

image

ie, 90% = green line

5% = red line

type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 14 days
show:
  last_updated: true
header:
  standard_format: false
  show: true
  show_states: true
  colorize_states: true
  title: Cubecell Tracker Batteries
now:
  show: true
  color: '#B20000'
  label: Now
series:
  - entity: sensor.1_tracker_battery_percentage
    type: line
    name: 1 Tracker
    fill_raw: last
    show:
      header_color_threshold: true
    stroke_width: 5
    color_threshold:
      - color: '#B20000'
        value: 5
      - color: '#FF9912'
        value: 25
      - color: '#FFFF00'
        value: 50
      - color: '#98FB98'
        value: 75
      - color: '#00CD00'
        value: 90
  - entity: sensor.2_tracker_battery_percentage
    stroke_width: 5
    name: 2 Tracker
    fill_raw: last
    show:
      header_color_threshold: true
    color_threshold:
      - color: '#B20000'
        value: 5
      - color: '#FF9912'
        value: 25
      - color: '#FFFF00'
        value: 50
      - color: '#98FB98'
        value: 75
      - color: '#00CD00'
        value: 90

Many thanks for any advice

Looks like it is possible with the underlying Apex Charts library but not sure if you can achieve this in HA Line color based on value · Issue #585 · apexcharts/apexcharts.js · GitHub

Have a look at the Apex Charts docs dataLabels – ApexCharts.js in the formatter section

1 Like

Hi,

Thanks for getting back to me.

I do know that this is possible with the mini-graph card in HA as I use this already.

image

also, if you look https://github.com/RomRider/apexcharts-card/tree/dev#brush-experimental-feature:~:text=color_threshold%3A%0A%20%20%20%20%20%20%2D%20value,color%3A%20orange in the docs, the image is the image I want, I just don’t know how to get it.

The code above, (where the link points to) does not represent the graph below

Yeah ok. He does says its experimental! Only thing I noticed is that you don’t have a colour for 0-5? You could try removing some of the other key values you have to see if you are getting a conflict somewhere. Strip it right back and see if you can just get one line and colours.

Hallo, I need your help.
I have a daily increasing meter sensor and I’m using Apex Chart to show daily and weekly/monthly long time statistics. However, the problem is that the long time statistics seems not to reset the daily sensor exactly at 0:00 but some seconds later. This results in the problem that the fist value of the statistics is mostly not zero but the value of the previous day.

So, for daily statistics, I could fix this by using func: last

series:
  - entity: sensor.daily_energy_consumption
    name: Daily Energy
    statistics:
      type: max
      period: hour
    group_by:
      func: last
      duration: 1d

However, if I want to generate weekly or monthly statistics, I need to use func: sum which sums up wrongly when the last day value is higher then the current day value… as mentioned above … the statistics max function thinks that the first value is the maximum since the daily sensor reset was too late.

series:
  - entity: sensor.daily_energy_consumption
    name: Monthly Energy
    statistics:
      type: max
      period: hour
    group_by:
      func: sum
      duration: 30d 

Do you have any idea how I can skip or correct the first value in the daily statistics bucket?

Many thanks in advance

yea, get the whole experimental part, was just wondering as it does appear in the docs and if I was doing anything wrong in my yaml…

FWIW… here are the 2 side by side with the exact same thresholds…

anyway, thanks again,

Hey ! On it, ty for the direction