„No statistics found“ - but „Show more“ shows data?!

I have an ESPHome device sending power Informationen to HA. When clicking on the sensor entities it used to show the graph for power, energy usage, etc.

For a couple of days (since updating to 2022.12 I believe) it does not a show a graph anymore, but “Statistics not found”. But if I click in show more it jumps to the History panel and shows the graph just fine. If I look at the MariaDB tables the data is there - but for all sensors of one ESPHome device HA does not show them in the pop-up.

It does show them for the Diagnostics sensors and the switch of the device. Also, as the error message points to “No statistics found” and not “No history data” (or something along the lines) there seems to be a connection to the statistics data subset, not the history as such?

No errors in the log, DB working just fine. Deleting and re-adding the device did not do the trick, neither changing entity names or updating using ESPHome. Not quite sure where to keep looking…

Hm, so it appears changing the entity_id solves the problem but all data in the energy dashboard is lost (or already was before). Strange issue…

As it turns out, only deleting the device and re-adding it, then renaming the relevant entity, solves the problem. I have now found a temperature entity where the pop-up modal wants to show statistics that aren’t there anymore. Anyone have a hint what to look at? Still nothing in the logs and data in the database appears to be fine.

After updating from 2022.12.7 to .8 it works again. :man_shrugging:

Does anyone know more about this? I’m having it happen to me now on a sensor that worked before the 2023.1 update and now gives me this.


  # Water pressure analog signal in scale
  - platform: adc
    pin: SVP
    name: "Water Pressure"
    id: water_pressure
    unit_of_measurement: "psi"
    icon: "mdi:gauge"
    device_class: "pressure"
    state_class: "measurement"
    accuracy_decimals: 0
    update_interval: 1s
    # Required for ESP32 to measure 3.3v
    attenuation: 11dB
    #force_update: true
    #internal: true
      - calibrate_linear:
          # Zero-Pressure Calibration:
          - 0.3430 -> 0.0
          # Working-Pressure Calibration:
          - 1.91800 -> 58.0
      - sliding_window_moving_average:
          window_size: 15
          send_every: 1
      - logger.log:
          format: "*CALIBRATE Pressure LB-Correction: adc_raw=%.4f / output=%.4f lb"
          args: [ 'id(water_pressure).raw_state', 'id(water_pressure).state' ]


But under “show more” it has the full history just fine:

I know have it on a number of entities but can’t spot the common factor.

For example: I added a Shelly Pro4 where three channels work fine and one channel shows the exact problem above.

For some sensors, it works the first 12-24h after restart, then shows the problem above. I’m lost, I hope it’s not a problem with the database.

It appears that for some entities no statistics are being recorded. I don’t see anything wrong with the attributes - for example for the Shelly Pro4 where it works for three of the four channels and the settings are exactly the same.

Beginning to fear that I have a database problem…

I think I’ve narrowed it down a bit: Even though the database has the statistics for the correct metadata ID, HA claims “no statistics” for this period under Dev Tools → Statistics.

So the recording of the stats doesn’t seem to be a problem, but they seem not to be connected to the entity, even though the metadata entry is there.

Will investigate some more tomorrow…

OK, this is starting to get really weird…

Here’s a screenshot from my statistics_meta table:

Now if I run this query:

FROM   statistics_meta
WHERE  statistic_id = 'sensor.energieverbrauch_beschattung'

the result is 1 line found with id=294.

BUT: If I run this query:

FROM   statistics_meta
WHERE  statistic_id = 'sensor.athom_pg01_heizer_total_daily_energy'

… the result is 0 lines found.

My best guess is this why HA can’t find the statistics because it can’t match the entity_id to the entries.

But why doesn’t MariaDB report back the correct line even if its there?!

I found and fixed the problem: The index of the table was corrupted, for one device it also had duplicate entries. By killing the duplicate entries and optimizing the table the index was rebuild and everything looks good again.

Well still not great that it happens, but how do you fix the index?

For MariaDB, I used HeidiSQL to optimize the table which rebuilds the index.

I think HA uses sqlite by default and I was wondering what command to rebuild the index should I use, but it seems to be different issue for me.

Hi Guys;

I found a way to make this happen:
Change the unit of a sensor in Esphome after it has been running for a while. Even if you change it back it won’t correct the problem. I have had some luck with changing the unit in the meta entry to the currently used one. This seems to be an undocumented feature that needs some tracking down. But is does look like database change is the only way currently. You could rename the sensor in Esphome entirely to a new one and the new should work.