Folder watcher (Watchdog) component

Quite a lot of applications create temporary files during normal operation, this could be causing all the triggers. You could us the patterns variable to try limit the number of triggers

How dā€™you mean? isnā€™t the trigger caused by the file referred to as ā€œtrigger.event.data.pathā€? If so, surely any temporary file would be the one that is sent, not the one I copied?

I tried to add a shell command straight after in the automation to delete the file. This resulted in multiple copies of half a file coming through on Telegram (bottom half of image blank) and then an error in the logs saying it couldnā€™t send because the file didnā€™t exist.

Oh I think I got your issue confused with another on this thread. You can disable automations temporarily (there is a thread on the forums somehwere), but my experience is that getting the timing just right is quite tricky

Should imagine it is. It still doesnā€™t explain why I get the same image multiple times though; the fact is that the jpg folder watcher is looking for gets created once, so why should I get repeated triggers?!

Something not right.

Just tried the ā€˜Modifiedā€™ event type and if I rename a file thatā€™s already in there I get one message, so expected behaviour. If I leave it set to modified and upload a file though the same problem occurs.

Tried Samba, FTP connection from PC and from camera and still getting multiple triggers. Strange thing is thereā€™s no pattern to how many triggers I get. Sometime 4-5, others a few hundred.

I had similar problem due to ā€œtempā€ file triggering before complete file was generated.
I just added delay of couple of seconds to my automation.

Got it working! Turns out itā€™s very funny about the way the YAML is laid out.

Swapping:

  trigger:
  - event_data:
      event_data:
        event_type: created
    event_type: folder_watcher
    platform: event

for:

  trigger:
    platform: event
    event_type: folder_watcher
    event_data:
      event_type: created

Did the trick. It turns out that if you donā€™t specify an event type to trigger on it fires on ANY event. Whilst I specified a type originally, my YAML wasnā€™t quite right so the event type Iā€™d specified was ignored and default behaviour prevailed.

1 Like

Where did you get the first version from? The second is in the docs

I know. I copied from the docs in the first place but dipped in with the GUI to make a couple of quick changes to the action. The GUI rearranged it all as it does which broke it. I didnā€™t think it would matter but it obviously does!

1 Like

Iā€™d like to check something regarding the documentation that isnā€™t quite clear to me: Is the folder option relative to the HA installationā€™s path, or is it an absolute path? As an example, if I set - folder: /tmp/ and /tmp/ is world readable, should/would it work?

And for me relevant close to this is if itā€™s possible to watch a folder outside HA, like on a usb disk on a PC or NAS via Samba and smb: function?

cannot watch external locations, although you could install home assistant on the external location and use it

1 Like

Thats an idea of course. Thanks!!
I did find this software https://directorymonitor.com/ so I will try that first :slight_smile:

Sounded interesting until I saw $159 USD for 1 machine license :money_mouth_face:

They can for sure keep track of directories (even in the free version) but I have a need to keep track of a COPY being ready and that they cant do. Only create and the other things, but not Copy. :frowning:

@robmarkcole Looks like a cool component, but Iā€™m getting errors when setting this up. The config comes up clean when I check config via Server Controls.

Here are the log errors and my configs:

Logs:

2020-09-08 10:09:09 ERROR (SyncWorker_2) [homeassistant.components.folder_watcher] folder /share is not valid or allowed
2020-09-08 10:09:10 INFO (MainThread) [homeassistant.setup] Setup of domain folder_watcher took 0.6 seconds
2020-09-08 10:09:10 ERROR (MainThread) [homeassistant.setup] Setup failed for folder_watcher: Integration failed to initialize.

"/share" directory added to [allowlist_external_dirs:

homeassistant:
  name: Home
  latitude: ##.######
  longitude: -##.######
  elevation: 72
  unit_system: imperial
  time_zone: America/New York
  external_url: "https://########################.ui.nabu.casa/lovelace/home"
  internal_url: "http://###.###.#.###:8123"
  allowlist_external_dirs:
    - /share

Basic config:

folder_watcher:
  - folder: /share

Ah dockerā€¦ The error is folder /share is not valid or allowed
Recommend some experimentation

@robmarkcole ok - so this folder is located at //192.168.1.237/share (my HA IP), along with my /config folder and a few others I canā€™t recall - /add ons I think?. I have swapped out /share with /config and get the same results - no dice. What sort of experimentation would you recommend?

I think the issue is that /share is not accessible to the home assistant user. Better to create a subdirectory in /config and watch that as per the docs example. So you will have config like:

folder_watcher:
  - folder: /config/my_watched_dir

@robmarkcole Unfortunately, no dice :thinking:

I updated the config, restarted HA from the UI, and for good measure, I also restarted the VM to make sure the allowlist_external_dirs gets updated, and I still get the same error in the logs:

2020-09-09 15:21:33 ERROR (SyncWorker_38) [homeassistant.components.folder_watcher] folder /config/folder_watcher is not valid or allowed
2020-09-09 15:21:34 INFO (MainThread) [homeassistant.setup] Setup of domain folder_watcher took 0.1 seconds
2020-09-09 15:21:34 ERROR (MainThread) [homeassistant.setup] Setup failed for folder_watcher: Integration failed to initialize.