Configuring filesize sensor to monitor the size of home-assistant_v2.db

I have the following config:

  - platform: filesize
      - /var/lib/homeassistant/.homeassistant/home-assistant_v2.db

which results the following error at startup:

ERROR (SyncWorker_2) [homeassistant.components.filesize.sensor] Filepath /var/lib/homeassistant/.homeassistant/home-assistant_v2.db is not valid or allowed

The file is 100% there, as HASS is writing to it:

# ls -la /var/lib/homeassistant/.homeassistant/home-assistant_v2.db
-rw-r----- 1 homeassistant homeassistant 97591296 Jan  6 19:35 /var/lib/homeassistant/.homeassistant/home-assistant_v2.db

I am more interested in “not allowed” hint of error message… What I did wrong to configure this sensor?

Try whitelisting the /var/lib/homeassistant/.homeassistant folder under the homeassistant entry in your configuration.yaml file.

    - /var/lib/homeassistant/.homeassistant

See here:

If you are running HA in docker, you need to whitelist the /config folder instead and the file path would then be /config/home-assistant_v2.db.

Thanks, unfortunately it didn’t help. I have added above lines to the config, but it had no effect (the error is still logged at HASS startup).
P.S. I am not running HASS in a docker.

Strange, I have the same setup and my sensor is working fine. Do you get any error when you validate the configuration?

I validate the configuration using hass --script check_config and it does not report any issues.

Occasionally I have found out that HASS does not correctly expand symlinks in whitelist_external_dirs, reported as issue #31238.

Are you using docker?
Does the link work in the docker container or /and in the host?

No , I am not running under docker. I am running on Debian Linux.
I have created this symlink myself, and it has confused HASS. However the way it check file paths seems to be inconsistent: directory seems to be resolved, but file location is not. Hence they don’t match.

Then it should work. Maybe a permission file problem.

No, it cannot be. I just changed one line in configuration.yaml and it started to work.

What did you change? I can’t get it to work either. Can’t see the entity from within HA.

I don’t get your question. If you have a symlink somewhere in your full path to your file, then the solution is to add the full path to this file (with symlink resolved) to homeassistant.whitelist_external_dirs configuration variable.

Sorry. I have exactly this in my config:

    - /config

  - platform: filesize
      - /config/home-assistant_v2.db

After restarting HA, I can’t find the entity. I go to Developer-States and inspect all the entities and I can’t find anything. I was expecting to see something like sensor.filesize.XXX

Any tips?

And /config is a symlink? Anyway, post the full listing of your directory so that we can doublecheck permissions:

ls -la /config /config/

How do you have Home Assistant installed? On my RPI4 I have exactly what you have and it works fine. Depending on how you installed (i.e. mine runs under Docker) the path will be different.

I also added:

scan_interval: 1800

So it only checks the size every 30 minutes (1800 seconds) so my database does not get huge.

I have HA installed on “bare Linux” (so not Docker) via pip3 install homeassistant
So the path is absolutely correct.
How do you test? What is your configuration? What is the file location?

I’m running under docker, so the paths are different. If you are running bare metal, then I’d think that the paths would be the actual / physical path to the file.

Not sure if this is of any help but I use this sensor to get my DB size:

1 Like

It does not matter. Just tell me your setup and probably I get the difference. Your .homeassistant directory is inside Docker, right? Or you submount it as a volume? I see from above posts that typically the configuration directory is /config, so is /config a symlink in your case (the answer should be yes)? Where it points to?

I think you’re mixing SQL database (which is enabled within recorder) and file storage. This topic is about a sensor that measures size of file database, namely home-assistant_v2.db.

Fair enough, but isn’t the .db file the size of the database ? I was just suggesting a different way of monitoring its size, I dont have a home-assistant_v2.db as use MariaDB