Whitelist for file sensor doesn't work in HA virtual environment

Hi,

I spent days to get my file sensor work in Home Assistant. I followed som many manuals and discussions but it will not work.

I have an Raspberry OS with Home Assistant in Python virtual environment installation - followed the official installation guide.
My configuration.yaml:

default_config:
  whitelist_external_dirs:
    - /config
    - /config/www
  allowlist_external_dirs:
    - /config
    - /config/www
sensor:
  - platform: file
    file_path: /config/test.txt

I get the error “/config/test.txt is not an allowed directory”.
I tried all combination of “config” and “/config” and copied the file to nearly every possible directory on my RPi.

Then I tried it with an HassOS and an Home Assistant Core installation (without the Python virtual environment). In this installations my file sensor worked with the posted configuration.yaml.

So I reinstalled Raspberry OS and HA (Python Venv) and I got the same issues. Nothing will work.

Why is it not working in the official supported Python virtual environment?
Is it possible to access folders outside the virtual environment?
Has anyone a working file sensor in Venv?
Do I have to use an other whitelist_external_dirs setting in an Venv?

Thanks for your help.

The configuration directory is in “home/homeassistant/.homeassistant”
The test.txt file is in this directories:
/config
/home/homeassistant/.homeassistant/
/home/homeassistant/.homeassistant/config/
/home/homeassistant/.homeassistant/.storage/
/home/homeassistant/.homeassistant/.storage/config/

I start HA with a systemd service file with the command /srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

There are so many problems with your code snippet that I’m not quite sure how deep to go…

Almost every line is incorrect.

allowlist goes under homeassistant not default config. Whitelist doesn’t exist anymore, because it was replaced with allowlist. And venv installs don’t have /config (which is a mapped directory in a docker container), they have an actual configuration directory that you will need the path for. The configuration directory itself doesn’t need to be allowlisted anyway.

All I can really add to this is that everything you need to do to fix this is quite clearly covered in the documentation, so I don’t know where you got the configuration you did from, but scrap it and stick with the official docs in future :+1:

1 Like