File sensor directory hassio help

hi
i’m trying to set up the file sensor without success

- platform: file
  name: Todays Events
  file_path: /share/todays_events.txt

no matter what folder i choose i get the following error

Failed config
  sensor.file: 
    - Invalid config for [sensor.file]: not a file for dictionary value @ data['file_path']. Got '/share/todays_events.txt'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.file/
    - platform: file
      file_path: /share/todays_events.txt
      name: Todays Events
Successful config (partial)
  sensor.file: 

can someone please help

Did you “Note that file paths must be added to whitelist_external_dirs.”

I started again

so I have this in my config

   whitelist_external_dirs:
     - /config/test

and this is the sensor

- platform: file
  name: Todays Events
  file_path: /config/test/todays_events.txt

yes I still get the error

- Invalid config for [sensor.file]: not a file for dictionary value @ data['file_path']. Got '/config/test/todays_events.txt'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.file/
- platform: file
  file_path: /config/test/todays_events.txt
  name: Todays Events

Have you created /config/test and is a file in that dir called todays_events.txt

Removing the first / resolved my issue

Thank you for the support

1 Like

having the same problem, but using as file_path /local/file.txt

which first / are you referring too?

First slash in you sensor setting

Here is the white list in my config

whitelist_external_dirs:
- /config/sensor_scripts

Here is my sensor

  • platform: file
    name: Todays Events
    file_path: sensor_scripts/todays_events.txt

that’s my configuration

sensor:
  - platform: file
    file_path: local/filed_automations.txt
    name: Filed automations

homeassistant:
  whitelist_external_dirs:
     - /config/www
     - /config/python_scripts

still error. I am on HASSIO

2018-12-08 11:50:03 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.file]: not a file for dictionary value @ data[‘file_path’]. Got ‘local/filed_automations.txt’. (See ?, line ?). Please check the docs

Your using a path in your sensor that’s not the same as what you have white listed.

I’m sure you don’t need to white list www

I added whitelist because had the error (and still have)

Try placing your txt file in your python_scripts folder and change the sensor to python_scripts/filed_automation.txt and see if it works

I know this is an old thread. Thank you for the help on the directory part. Also My Acurite station output a csv and I figured out that it is case sensitive. in my case it must be “.CSV” not “.csv”. Maybe that will help someone in the future.

1 Like

Overall this thread helped alot, but there is no single example of a working config, and I feel that it would be helpful for future visitors:

For me, I created a file, that contains either 1 or 0, it is updated by a cron job on the OS, and my supervised Home Assistant install monitors it.

The OS path for the file is:

/usr/share/hassio/homeassistant/_my/data/flag_file

The same path from within the Home Assistant container is:

/config/_my/data/flag_file

In my /config/configuration.yaml I have the following under homeassistant:

homeassistant:
  allowlist_external_dirs:
    - "/config/_my/data"
  packages: !include_dir_named _my/packages

This loads pacakge files from /config/_my/packages' and whitelists _my/datapath under/config`

My file sensor configuration is placed in /config/_my/packages/flag_file.yaml:

sensor:
- platform: file
  name: Flag file
  file_path: "config/_my/data/flag-file"

After restarting, I now have an entity named sensor.flag_file with the content of the file.