Folder_watcher not working - no errors?

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

Hello, did you get an answer for this after? I’m in the same situation, currently sending a notification when my camera detects a person, but sometimes the media isn’t available straight away (thanks nest) so want to trigger based on a file being created instead of the device

It was too inconsistent, I eventually just put a delay in the automation - so it waits a minute after its triggered before sending the file

I think i’ve figured this out now. Its over engineered, but seems to be working more consistently, and get access to a higher image in the notification (the nest ones were blurry)

So it uses Watch Folder to check when a new file is created in the specified folder, that will trigger my shell command that will simply copy the newest file from the nest directory , and copy it to the www folder at ‘latest’ (Used copy to keep the originals in nest folder incase I ever need them & move to latest in destination folder so that this folder doesn’t fill up)

The notification simply uses the latest.jpg image each time, which so far get’s updated and haven’t noticed a significant delay from the original way of doing it (both automations are running while i assess) and of course, each time you have a valid image

move_media_file_for_notification: cp $(ls -t1 /ls -t1 nest/event_media/a5a101b3b10822886f2c9a1155538391/*camera_person.jpg | head -n1) /config/www/media/latest.jpg
- id: doorbellnewfilecreatedinnestfolder
  alias: Doorbell - Person detected - Screenshot
  trigger:
    - platform: event
      event_type: folder_watcher
      event_data:
        event_type: created
  condition:
    # If holiday mode on no automations
    - condition: state
      entity_id: input_boolean.holiday_mode
      state: 'off'
    # If send notification boolean is true
    - condition: state
      entity_id: input_boolean.doorbell_person_detected_notification
      state: 'on'
  action:
    - service: shell_command.move_media_file_for_notification
    - service: notify.mobile_app_v0f9p0cww7
      data:
        message: "Person detected"
        data:
          image: "/local/media/latest.jpg"