Configuring Agent DVR to save videos to an FTP server + deleting files using Delete files in Home Assistant
- We put Agent DVR
- We put the addon FTP
- Setting up integration Delete files in Home Assistant
- Configure Folder Watcher
- Configure Folder Sensor
1) We put the FTP addon in the Home Assistant and specify in the configuration
port: 21 # you can specify any port from 0 to 65535
data_port: 20
banner: Welcome to the Hass.io FTP service.
pasv: true
pasv_min_port: 30000
pasv_max_port: 30010
pasv_address: ''
ssl: false
certfile: fullchain.pem
keyfile: privkey.pem
implicit_ssl: false
max_clients: 2
users:
- username: login
password: 123456
allow_chmod: true
allow_download: true
allow_upload: true
allow_dirlist: true
addons: false
backup: false
config: false
media: true
share: false
ssl: false
2) In the Media folder, create the AgentDVR folder, where photos and videos will be saved
/media/AgentDVR/
3) In the Agent DVR settings, enable FTP and specify the path to /media/AgentDVR/
4) In the camera settings, in the FTP section, we turn on the choice of what you need to save to a folder /media/AgentDVR/
We specify anything as a name and save the settings
video_{0:dd-MM-yyyy_HH-mm-ss_fff}
5) Setting up integration Delete files in Home Assistant
After installing the Delete files in Home Assistant integration and restarting the Home Assistant, then in configuration.yaml add a line and reload the Home Assistant
delete:
If everything is done correctly, then we will have a service
delete.files_in_folder
Creating a script to delete files in the /media/Agent DVR/ folder. Where I indicated that we delete only .mp4 and .jpg and delete without specifying the time. But you can specify the time and the time is specified in seconds.
alias: 'Camera in hall: Deleting video files in the Agent DVR folder'
sequence:
- service: delete.files_in_folder
data:
folder: /media/AgentDVR/
time: 0
only_extensions:
- .mp4
- .jpg
mode: single
icon: mdi:delete-variant
6) Setting up Folder Watcher and Folder Sensor
We add lines to the configuration. Folder Watcher monitors the folder and will send events to the Home Assistant, and the sensor will show how much space is occupied
folder_watcher:
- folder: /media/AgentDVR/
patterns:
- '*.mp4'
homeassistant:
media_dirs:
media: "/media"
sensor:
- platform: folder
folder: /media/AgentDVR/
After creating a sensor for the Agent DVD folder, the sensor.agentdvr sensor should appear. The sensor can be found in the developer panel
Текст на русском (Text in Russian)
Настройка Agent DVR для сохранения видеозаписей на FTP сервер + удаление файлов с помощью Delete files in Home Assistant
- Ставим Agent DVR
- Ставим аддон FTP
- Ставим интеграцию Delete files in Home Assistant
- Настроим Folder Watcher
- Настроим Folder Sensor
1) Ставим в Home Assistant аддон FTP и в конфигурации указываем
port: 21 # порт можно указать любой от 0 до 65535
data_port: 20
banner: Welcome to the Hass.io FTP service.
pasv: true
pasv_min_port: 30000
pasv_max_port: 30010
pasv_address: ''
ssl: false
certfile: fullchain.pem
keyfile: privkey.pem
implicit_ssl: false
max_clients: 2
users:
- username: login
password: 123456
allow_chmod: true
allow_download: true
allow_upload: true
allow_dirlist: true
addons: false
backup: false
config: false
media: true
share: false
ssl: false
2) В папке Media создаем папку AgentDVR, куда будут сохраняться фото и видео
/media/AgentDVR/
3) В настройках Agent DVR включаем FTP и указываем путь к /media/AgentDVR/
4) В настройках камеры, в разделе FTP включаем на выбор, что нужно сохранять в папку /media/AgentDVR/
В качестве имени указываем что угодно и сохраняем настройки
video_{0:dd-MM-yyyy_HH-mm-ss_fff}
5) Ставим интеграцию Delete files in Home Assistant
После того, как установили интеграцию Delete files in Home Assistan и перезагрузили Home Assistant, то в configuration.yaml добавляем строчку и повторно перезагружаем Home Assistant
delete:
Если все сделано правильно, то у нас появится служба
delete.files_in_folder
Создаем скрипт на удаление файлов в папке /media/AgentDVR/. Где я указал, что удаляем только файлы .mp4 и .jpg и удалять без указания времени. Но можно указать время и время указывается в секундах.
alias: 'Камера в коридоре: Удаление видеофайлов в папке AgentDVR'
sequence:
- service: delete.files_in_folder
data:
folder: /media/AgentDVR/
time: 0
only_extensions:
- .mp4
- .jpg
mode: single
icon: mdi:delete-variant
6) Настраиваем Folder Watcher и Folder Sensor
В конфигурацию добавляем строчки. Folder Watcher следит за папкой и будет слать в Home Assistant события, а сенсор покажет сколько места занято
folder_watcher:
- folder: /media/AgentDVR/
patterns:
- '*.mp4'
homeassistant:
media_dirs:
media: "/media"
sensor:
- platform: folder
folder: /media/AgentDVR/
После создания сенсора для папки AgentDVR должен появиться сенсор sensor.agentdvr. Сенсор можно найти в панели разработчика