ApexCharts card - A highly customizable graph card

The first one didn’t work - but the second did! Amazing! Thanks a million!

Super happy with the result :slight_smile:

1 Like

Hi everyone,

I use dash lines in different charts, however depending on the avg-duration, it doesn’t show a dash line, it just shows a line.

Does someone have a tip on how to set the dashArray, so that it appears as a dash even when the average set to 60 minutes?


2023-03-21 14_14_15-Anzucht – Gemüserei

Just looked at your code. I don’t see anything wrong with it !

I use the integration from my solar inverter, i write this number to an input number.
At 00:00 i reset this number to 0.
I have a template sensor that templates the value of the input number.
The name of that template sensor is sensor.gw2000_xs_totaal_vermogen_vandaag.
This sensor is logging to influxdb, i use the influxdb integration.
I have a url to the database which takes every day the highest number of this day.
Url:

192.168.2.19:8086/query?u=homeassistant&p=homeassistant&pretty=true&db=homeassistant&q=SELECT+max("value")+FROM+"sensor.gw2000_xs_totaal_vermogen_vandaag"+WHERE+("entity_id"+=+'gw2000_xs_totaal_vermogen_vandaag')+GROUP+BY+time(1d)+fill(none)

It gives me those values.
image

Since yesterday i was trying to take this data in a sensor with the rest sensor.
The idea was, maybe i can make a sensor that gives the same data as the example sensor, and is that the way to create a chart.

again,
how does this sensor look in the ha-history page ? GO TO HISTORY, LOOK up the sensor there ( span 1 month )

your integration ? is it the HACS intergration for your GW ?
what “this” number ?

highest number ?, is that a PEAK , or TOTAL?

You still have very hard to understand that noone can know what you are doing, so the best you can do is try to provide sufficient information

PS: Sorry i have very hard to understand which sensors your integration provides, seems strange to me that you can “LOG” to a DB, but not use SAME sensor to create a graph

Which sensors does you “integration” gives you ( forget about what you create, unless it’s all “homemade” ) , go through ALL the sensors you get from your integration, is there ANY that gives you a graph in HISTORY ?

Hello,

I use the Goodwe integration for my solar panels.
This gives me a sensor that displays each day’s total generated that day.
Somehow this often goes wrong and this value does not reset at 00:00.
To solve this problem I write the value to an input number, I reset it every day at 00:00 with an automation.
Then i use a template to display the value of the input number as a sensor.
Template sensor:

- sensor:
    - name: "GW2000_XS_TOTAAL_VERMOGEN_VANDAAG"
      unique_id: 'gw2000_xs_totaal_vermogen_vandaag'
      unit_of_measurement: "kWh"
      state: >
        {{ float(states("input_number.gw2000_xs_totaal_vermogen_vandaag")) }}

This works perfect.
History from the past days in my history. (my recorder records like 3 days)

But now i want to see the data from the past.
I have my solar panels now for 2 years, and my HomeAssistant about a year.
So i needed a DataBase where i can write data from the past in it.
Finally my search ended at influxdb.
So i installed the Community Add-on: InfluxDB
The handy thing is that I can upload my data from the past here by means of a CSV file.
Every day i write the kw’s from this day to the CSV file.
Works fine, with this CSV file i can add history data to my DataBase, and if my DataBase crashes.
I upload the CSV file and the data is back.
I have added my sensor.gw2000_xs_totaal_vermogen_vandaag to InfluxDB.
So it records sensor.gw2000_xs_totaal_vermogen_vandaag sensor in the InfluxDB.
So if i add the data manual, every day will get 1 value, the recording of the sensor.gw2000_xs_totaal_vermogen_vandaag to InfluxDB is “live”. So on 14:00 it will be 2.0kW and on 16:00 it will be 2.6kW.

With this url i can see the data in my browser:

192.168.2.19:8086/query?u=homeassistant&p=homeassistant&db=homeassistant&q=SELECT+max("value")+FROM+"sensor.gw2000_xs_totaal_vermogen_vandaag"+WHERE+("entity_id"+=+'gw2000_xs_totaal_vermogen_vandaag')+GROUP+BY+time(1d)+fill(none)

u= the Username of the user of the database
p= the Password of the user of the databse
db= name of the database
Then i select the max( “value”), so if this day on 14:00 i have 2.0kW and on 16:00 i have 2.6kW, the output is 2.6kW.
And i group this by(1d).
So it gives me the max(“value”) of every day.
See image:

And now is the goal to plot a graph where i can see the monthly values of the solar panels.

I was trying with the rest sensor

rest:
  - authentication: basic
    scan_interval: 90
    resource: http://192.168.2.19:8086/query?u=homeassistant&p=homeassistant&db=homeassistant&q=SELECT+max(%22value%22)+FROM+%22sensor.gw2000_xs_totaal_vermogen_vandaag%22+WHERE+(%22entity_id%22+=+%27gw2000_xs_totaal_vermogen_vandaag%27)+GROUP+BY+time(1d)+fill(none)
    sensor:
      - name: "RestTest6"
        value_template: "OK"
        json_attributes_path: "$.results[0].series[0]"
        json_attributes:
          - values

