RomRider / apexcharts-card

📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant
MIT License
1.08k stars 75 forks source link

Support of statistics without state entities #707

Open vingerha opened 1 month ago

vingerha commented 1 month ago

Enhance Apexchart to allow the use of statistics data in Home Assistant without state entities.

Re-trying on the ticket @hindseb opened earlier

There are quite a few integrations that collect statistics externally and HA (core) then requires this to have a statistics_id with a colon, alike opower:consumption.... I am assuming that this prevents the Energy dashboard to complain.

All these integrations create statistics without state entities because utilities don't provide real time data. Examples are opower (see https://github.com/RomRider/apexcharts-card/issues/663), french electricity (myelectricaldata) and gas (gazpar_2_mqtt) and likely many more.

HA regular statistics card can deal with these stats but that does not allow to add the super functionality that ApexC offers.

vingerha commented 1 month ago

@RomRider it is not too easy to get to the details of HA as there is no (di.e. I id not find it) documentation on this topic. When diving in the core/recorder/etc. python stuff one finds out that the external statistics are stored with a (for-me) very odd naming convention wrt to their statistics_id (statistics_meta), e.g. for my gas sensors, they look like: gazpar:gazpar_thuis_consumption ... especially the use of a colon in the name was surprising. By using this 'convention' (no clue who invented this), it seems to skip checks (?) for the energy dashboard but it also does not allow to provide dummy sensors to circumvent apexcharts needs/shortcommings in this case.

I am not at all up to speed with the tech stuff behind your apexcharts solution but if you see light at the end of this tunnel and may provide direction, I am am happy to further investigate/test/etc. :)

hindseb commented 1 month ago

Hi @vingerha

If it is of any help, I am copying the documentation from Home Assistant on the naming convention. Please see here: https://data.home-assistant.io/docs/statistics/

Here you can see that colons are used if the data is imported from an external source.

I hope that helps a bit further. I would highly appreciate it if the apex chart could be enhanced. I would love to use the tool to show data from my long-term statistics. Thanks for the efforts in advance.

vingerha commented 1 month ago

Hi, I am aware of that and the design (logic?) escapes me but even though I want to understand how/why HA does things, I am on low expectation that this gets fixed. I tried with dummy entities and normal (non ':' ) named statistics, apex works but then the energy board (a.o.) starts complaining. In any case... the request is to have Apexcharts ignore the 'normal' entity and allow statistics entities ...which is the actual source of the statistics data so not too bad as a entry point :)

RomRider commented 1 week ago

Where do you find this statistics_id with the : in the name ?

vingerha commented 1 week ago

After the import you would only find this in the statistics_meta table Here is a visual example of mine for two integrations that use this load, they both use data extracted from the provider with a day or more delay in the availability. There are quite a few other areas on where this is used.

image