Why do some entities have no statistics entry?

Since the December release we call all see long term statistics in the history graphs :raised_hands:… However, not all my entities have history past 21 days ago.

For example, my inverter integration (GitHub - wills106/homeassistant-solax-modbus: SolaX Power Modbus custom_component for Home Assistant (Supports some Ginlong Solis, Growatt, Sofar Solar, TIGO TSI & Qcells Q.Volt Hyb)) has been running great for over 9 months, but for some reason many of the entities provided do not have long term statistics.

One affected is sensor.inverter_battery_soc that tracks state of charge. It’s found in the states_meta table but not in statistics_meta. The attributes for the entity looks fine, too:

unit_of_measurement: "%"
device_class: battery
friendly_name: Inverter Battery SOC

So a couple of questions…

  1. Is there a way to add missing entities to the statistics table?
  2. Any idea how this could have happened?

And a bonus: InfluxDB has been collecting everything fine, anyone know a way to get stats out of there and back into long term storage?

1, Yes.
2. Your sensors do not have a state_class.

1 Like

@tom_l Thank you :+1:, I’ll raise a pull request to fix that.

In principle, if I can get the full moment-by-moment history from InfluxDB, is there a process or class in HA that could reduce that down to and store in long term statistics?

It’s not impossible but it would involve some very tricky SQL. Which I do not know at all.

EDIT: also while waiting for the PR to be merged you can add the state_class with customize.

I’ve been wondering this recently, is there any way to get a list of all entities that aren’t linked to long term statistics? I’d like to figure out which ones don’t in my setup and get them resolved…