„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.

sensor:

  # 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
    filters:
      - 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
    on_value:
      - logger.log:
          format: "*CALIBRATE Pressure LB-Correction: adc_raw=%.4f / output=%.4f lb"
          args: [ 'id(water_pressure).raw_state', 'id(water_pressure).state' ]

image

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…

1 Like

OK, this is starting to get really weird…

Here’s a screenshot from my statistics_meta table:

Now if I run this query:

SELECT id 
FROM   statistics_meta
WHERE  statistic_id = 'sensor.energieverbrauch_beschattung'

the result is 1 line found with id=294.

BUT: If I run this query:

SELECT id 
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.

1 Like

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.

1 Like

Yes, it’s a mess.
At some point I’ve renamed “sensor.device_x_wattage” of a power meter to a more sensible “sensor.device_x_power” on the Home Assistant Entity UI and since that, no history of that at all (though the current power is displayed correctly) even after renaming it back.

The only way I was able to have history for this sensor was to remove this device from integrations/ESPHome, and add it again.

I regret trying ESPHome on some of my power meters, never had any issues with Tasmota, mqtt config files was straightforward.

Hi,
I tried to replace the name and the id, but still didn’t work for me.
Before that I’ve checked the DB for duplication and didn’t find any.
Any other suggestion?
thx

Any update here?
I have an ESPHome device where some exposed entities have statistics (temp, humidity) but others don’t (air quality in µg/m³ / device_class: pm25)

Hey, where have you removed duplicate entries? I’ve got MariaDB and phpMyAdmin, can’t follow your steps :slight_smile: thanks.