먼저 설정/시스템/저장소에서 네트워크 폴더를 마운트.
설정/기기 및 서비스/통합구성요소 추가하기에서 Folder Watcher선택하고 폴더와 모니터링할 파일 패턴 설정.
그리고 특정패턴의 파일 추가나 변경시 실행할 자동화 구성.
특정패턴의 파일이 생성됐을 때 자동화
automations.yaml
- id: system-download
alias: system-download
mode: single
triggers:
- trigger: state
entity_id: event.folder_watcher_share_downloads
to: ~
conditions:
- condition: template
value_template: "{{ trigger.event.data.event_type == 'closed' }}"
actions:
- action: switch.turn_off
entity_id: switch.nas
삼바 디렉토리는 로컬에서 삼바 디렉토리로 파일변경 작업은 감지되는데 다른 시스템에서 파일변경 작업은 haos에서 감지 안됨. 로컬 폴더나 nfs 폴더는 위 자동화가 문제없이 실행됨.
삼바로 마운트된 폴더는 command_line에 폴더를 모니터링하는 센서를 생성해 자동화.
command_line.yaml
- sensor:
name: 'Downloads File Check'
command: ls /share/Downloads | grep -E '\.mp4$' | wc -l
scan_interval: 60
automations.yaml
- id: system-download
alias: system-download
mode: single
triggers:
- trigger: state
entity_id: sensor.downloads_file_check
conditions:
- condition: template
value_template: "{{ states('sensor.downloads_file_check') | int > 0 }}"
actions:
- action: switch.turn_off
entity_id: switch.nas