ApexCharts card - A highly customizable graph card

I want to use a input_select as value for a annotation line. How?

apex_config:
  annotations:
    yaxis:
      - 'y': {{states['input_select.limit']}}
        borderColor: '#cf6679'
        label:
          text: Limit
          borderColor: '#cf6679'
          style:
            color: '#fff'
            background: '#cf6679'

have to do a new sensor as this:

value_template: "{{(states('sensor.power_meter_active_power') | float * -1 ) | round(2)}}"

1 Like

You could wrap it with card-templater, it allows to add templates to almost any attribute (there is another card that allows templating too)
EDIT, example where I use wto input select fields to drive the offset

2 Likes

can we rewrite a data_generator:

        data_generator: |
           return entity.attributes.prices.map((record, index) => {
            return [record.time, record.price];
           });

to use individual entities for the hourly prices?
Ive deleted that CC providing those attributes (not allowed in core HA…) but do have a rest sensor providing 24 entities :wink:

I have this in a custom:mini-graph-card config now, but would prefer it to be an apexcharts.

this is the idea currently:

      - entity: sensor.energieprijs_uur_0
        name: 00:00-01:00
      - entity: sensor.energieprijs_uur_1
        name: 01:00-02:00
      - entity: sensor.energieprijs_uur_2
        name: 02:00-03:00
      - entity: sensor.energieprijs_uur_3
        name: 03:00-04:00
      - entity: sensor.energieprijs_uur_4
        name: 04:00-05:00
      - entity: sensor.energieprijs_uur_5
        name: 05:00-06:00
      - etc!

would appreciate some nudges into the right direction , thx!

Hi, can anyone help me troubleshoot two issues please?

  1. No matter what I do, I can’t seem to disable the automatic scaling of the Y axis. I would like to be able to set min and max manually so it doesn’t constantly adjust with my MQTT sensors. However, when I do this it shows me the correct Y axis for a second whilst pulling data from my sensor, but then defaults to the max value of the sensor and continues to automatically adjust the scale. I have tried forceNiceScale with no luck.

  2. I also can’t seem to set a label on my Y axis. No matter what options I out in, nothing ever shows.

I can’t help thinking that the two issues are related, and would be very grateful if someone could point out whatever obvious point I’m missing!

Thanks in advance

title: Water
views:
  - panel: true
    cards:
      - type: custom:apexcharts-card
        graph_span: 48h
        show:
          last_updated: true
        apex_config:
          chart:
            height: 300px
            width: 100%
          yaxis:
            labels:
              show: true
        yaxis:
          - id: W
            decimals: 0
            apex_config:
              min: 0
              max: 80
              labels:
                show: true
        series:
          - entity: sensor.tank_water_temperature
            type: line
            group_by:
              func: last
              duration: 5m
            stroke_width: 2
            yaxis_id: W

try this

        yaxis:
          - id: W
            decimals: 0
            min: 0
            max: 80

D’oh! Thanks very much…

This awesome card is sometimes too awesome :slight_smile: to find your way aound

very simple, just add “-” to your return x

  - entity: sensor.power_meter_active_power
    name: Grid
    color: red
    extend_to: false
    transform: return x / -1000;
    unit: kW
    float_precision: 2
1 Like

where do I put this ?

within the series as it is a series/sensor specific choice

How do I get rid of the (-1d) and the “legend” with the date and the line also want to have gone …

Hi, your post was 2 years ago, and unfortunately I can’t help you with your question either.
But could you share the yaml for your solar forcast card? Especially the readout of the SOLCast pv_estimate10 and pv_estimate90 (both Future Forecast) with the correct timestamp would interest me. (the setting of the data_generator). Thanks a lot!

image

To generate a forecast card using Apexcharts and SolCast showing the past forecast values (forecast pv_estimate in kWh) and the future lower and upper bound probabilistic forecast data P10, P90 (detailedForecast pv_estimate10 and pv_estimate90 in kWh) and the generated PV power (solarman_total_ac_output_power_active in W):

type: custom:apexcharts-card
apex_config:
  chart:
    height: 350px
all_series_config:
  unit: kWh
  float_precision: 3
  opacity: 0.3
  stroke_width: 3
header:
  title: Daily forecast
  show: true
  standard_format: true
  show_states: true
  colorize_states: true
graph_span: 1d
span:
  start: day
  offset: '-0d'
now:
  show: true
  label: Now
yaxis:
  - id: kWh
    min: 0
    max: 0.6
    apex_config:
      tickAmount: 5
  - id: header_only
    show: false
