home-assistant.io/source/_components/folder_watcher.markdown
Robin bc01c98712 Adds info on whitelist_external_dirs (#5213)
whitelist_external_dirs needs to be mentioned
2018-05-03 15:05:52 -04:00

2.2 KiB

layout, title, description, date, sidebar, comments, sharing, footer, logo, ha_category, ha_iot_class, ha_release
layout title description date sidebar comments sharing footer logo ha_category ha_iot_class ha_release
page Folder Watcher Component for monitoring changes within the filesystem. 2018-03-11 14:00 true false true true home-assistant.png System Monitor Local Polling 0.67

This component adds Watchdog file system monitoring, publishing events on the Home Assistant bus on the creation/deletion/modification of files within configured folders. The monitored event_type are:

  • created
  • deleted
  • modified
  • moved

Configured folders must be added to whitelist_external_dirs. Note that by default folder monitoring is recursive, meaning that the contents of sub-folders are also monitored.

To enable the Folder Watcher component in your installation, add the following to your configuration.yaml file:

{% raw %}

folder_watcher:
  - folder: /config

{% endraw %}

{% configuration %} folder: description: The folder path required: true type: string patterns: description: Pattern matching to apply required: false default: "*" type: string {% endconfiguration %}

Patterns

Pattern matching using fnmatch can be used to limit filesystem monitoring to only files which match the configured patterns. The following example shows the configuration required to only monitor filetypes .yaml and .txt.

{% raw %}

folder_watcher:
  - folder: /config
    patterns:
      - '*.yaml'
      - '*.txt'

{% endraw %}

Automations

Automations can be triggered on filesystem event data using a data_template. The following automation will send a notification with the name and folder of new files added to that folder:

{% raw %}

- action:
  - data_template:
      message: 'Created {{ trigger.event.data.file }} in {{ trigger.event.data.folder }}'
      title: New image captured!
      data:
        file: " {{ trigger.event.data.path }} "
    service: notify.pushbullet
  alias: New file alert
  condition: []
  id: '1520092824697'
  trigger:
  - event_data: {"event_type":"created"}
    event_type: folder_watcher
    platform: event

{% endraw %}