Add event entities to Folder watcher (#32611)

* Add entities to Folder watcher

* Address comments

* tiny tweaks

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
G Johansson 2024-05-27 09:23:32 +02:00 committed by GitHub
parent f2ffeb1d66
commit b1bb66b32d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,11 +7,15 @@ ha_iot_class: Local Polling
ha_config_flow: true ha_config_flow: true
ha_release: 0.67 ha_release: 0.67
ha_quality_scale: internal ha_quality_scale: internal
ha_platforms:
- event
ha_domain: folder_watcher ha_domain: folder_watcher
ha_integration_type: integration ha_integration_type: integration
--- ---
The **Folder watcher** {% term integration %} adds [Watchdog](https://pythonhosted.org/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: The **Folder watcher** {% term integration %} adds [Watchdog](https://pythonhosted.org/watchdog/) file system monitoring.
It creates event entities for these monitored event types:
- `closed` - `closed`
- `created` - `created`
@ -30,7 +34,7 @@ As example to monitor specific file, as example YAML and text-files add `*.yaml`
## Automations ## Automations
The elements the events contain are: The attributes the event entities contain are:
- `event_type`: matching the `event_type` of the filter (one of `created`, `moved`, `modified`, `deleted`, `closed`) - `event_type`: matching the `event_type` of the filter (one of `created`, `moved`, `modified`, `deleted`, `closed`)
- `path`: The full path to the file (e.g. "/hello/world.txt") - `path`: The full path to the file (e.g. "/hello/world.txt")
- `file`: The name of the file (e.g. "world.txt") - `file`: The name of the file (e.g. "world.txt")
@ -41,7 +45,7 @@ When the `event_type` is `moved`, the file details are for the source file and d
- `dest_file`: The name of the moved file (e.g. "world.txt") - `dest_file`: The name of the moved file (e.g. "world.txt")
- `dest_folder`: The folder moved path (e.g. "/hello") - `dest_folder`: The folder moved path (e.g. "/hello")
Automations can be triggered on filesystem event data using a template. The following automation will send a notification with the name and folder of new files added to that folder: Automations can be triggered on file system events data using a template. The following automation will send a notification with the name and folder of new files added to that folder:
{% raw %} {% raw %}
@ -50,17 +54,15 @@ Automations can be triggered on filesystem event data using a template. The foll
automation: automation:
 alias: "New file alert"  alias: "New file alert"
trigger: trigger:
  platform: event   platform: state
  event_type: folder_watcher entity_id: event.created
  event_data:
     event_type: created
action: action:
  service: notify.notify   service: notify.notify
  data:   data:
    title: New image captured!     title: New image captured!
    message: "Created {{ trigger.event.data.file }} in {{ trigger.event.data.folder }}"     message: "Created {{ trigger.to_state.attributes.file }} in {{ trigger.to_state.attributes.folder }}"
    data:     data:
      file: "{{ trigger.event.data.path }}"       file: "{{ trigger.to_state.attributes.file }}"
``` ```
{% endraw %} {% endraw %}