Today, I’m going to show you something really cool and useful: the Folder Watcher integration in Home Assistant. If you’ve never heard of it, don’t worry—I’ll explain everything in simple terms.
Table of Contents
What is Folder Watcher?
Folder Watcher is a feature in Home Assistant that monitors files in certain folders. Whenever a file is created, deleted, modified, or moved in those folders, Folder Watcher will notice and can trigger a Home Assistant automation.
Setting Up Folder Watcher
Prefer a video?
No problem, here is my video tutorial:
Step 1: Allow Home Assistant to Access Folders
Before you can use Folder Watcher, you need to tell Home Assistant which folders to monitor. These folders must be added to allowlist_external_dirs
, which is like giving Home Assistant permission to access these folders.
Step 2: Using the File Editor Add-On
Here’s how to set it up:
- Install the File Editor Add-On:
- Go to the Add-On Store in Home Assistant.
- Start the add-on and optionally enable the sidebar option for easy access. If you don’t have the Add-On Store, you’re likely using Home Assistant Container or Core. In that case, use a text editor to edit your configuration file directly.
- Search for “File Editor” and click “Install”.
- Edit the Configuration File:
- Open the File Editor and browse to your configuration file (
configuration.yaml
). - Add the folders you want to monitor to the
allowlist_external_dirs
section.
- Open the File Editor and browse to your configuration file (
homeassistant:
allowlist_external_dirs:
- /config/subscribe
Be careful with indentation, as YAML files are sensitive to it.
Step 3: Create the Monitored Folder
In the File Editor, create the folder you want to monitor. For example, create a folder named subscribe
under the Home Assistant /homeassistant directory.
Have in mind that the /homeassistant and /config folders are some kind of aliases. You have to create your folders inside /homeassistant folder ( ex. /homeassistant/YOUR_FOLDER ), but you have to refer to them as /config/YOUR_FOLDER. Go figure…
Step 4: Restart Home Assistant
After making these changes, restart Home Assistant to apply the new settings.
Adding the Folder Watcher Integration
Now that your folders are set up, you can add the Folder Watcher integration:
- Navigate to Integrations:
- Press the “c” button and type “Integrations”, then select “Navigate Integrations”.
- Click on “Add Integration” and search for “Folder Watcher”.
- Configure Folder Watcher:
- Select the folder you want to watch (ex.
/config/subscribe
). - You can add patterns or filters to specify which files to monitor. For example, using
*.txt
will monitor only text files. If you want to monitor everything, leave the default pattern (use*
)
- Select the folder you want to watch (ex.
Creating Automations with Folder Watcher
Now, let’s create an automation using Folder Watcher:
- Create a New Automation:
- Press the “c” button, type “Automations”, and select “Navigate Automations”.
- Click on “Create Automation” and then “Create New Automation” to choose an empty template.
- Use a Predefined Example:
- Get the YAML code from the example automation below.
- Paste this code into your new automation in Home Assistant, making any necessary adjustments.
Here’s an example of a simple automation:
alias: New file alert
description: ""
trigger:
- platform: event
event_type: folder_watcher
event_data:
event_type: created
action:
- service: notify.telegram
data:
title: New image captured!
message: Created {{ trigger.event.data.file }} in {{ trigger.event.data.folder }}
data:
file: "{{ trigger.event.data.path }}"
- service: persistent_notification.create
metadata: {}
data:
message: Created {{ trigger.event.data.file }} in {{ trigger.event.data.folder }}
- Customize the Automation:
- Save and Test:
- Save the automation and restart Home Assistant to activate it.
- Test the automation by creating a file in the
subscribe
folder. You should receive a notification.
Home Assistant Webinar?
You’ve successfully set up the Folder Watcher integration in Home Assistant and created an automation to notify you of file changes.
Feel free to join my free Home Assistant webinar.
Thanks for reading, and until next time!