Folder sensor error

trying the folder sensor:
# https://home-assistant.io/components/sensor.folder/
- platform: folder
folder: /config
it should just calculate the size if the folder.

seems to work (creating sensor.config, had to hazard a guess, documentation fails to mention that…)

an error appears in the log as follows:

 "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/folder.py", line 41, in <listcomp>
    size_list = [os.stat(f).st_size for f in files_list]
FileNotFoundError: [Errno 2] No such file or directory: '/config/home-assistant_v2.db-shm'

is this expected behavior (the file seems to be temporary popping on and off during writes)?

I am also trying to get this to work. But getting config errors:

#  USB stick folder size
  - platform: folder
    folder: /dev/sda1

  - platform: folder
    folder: /sda1

This gets an ok when config check:
- platform: folder
folder: /dev

But how to I get the sda1 to work?

@Mariusthvdb The component works by first getting a list of files in a directory using glob, then iterating over each file in the list to get its size. My guess is that home-assistant_v2.db-shm is a file which is created temporarily, then deleted, which is causing it to not be found during the summation. Fix is to add a condition that the file is present. I’ve created an issue here.
@Mariusthvdb if the docs are lacking why not submit a PR to improve them?

@Tomahawk what is the error on the /sda1 folder?

1 Like

thanks @robmarkcole that would explain.
havent issued PR’s yet…not really sure thats up to us, thought is was for the dev’s only

OK I created a fix here.
Anyone can create a PR, the docs are a good place to start if you’ve never submitted a PR before. Therefore I will let you make the docs PR @Mariusthvdb just tag me as a reviewer.
Cheers

The fix has been merged

1 Like

The error when doing a configuration validation for my code abowe with configuration.yaml:

whitelist_external_dirs :
- ‘/config/’
- ‘/dev/’

“Invalid config for [sensor.folder]: not a directory for dictionary value @ data[‘folder’]. Got ‘/dev/sda1’. (See ?, line ?).”

If configuration like this, validation goes into an infinity loop when trying:
whitelist_external_dirs :
- ‘/config/’
- ‘/dev/sda1’

May I suggest that the folder sensor gets enhanced so it gives the alternative to list the files?
If I make a group called “USB-dongle”, I could have a list of the folder files with size and saved date/time.

The quotes around the paths aren’t necessary.

The intention with this component was to keep it simple and use minimal system resources. If you want to do more intensive monitoring of files then you will be interested in my folder_watcher component in 0.67.
Cheers

I am getting the same validation loop when sda1 is in the whitlist. And the same sensor error when sda1 is in the sensor declaration(?)

loop

Looking forward to 0.67 : )

You only need to add /dev to whitelist as all sub folders are covered

I am sorry to report that when introdusing “sda1” HA throws an config error (whitelits -/dev/ and sensor /dev/sda1/). If i only use “/dev/” for the sensor it works, but state-value is wrong for the “folder”-USB. Thinking of it, “sda1” is not a folder but the USB-drive. Can this be the issue?

Error when sensor with /dev/sda1:

And sensor and USB-dongle file size:
loop

… I expect that is the issue. What’s the python for scanning a drive?

As the N00b I am, I dint know.

I suggest you use a command line sensor and the linux command on this thread. Something like df -h /dev/sda1

Does not work.

  - platform: command_line
    name: USB folder size
    command: "df -h /dev/sda1/"

Still can´t get this to work. Has no one managed to get information about their USB-dongle in a Raspberry/Dockers environment?

List

Res

Is anyone using this component on Hassio? I recall I need to add the full path to the folder, and add the folder path to the whitelist, but can’t figure out what the correct path is on hassio. @Mariusthvdb ?

this is what I used (havent had the need for it lately, so can’t positively say it is still working):

     # https://home-assistant.io/components/sensor.folder/
     sensor:
       - platform: folder
         folder: /config

OK I had to add to whitelist and do a couple of restarts…

homeassistant:
.
.
  whitelist_external_dirs:
    - /share

sensor:
  - platform: folder
    folder: /share/motion
    name: motion_folder
1 Like

must confess had never thought of these other folders to be monitored… might be a good idea to keep an eye on the /backup folder too :wink:

Is there a way for this to calculate the folder size INCLUDING the sub folders?
I always get 0 bytes as the folder has subfolders and only goes above 0 when I add an actual file in and not a folder.