Unknown states, old friendly names, old entities - how to get rid of them?

You have changed your sensor/light/… entities and/or their “friendly names” and end up to situation where that old stuff is still there and at “History” view shows their names with “Unknown” status?

You have maybe red from here that “delete home-assistant_v2.db and reboot your HA”. But, then you “loose” all information, including those entities what actually work!

There is “better” way. You just need to terminal connection to that machines /config directory where that home-assistant_v2.db -file is. Hass.io add-on “SSH & Web Terminal” works here fine.

  1. Open connection terminal/ssh
  2. Give command ‘cd /config’
  3. Give command ‘sqlite3 home-assistant_v2.db’
  4. Give command ‘delete from states where state = ‘unknown’;’
    // note that dot (.) before exit command
  5. Give command ‘.exit’

Refresh your “history” view at HA. :slight_smile:

At sqlite3, if you give command ‘.fullschema’, you get information what are structures of those schemas in use. From there you can figure out structure of data and you can delete some other data what you don’t need… Like events of sensors what don’t exist anymore.

Nice. There’s an even easier way for patient souls; just wait until your recorder purges the old information from the DB.

Might need to include a few more instructions for some users.

Command ‘sqlite3’ not found, but can be installed with:

sudo apt install sqlite3

I’m guessing that sqlite3 is pre-installed on the hass.io+hass os version? I have two instances of Home Assistant (one installed as venv and the other as docker) and neither has sqlite3 (confirmed by executing apt list --installed).