Generation of long term statistics will be suppressed unless the unit changes back

Hi, after upgrading to 2021.9, I get this error:

“The unit of sensor.sommerhus_monthly (kWh) does not match the unit of already compiled statistics (None). Generation of long term statistics will be suppressed unless the unit changes back to None”

the sensor is/needs to be in kWh, and not “none”, how do one fix this ???

5 Likes

I am getting the same error messages.

I’m seeing a similar error message

The unit of sensor.duke_energy_usage_today_kwh_cost (USD) does not match the unit of already compiled statistics (EUR). Generation of long term statistics will be suppressed unless the unit changes back to EUR

USD is the correct unit and my currency is set to USD. This is the auto-generated entity for energy cost tracking.

1 Like

I fixed mine this way:

my recorder is running mariaDB, so I used phpMyAdmin

When into the “Statistics_meta” table and found the sensor (e.g. sort by the unit_of_measurement), hit “edit” and change the unit_of_measurement as pr the error. (to the value you want it to be)

I did a reboot, don’t know if that’s needed… then wait until hh:12 and check the logs

14 Likes

I was able to fix mine the same way. I use the default sqlite DB, so I used “DB Browser for SQLite” to fix.

Thanks, I did install the phpmyadmin add-on :Home Assistant Community Add-on: phpMyAdmin then follow your direction and changed it from null to kWh also and voilà! Thanks for sharing!

2 Likes

Thanks for the fix. Worked perfectly. A kinda dumb issue… I first configured Energy and the currency of my instance was set to EUR, which was wrong. I hadn’t needed to use it/change it before so wasn’t an issue. I changed it to GBP (correct currency) and it was working fine. Seems like a bug that you can change a setting via the UI and break something else - at the very least changing the UI setting should have updated this database value too.

completely agree, but the fix is easy, but i understand why it’s needed… hope it fixed in 2021.10 :smiley:

one can do it directly from ssh terminal without need to install anything.
First stop the home assistant, then, start sqlite CLI:

root@raspberrypi:/mnt/1g/hass# sqlite3 ./home-assistant_v2.db
SQLite version 3.27.2 2019-02-25 16:06:06
Enter ".help" for usage hints.
sqlite>

then, check schema of table statistics_meta:

sqlite> .schema statistics_meta
CREATE TABLE statistics_meta (
        id INTEGER NOT NULL, 
        statistic_id VARCHAR(255), 
        source VARCHAR(32), 
        unit_of_measurement VARCHAR(255), 
        has_mean BOOLEAN, 
        has_sum BOOLEAN, 
        PRIMARY KEY (id)
);
CREATE INDEX ix_statistics_meta_statistic_id ON statistics_meta (statistic_id);
sqlite>

then, dump the table:

sqlite> select * from statistics_meta;
...
41|sensor.mainpowercons_energy_cost|recorder|EUR|0|1
...
sqlite>

so in our case the line with the currency entry is 41 - so update it to desired value:

sqlite> update statistics_meta set unit_of_measurement = 'CZK' where id=41;
sqlite> 

press ctrl+D to exit the sqlite console, and start the home assistant again.

HTH.

4 Likes

This manual procedure is necessary for basically any utility meter you create, as it only receives an unit after it gathers data.

Hopefully it gets fixed, but for now, thanks for the steps!

And for MariaDB it works almost the same;

From HA command-line:

➜  ~ mariadb homeassistant

Select statistics meta table:

MariaDB [homeassistant]> select * from statistics_meta;
MariaDB [homeassistant]> update statistics_meta set unit_of_measurement = 'CZK' where id=41;
4 Likes

Any ideas how to do this on a HAOS install? sqlite3 is not available.

Supervisor → add-on store → community add-ons

image

A new Developer Tools panel/tab has been added. I couldn’t find the exact version number, but somewhere between 2021.9 and 2021.10 the Statistics tab was introduced.

You should now be able to correct this issue in the HA GUI under:

Developer Tools > Statistics

The missing unit entry should be listed here, and the database can be amended by simply clicking FIX ISSUE.

Here’s an example of the the tab:

35 Likes

Had the exact same issue on 2021.10.3 with AUD/EUR. This fix helped me as well. Thanks @Michael_Dahl

Found the location but the fix is to what I get is:

Entity has no state

This entity has no state at the moment, if this is an orphaned entity, you may want to remove the long term statistics of it from your database.

Do you want to permanently remove the long term statistics of sensor.house_daily_utility_meter from your database?
I am able to confirm or cancel. I am not sure I understand the solution.

MaxVRAMs post should be the solution. Its the UI solution, the others work too, i guess.

@niraviry i had the same issue, in my case i added a weather station, default was mph for wind speed. but i changed to m/s (since, who the heck needs land or what ever miles, aside from sea and air where its nautical miles and where it really makes sense as the unit is based on the earth, metric is so much easier all around), so HA created wind_speed_2 for me with m/s as unit. Since i did not want to use the _2 on all occasions i was using wind in future, i deleted the wind_speed entity and renamed the _2 to just wind_speed. (of course i also had wind_gust and max_daily_wind_gust with the same issue)

Then the DB threw an error at me. first error was the wind_speed has mismatching units (mph vs m/s). thats easy, it was recorded as mph, then i switched, of course the values do not match, so i deleted all the old history with the solution from here you have already followed and based your question on.

later then i had an other error, the very same you had. this time for wind_speed_2. i think you see where this goes. took me a while to understand, that this was just an information that the DB was tracking a value where it did not receive any recent updates. in other words, in my case it told me, that the entity i did monitor as wind_speed_2 did not exist any more.

so you need to check, is your entity dead because the sensor does not report any more due to battery or radio issues, or did you remove or rename it, and therefore there is no input to the DB any more.

If radio or battery, fix it and the error goes away.

if removed or renamed, delete it with the tool from MaxVRAM pointed at. no sense in recording a zero with no value to you into the db.

Cheers
Manne

Hi! how can i acces to DB if i am running homeassistant in a synology nas through docker contanier?
I am having the same issue.
thanks!

I had the same problem and came across this thread.
First I tried to fix it with SQLite browser approach. But if you read the log message to the end, you can fix it in HA via UI.
Use this link and open it in HA and then sort the stats list by issue. You can find all problems and fix them directly.

4 Likes

Holy crap thank you, can this please be marked the solution? I was trying a bunch of solutions above (and failing), until I scrolled far enough to see this magic one.