To get the values.
For now it looks like this:
image

Don’t believe this, i have started my old Raspberry PI.
And with the code i make the graph.
The differents is now that the DB not is on the PI, but on the NUC.
Trying to find the problem now, the PI is only local, maybe there is a problem.

1 Like

Do you also have this entity added in HA’s energy-page ? , so you actually have this data already there ? , i guess it might depends upon how you configured your influxDB

To query in the data-generator, maybe this will do

   series:
      - entity: the.sensor you want to read from
        name: kWh
        yaxis_id: xxx
        unit: kWh
        type: column
        data_generator: |
          return entity.attributes.values.map((entry) => 
          {
            var date = new Date(entry.time);

            return [date, entry.total];
          });

PS: above “time” and “total” is my “entry-name” for the values, in your case your don’t have a “name” for the entry, if you can’t get that , maybe try with “-” , thou the “map/list” you get(showed in the pic) does not look like yalm ! , maybe json, but maybe the “Original” sensor provide you with another “syntax” yaml …

I actually had influxdb, for grafana ( and also do to the fact i wanted import from CSV ) , but it’s a pain so i dropped it (i mean after 3 years( or less), you’ll never look back at those statistics ( as i also found it easier with ha-db, and graph-cards in ha ), not sure i would be better with MariaDB,

gtotal

No issues or questions, just wanted to share that I love this statistics card a lot! I’m coming from domoticz and moved to HA around 6 months ago and the only thing I was missing were the nice graphs that are default in domoticz.
Maybe one small recommendation to make starting with this card a bit easier: I think it would be better to scrap this data generation part of the default code for the card, since it looks as if it is all commented out it took me a while to understand where the data is coming from but besides this small issue it’s really great… should be the standard graph viewer for entities in HA imo

in Some case there is a need for “data-generation”, but out-most best would be read direct from sensor if possible

Indeed , always start small, and grow with patience and experience

I’m gonna try this also.
Don’t believe this, i have started my old Raspberry PI.
And with the old code i make the graph, the same code which gives on my NUC, Loading…
The differents is now that the DB not is on the PI, but on the NUC.
Trying to find the problem now, the PI is only local, maybe there is a problem.
If i now install InfluxDB on the PI, i upload the data it gererates a graph from his own database.
Maybe there is something wrong with my certificate, because i can connect the NUC from outside with DuckDNS, the PI is only local.

well still your sensor deliver a graph in History, ( And stores in the DB )

i would consider using the sensor

type: custom:apexcharts-card
header:
  show: true
  title: Solar Production - Daily
  show_states: false
  colorize_states: true
apex_config:
  chart:
    height: 440
    extend_to: now
  yaxis:
    min: 0
    max: 20
    forceNiceScale: true
  stroke:
    show: true
    width: 2
  legend:
    show: true
  experimental:
    brush: true
graph_span: 1month
span:
  end: month
show:
  last_updated: true
series:
  - entity: your sensor " gw2000_xs_totaal_vermogen_vandaag "
    name: This day
    color: '#5692A9'
    type: column
    float_precision: 2

InfluxDB you need specific sensor to fetch data from, if im not wrong

This is working, but only for the past 3 days.

First i can go to HA with http://192.168.1.1:8123.
If i add the duckdns addon, and add the certificate
Then i restart, i can acces HA with
https://192.168.1.1:8123, then the graph goes to Loading…
Delete i duckdns and certificate, it’s working.

http:
#  ssl_certificate: /ssl/fullchain.pem
#  ssl_key: /ssl/privkey.pem

I add here the #, HomeAssistant goes from https to http and it’s working.

try to install this “SSL” on influx

I tried

ssl &
verify_ssl

With all possible options, for now still Loading…
Thanks for thinking along

Hi!

Thank you for the awesome work here!

I searched through the topic and I couldn’t find an answer for this.
apexch

Is it possible to “lock” the opposite y-axis so that the 0.00 value always stay in the same position?
Sometimes the grey dashed line (primary y-axis) goes negative and the opposite one goes “down”, but I wanted it’s 0 to keep matched with the 0 from the primary one.

On the other hand I would like to keep the primary y-axis resizing dinamically.

Thanks!
AL

can’t add mush to the ssl part, i only have local access here, and also as you seems, using ip-address and not hostname … maybe thats why it never came to my mind that https could be the cause, which a never ending “loading” ofcause could indicate ( connection problems ) … thou i guess you never looked in the logs for that :slight_smile:

I have no idea, where i can find something about the Loading… in my logs.

maybe in the influxdb-integration logs, Settings/Add-ons/influxdb, … or ha-logs, in some case one have to enable “loglevel- Debug” ( in configuration.yaml) default log-level in HA is “info”, so if something is “wrong” you can change loglevel

1 Like