Folder_watcher not working - no errors?

I’ve setup the folder_watcher component to monitor a folder, and update a input_text field - but nothing happens, no errors, no update - any advice on where to start looking? I’ve tried giving the lest restrictions possible just to get it to work

/media/Security/motion
drwxrwxrwx 2 homeassistant homeassistant 0 May 12 2018 motion

configuration.yaml:
whitelist_external_dirs:
- /media/Security/motion
folder_watcher:

  • folder: /media/Security/motion
    patterns:
    • ‘*.mkv’
    • ‘*.mp4’
    • ‘*.avi’
    • ‘*.mov’

automation.yaml:

  • alias: “Admin - set last_security_vid variable”
    trigger:
    event_data: {“event_type”:“created”}
    event_type: folder_watcher
    platform: event
    action:
    service: input_text.set_value
    data_template:
    entity_id: input_text.last_security_vid
    value: ’ {{ trigger.event.data.path }} ’

Literally - nothing happens when files are created in the directory.

Same here no errors in log still nothing happening:(
Home Assistant
0.69.0
hassbian
already tried to (re)install the watchdog lib.

#trusted directories for sending files
whitelist_external_dirs:

  • /tmp

folder_watcher:

  • folder: /tmp
    patterns:
    • ‘*.avi’

automation.yaml:

  • alias: “Motion Video created”
    hide_entity: true
    trigger:
    platform: event
    event_type: folder_watcher
    event_data:
    event_type: created
    action:
    • service: notify.telegram
      data:
      message: ‘Bewegung in der Wohnung!’
      data:
      video:
      - file: “{{ trigger.event.data.path }}”

If this helps, I have it working but I don’t have a whitelist setup but this limits you to where you can have folder watcher monitor files.
For me under homeassistant’s config directory www/ I created subdirectories to monitor.

folder_watcher:
  - folder: /PATH_TO_HA_CONFIG/.homeassistant/www/SUB_DIR
    patterns:
      - '*.jpg'

Whenever a JPEG file is created under SUB_DIR, folder watcher sees it.

I get the same thing - doesn’t work for me. No errors logged.

(the sub folder under www is a link to a smb share - but, access is fine - motion, etc is happily writing there, I can also access items such as jpg files from home-assistant on the share)

The watched folder needs to be accessible directly by the OS, and will not work on network drives. Please see the docs to understand how watchdog operates https://pythonhosted.org/watchdog/

I’ve created an issue to address this, but I’m not sure the solution https://github.com/home-assistant/home-assistant/issues/14677

Cheers

@xrapidx @wmaker can you try the folder sensor and see if this works? trying to determine what the issue is here

Sorry or the delay… will give it a try over the weekend, having issues with my install so redoing everything.

@robmarkcole Sorry, I’ve been out for a couple of weeks. Would you still like for me to try folder sensor?

I can confirm folder_sensor works - if I understand correctly, it only gives the size and count of whats in the folder?

Please do try

folder_sensor works for me. I did two cases:

  1. No white list, but folder_sensor monitoring sub-directory under www
sensor:
  - platform: folder
    folder: /PATH_TO_HA_CONFIG/.homeassistant/www/SUB_DIR
  1. Using White List (without White List, this does NOT work)
homeassistant:
  whitelist_external_dirs:
    - /PATH_OF_INTEREST
sensor:
  - platform: folder
    folder: /PATH_OF_INTEREST

I added and deleted files, and the state (size in MB) and attributes (number of files, byte size) are updated after 5 to 15 seconds.

Interesting, folder_watcher should default to polling if reachable but not local. Is the drive a usb or external?

1 Like

Ah…I see what you’re after now (test with network drive).
No my file system is all local drive.

My test was with a mounted network folder in a home-assistant docker container. It worked for the sensor, but not for the watcher.

This is interesting - I just checked my home-assistant error log, and I have just two errors:

(sqlite3.OperationalError) locking protocol [SQL: ‘INSERT INTO events (event_type, event_data, origin, time_fired, created) VALUES (?, ?, ?, ?, ?)’] [parameters: (‘folder_watcher’, ‘{“event_type”: “modified”, “path”: “/Security/44-20180612065038.mp4”, “file”: “44-20180612065038.mp4”, “folder”: “/Security”}’, ‘LOCAL’, ‘2018-06-12 06:50:44.415257’, ‘2018-06-12 06:50:47.074768’)] (Background on this error at: http://sqlalche.me/e/e3q8). (retrying in 3 seconds)
Log Details (ERROR)
Tue Jun 12 2018 08:50:57 GMT+0200 (South Africa Standard Time)

Error executing query: (sqlite3.OperationalError) locking protocol [SQL: ‘INSERT INTO events (event_type, event_data, origin, time_fired, created) VALUES (?, ?, ?, ?, ?)’] [parameters: (‘folder_watcher’, ‘{“event_type”: “modified”, “path”: “/Security/44-20180612065038.mp4”, “file”: “44-20180612065038.mp4”, “folder”: “/Security”}’, ‘LOCAL’, ‘2018-06-12 06:50:44.415257’, ‘2018-06-12 06:50:47.074768’)] (Background on this error at: http://sqlalche.me/e/e3q8)

I use Ubuntu and I locally mounted a samba (cifs) to a remote file system.
I also added the newly mounted directory to the white list. Folder_sensor worked.
It took anywhere from a couple of seconds to as much as 35 seconds to recognize
file adds/deletes.

Think I might look into using something else. My requirement is quite simple, I just want to send a telegram video message when motion is captured on an outdoor camera.

I would have been nice to do as an automation for the ability to easily disable or enable the “service”

I have the same problem.

Guys I had also problems with the folder watcher, you can try this in order to check if the underlying library works as expected:

# d1.py is the sample script from this site: https://pythonhosted.org/watchdog/quickstart.html#a-simple-example
/tmp # python3 d1.py 
2019-09-08 22:16:32 - Modified file: ./camera_doods_flur_unten_latest.jpg
2019-09-08 22:16:32 - Modified file: ./camera_doods_flur_unten_latest.jpg
2019-09-08 22:16:32 - Created file: ./camera_doods_flur_unten_20190908_221631.jpg
2019-09-08 22:16:32 - Modified directory: .
2019-09-08 22:16:32 - Modified file: ./camera_doods_flur_unten_20190908_221631.jpg
2019-09-08 22:16:34 - Modified file: ./camera_doods_flur_unten_latest.jpg
2019-09-08 22:16:34 - Modified file: ./camera_doods_flur_unten_latest.jpg
2019-09-08 22:16:34 - Created file: ./camera_doods_flur_unten_20190908_221633.jpg
2019-09-08 22:16:34 - Modified directory: .
2019-09-08 22:16:34 - Modified file: ./camera_doods_flur_unten_20190908_221633.jpg