Statistics not showing for some entities

My HA configuration includes default_config and I have no config entry for recorder so according to the recorder docs statistics should be kept for all entities, but I see long term statistics only for some. e.g. the battery level of a Bluetooth monitor has long term statistics, but the value of an entity from an ESPHome device measuring current is shown only up to 10 days ago, i.e. no long term statistics.

What’s the explanation for this?

Only for sensors that have a valid, unit_of_measurement and state_class.

That’s not mentioned in the user docs:

It says “all entities” will be recorded in the absence of any filters.

The entity in question does have a unit of measurement, but it’s quite possible it doesn’t have an explicit state class, though I’m surprised that "MEASUREMENT’ isn’t assumed as a default in that case.

Is there a way in HA to change the state class of an existing entity? It’s not presented as an option in the dialog that allows the name, icon etc to be changed. Indeed is there any way from the UI to see what the state class is?

That is state data only. Not LTS.

Yes. You said that at least one was from ESPHome. You can set the state_class in the esphome device file. See: Sensor Component — ESPHome

Other YAML defined integrations may have the same option you can add.

Alternatively you can use Manual Customisation to add it. This should be your last resort though.

The device in question is “Made for ESPHome” so although it’s currently running the stock firmware I can update it as the YAML config is available for customisation.

You can contact the device developer and ask them to add the state_class if you do not want to take control of the device firmware.