Why is recorder not adding entities to long term statistics?

Hello everyone,
I just looked at the statistics_meta table and found that a lot of my sensors are missing.

Maybe I have a basic idea wrong, but I thought that all entities that are being stored by the recorder also go into the statistics if they are a measurement (which basically all entities with numeric value are).

My recorder yaml:

Summary
recorder:
  db_url: !secret mariadb_homeassistant_url
  commit_interval: 60
  auto_purge: false
  include:
    entity_globs:
    #power consumption
      - sensor.*_energy
      - sensor.*_power
      - sensor.*energy_power*
      - sensor.*energy_today*
    #device information
      - sensor.esp32_wroom_32d_devkitc_v4_*_temperature
      - sensor.*_analog_temperature
      - sensor.*_last_restart_time
    #climate
      - sensor.eq3*
      - sensor.xiaomi*
    #misc
      - sensor.siemens*_operation_state
    entities:
      - binary_sensor.garage_input
      - sensor.database_file_size
  exclude:
    event_types:
      - lovelace_updated
      - hacs/config
      - hacs/reload
      - hacs/repository
      - hacs/stage
      - hacs/status

I do have the data in my normal states table available for e.g. all my climate sensors like the Xiaomi. But in statistics_meta there is not a single climate entity.

Does anybody know why?

Thank you :slight_smile:
Alex

This page shows the requirement for long term statistics. The short version is an entity must have a state_class of measurement , total or total_increasing. So yes, measurements, but you have to be explicit.

1 Like

Thank you @michaelblight ,
I just re-checked all my sensors and found that they all had a unit_of_measurement defined but not explicitely again the state_class: measurement.
This feels a little redundant to me to define the unit of measurement and HA not knowing that this then has to be a measurement. But anyway, clear oversight on my side.

Unfortunately SQL sensors do not allow definining a state_class. Is this intenional and is there a workaround?

And I also found that statistics seem unable to record a state. I have batteries not recording % but state GOOD/LOW. They are not being added to statistics.

You can use customize to add it. So something in customize.yaml along the lines of:

sensor.my_entity:
  state_class: measurement
1 Like

Kond of backwards to have to add state_class after creation instead of during :smiley:

But thank you very much. I will think about it :slight_smile: