Display apexchart from Statistic entity

Hello,

I have an integration, edata from HACKS, to get data from the meeter of couple houses into HA.
That integration provide some useful data and you can add it into the Energy dashboard.
I would like to do some cool charts with apexcharts, although it doesn’t accept the statistic entity edata:zc0f_consumption, it only allows sensors.
From the statistics tool I can see the hourly data is there.

How could I extract the hourly data to use it in an Apexchart?

Thanks.

if the statistic is imported (and HA enforces a colon ‘:’ in the name ) then it is not possible with Apexcharts, requests to enhance have been raised multiple times.
Apex requires a ‘normal’ sensor on which the statistics are based

1 Like

Thank you.
Is there anyway to convert the statistic entity into a sensor?
I’ve tried with helpers and scripts but without any success.

Not that I know of and I tried in many (!) ways ( I have an integration importing gas usage). Only option is to use the HA-core statistics graph

1 Like

And not sure why I did not see this before but… you can ‘fake’ an entity via the datagenerator and collect the stats using the websocket.
In below sensor.0c414c7e_b64a8a9a_browser_user is just a random entity as Apexcharts demands an existing entity …it is a dummy entry but has to be an existing one
the stat_entity has to be added twice and then it works.
Note that for my statistiuc data, I am using the ‘state’ value, you may want ‘sum’ or 'mean’or anything else IF that exists for your entity (check via the HA statistics graph)

type: custom:apexcharts-card
graph_span: 100d
series:
  - entity: sensor.0c414c7e_b64a8a9a_browser_user
    name: current
    color: red
    stroke_width: 1.3
    data_generator: |
      const stat_entity = 'gazpar:gazpar_thuis_consumption_stat';
      var statistics = await hass.callWS({
          type: 'recorder/statistics_during_period',
          start_time: new Date(start).toISOString(),
          end_time: new Date(end).toISOString(),
          statistic_ids: [stat_entity],
          period: "hour",
      });
      var stats = statistics[stat_entity];
      var result = [];
      var len = stats.length;
      for (let i = 0; i < len; i++) {
        let stat = stats[i].state;
        result.push([(new Date(stats[i].end).getTime()),stat]);
        }
      return result;

That’s awesome,
In my graph I need state also.
I’ve created a dummy input number helper, input_number.dummy_helper_kwh, for the apexchart entity so in the legend it can display kWh .