series:
  - entity: sensor.solarman_total_ac_output_power_active
    yaxis_id: kWh
    type: area
    name: PV
    color: orange
    opacity: 0.4
    show:
      legend_value: false
      in_header: false
    stroke_width: 1
    transform: return x/1000
    group_by:
      func: avg
      duration: 1min
    extend_to: false
  - entity: sensor.solcast_forecast_today
    yaxis_id: kWh
    type: line
    name: forecast
    color: black
    opacity: 1
    stroke_width: 2
    data_generator: |
      var now = new Date().getTime();
      var today = entity.attributes.forecast
        .filter(start => new Date(start["period_start"]).getTime() < (now + 1000*60*30))
        .map((start, index) => {
        return [
          new Date(start["period_start"]).getTime(), start["pv_estimate"] || 0
        ];
      });
      var data = today
      return data;
    show:
      legend_value: false
      in_header: false
    extend_to: false
  - entity: sensor.solcast_forecast_today
    yaxis_id: kWh
    type: line
    name: detailedForecast
    color: grey
    opacity: 1
    stroke_width: 2
    data_generator: |
      var now = new Date().getTime();
      var today = entity.attributes.detailedForecast
        .filter(start => new Date(start["period_start"]).getTime() > (now - 1000*60*30))
        .map((start, index) => {
        return [
          new Date(start["period_start"]).getTime(), start["pv_estimate"] || 0
        ];
      });
      var data = today
      return data;
    show:
      legend_value: false
      in_header: false
    extend_to: false
  - entity: sensor.solcast_forecast_today
    yaxis_id: kWh
    type: line
    name: 10%
    color: grey
    opacity: 0.6
    stroke_width: 1
    data_generator: |
      var now = new Date().getTime();
      var today = entity.attributes.detailedForecast
        .filter(start => new Date(start["period_start"]).getTime() > (now - 1000*60*30))
        .map((start, index) => {
        return [
          new Date(start["period_start"]).getTime(), start["pv_estimate10"] || 0
        ];
      });
      var data = today
      return data;
    show:
      legend_value: false
      in_header: false
    extend_to: false
  - entity: sensor.solcast_forecast_today
    yaxis_id: kWh
    type: line
    name: 90%
    color: grey
    opacity: 0.6
    stroke_width: 1
    data_generator: |
      var now = new Date().getTime();
      var today = entity.attributes.detailedForecast
        .filter(start => new Date(start["period_start"]).getTime() > (now - 1000*60*30))
        .map((start, index) => {
        return [
          new Date(start["period_start"]).getTime(), start["pv_estimate90"] || 0
        ];
      });
      var data = today
      return data;
    show:
      legend_value: false
      in_header: false
    extend_to: false
4 Likes

How do you reference attributes? The docs say that you can read an attribute instead of state, but it doesn’t do anything, state is the same as the last value of the data_generator which reads an array called rates. The “current” value is also held in an attribute called rate.
In a console.log in the data_generator I can reference entity.attributes.rate.value_inc_vat, but how do I use this in the attribute?

attribute string v1.4.0 Instead of retrieving the state, it will retrieve an attribute of the entity. Make sure you increase update_delay if the chart doesn’t reflect the last value of the attribute

I have added an extra entity and hidden the incomplete graph (ends at now) and used the state from that as the header, meanwhile taken the data_generator for the same, hidden the header. Now I’m left with legend names and values at the bottom for each duplicate series How can I remove the legend at the bottom, I blanked them out but the dots remain?

graph_span: 29h
span:
  start: day
  offset: +0h

I had the span set to 24h with an 12h offset, but this needs to be more dynamic as the next day’s forecast doesn’t appear until 4pm and after midnight, the start: day really screwed things up. how can I restrict the range to consistently show previous 2 hours and as much future data at is available, sizing the graph to the available data rather than getting the flatline at the end?

Hi, thanks for your tip.

But Im struggling to make it work.

type: custom:card-templater
card:
  type: custom:apexcharts-card
  graph_span: 2d
  span:
    start: day
    offset: -1d
  now:
    show: true
    label: Now
  apex_config:
    annotations:
      yaxis:
        - y_template: {{state("input_number.limit")}} 
          borderColor: '#cf6679'
          label:
            text: Limit
            borderColor: '#cf6679'
            style:
              color: '#fff'
              background: '#cf6679'
  series:
    - entity: sensor.kwh_meter_power_meter
      transform: return x / 1000
      extend_to: false
      name: Active Power
      float_precision: 3
      type: area
      stroke_width: 1
      opacity: 1
      color: '#3700b3'
      group_by:
        func: avg
        duration: 1h
entities:
  - entity: input_number.limit

What am I doing wrong?

I see the issue, tried a few ideas for about 20 min…failed. So tried another card that allows template…that works

type: custom:config-template-card
entities:
  - sensor.linky_daily
card:
  type: custom:apexcharts-card
  graph_span: 30h
  header:
    show: true
    title: Conso ELEC temps réel
    show_states: true
    colorize_states: true
  apex_config:
    annotations:
      yaxis:
        - 'y': ${states['input_select.limit'].state}
          borderColor: '#cf6679'
          label:
            text: Limit

X-axis labels go wonky by less then 4 group by_points, plain wrong at 1 group_by point

(The below examples are simplified, my actual use case is to make a dynamic overview for a Campground, where alas single or few nights is very common.)

So when I group_by, in order to both get a “diff” result, but also to count noon-2-noon, at 4 nights, it all looks dandy:

At 3 and 2 nights, it looks rather wonky, but at least not wrong:

But at 1 night, the x-axis label is just plain wrong

So I wonder if this is something I should report as issue, or if there is anything I can do.
BTW: when I use span: end: day it does not work at all for 1 day, so calculating the start is already a bit of a workaround.

For clarity: that last 1-day image, the data is for June 26, as intended, but the x-axis is wrong, so it displays multiple numbers, and a different date ends up in the middle

type: custom:apexcharts-card
graph_span: 1d
span:
  start: day
  offset: '-1d'
header:
  title: Pitch 03 Energy
  show: true
all_series_config:
  type: column
  offset: -12h
  statistics:
    type: state
    period: hour
  group_by:
    func: diff
    duration: 1d
series:
  - entity: sensor.airco_pm_energy_total
    name: Daily Noon to Noon

Is there some place better to get support/discussion on this component?
git discussions and issues seem to go unanswered and the git readme sends me here… also many questions and no response/answers.

I like this graph, implementation but config by trial and error is painful