Finding the heaviest entities
To find which entities are using too much space, you will have to dig into the database itself and run a SQL query. Fortunately, there is already an add-on to make it easier for you.
Go to the Add-on store: Open your Home Assistant instance and show the Supervisor add-on store. 911
Install the SQLite Web add-on: Open your Home Assistant instance and show the dashboard of a Supervisor add-on. 1.3k
If you want, you can Show in sidebar and also Start on boot. The choice is yours.
Make sure this add-on is started before you continue.
When you open the SQLite Web interface, you can see a few tables, of which only two are relevant:
states contains a log of all the states for all the entities.
events contains a log of all the events. Some events include event_data (such as parameters in call_service events), but state_changed events have empty event_data, because the state data is stored in the other table.
If you are curious to view the size of each table, try this SQL query:
SELECT
SUM(pgsize) bytes,
name
FROM dbstat
GROUP BY name
ORDER BY bytes DESC
It will also show ix_* entries, which are not real tables, but just indexes to keys in the actual tables.
Viewing events usage
Click on the events table in SQLite Web.
Click on Query.
Type the following SQL query:
SELECT
COUNT(*) as cnt,
SUM(LENGTH(event_data)) as bytes,
event_type
FROM events
GROUP BY event_type
ORDER BY cnt DESC
Viewing states usage
Click on the states table in SQLite Web.
Click on Query.
Type the following SQL query:
SELECT
COUNT(*) AS cnt,
COUNT(*) * 100 / (SELECT COUNT(*) FROM states) AS cnt_pct,
SUM(LENGTH(attributes)) AS bytes,
SUM(LENGTH(attributes)) * 100 / (SELECT SUM(LENGTH(attributes)) FROM states) AS bytes_pct,
entity_id
FROM states
GROUP BY entity_id
ORDER BY cnt DESC
Filtering out entities
Now that you know which entities are bloating your database, you can filter them out. Feel free to filter as many or as few as you want. When considering if you should filter it or not, ask yourself: Does the history of the state changes for this entity bring me value? Does it bring me as much value as the size it takes?
Edit your /config/configuration.yaml file, here’s an example from mine:
recorder:
exclude:
domains:
- device_tracker
- media_player
- uptime
- time_date
- worldclock
entity_globs:
- sensor.clock*
- sensor.date*
- sensor.glances*
- sensor.load_*m
- sensor.time*
- sensor.uptime*
entities:
- camera.front_door
- sensor.home_assistant_v2_db
- sensor.memory_free
- sensor.memory_use
- sensor.memory_use_percent
- sensor.processor_use
- weather.openweathermap
te