Notification when a new file appear on shared folder

Hi.
When a new file appear\modified on shared folder I want to get notification with information of the file name.
I have mounted the shared folder to HA.
But the file watcher component cannot watch after files that was not edited by host.
Is there any way to do it?

The HA file and folder integrations are extremely limited. I had to use NodeRED.

I have done it via HA.

I have wrote /config/shell_command/watcher.sh

#!/bin/bash

#token for HA API stored in /config/secrets.yaml
token=$(grep 'api_token:' secrets.yaml | cut -c 12-)

files=$(find /media/movies -mmin -5 -type f ! -name ".*" | sort -n | tail -1)

curl -s -o /dev/null --show-error --fail \
 -X POST -H "Authorization: Bearer $token" \
 -d "{\"state\": \"$files\", \"attributes\":{\"friendly_name\":\"New file appear\"}}" \
 http://localhost:8123/api/states/sensor.has_new_file

Added to configuration.yaml

shell_command:
  get_latest_file: bash /config/shell_command/watcher.sh

Added to automation.yaml

- id: '1678800770219'
  alias: Check newest file
  description: ''
  trigger:
  - platform: time_pattern
    seconds: /30
  condition: []
  action:
  - service: shell_command.get_latest_file
    data: {}
  mode: single
- id: '1678808587026'
  alias: Notify new file
  description: ''
  trigger:
  - platform: template
    value_template: '{{states(''sensor.has_new_file'') != ''''}}'
  condition: []
  action:
  - service: notify.telegram_bot
    data:
      message: New file - {{ states.sensor.has_new_file.state }}
      data:
        parse_mode: html
  mode: single
1 Like