transmission: # ========================================== # --- СЕНСОРЫ ДЛЯ ПАРСИНГА ФАЙЛОВ --- # ========================================== command_line: - sensor: name: tr_file_list # Добавлена поддержка UTF-8 и правильная обработка кириллицы command: >- python3 -c 'import json, os; f="/config/tr_list_files.txt"; data={"file_list": [l.strip() for l in open(f, encoding="utf-8") if l.strip()]} if os.path.exists(f) else {"file_list": []}; print(json.dumps(data, ensure_ascii=False))' value_template: "{{ value_json.file_list | length if value_json is defined else 0 }}" json_attributes: - file_list scan_interval: 60 automation: # Обновление списка файлов в фоне - id: tr_refresh_file_list alias: "tr|refresh_file_list" mode: single trigger: - platform: time_pattern minutes: "/1" action: - service: shell_command.tr_files data: {} # ========================================== # --- КОМАНДА: ПОЛУЧИТЬ ФАЙЛЫ (/getfiles) --- # ========================================== - id: ntf_tg_tr_send_url_file_list alias: "ntf|tg|tr|send_url_file_list" trigger: - platform: event event_type: telegram_command event_data: command: '/getfiles' - platform: event event_type: telegram_command event_data: command: '/getfiles@ha_dddennnisss_bot' action: - service: telegram_bot.send_message data: # ИСПРАВЛЕНО: Для send_message нужно использовать target! chat_id: "{{ trigger.event.data.chat_id }}" parse_mode: html disable_web_page_preview: true message: > {% set base_url = "https://smb.dddennnisss.ru/files/share/downloads/" %} {% set files = state_attr('sensor.tr_file_list', 'file_list') %} {% if files is none or files | length == 0 %} 😔 Нет файлов для скачивания (Проверьте наличие файлов в /config/tr_list_files.txt) {% else %} 📥 Ссылки для скачивания: {% for file in files | reject('equalto', 'incomplete') | reject('equalto', 'unknown') %} 📄 {{ file }} {{ base_url }}{{ file | urlencode }} {% endfor %} {% endif %} inline_keyboard: - '⬇️ Меню торрентов:/tr_control' - '🔙 Главное меню:/menu_back, 🗑️ Прочитано:/menu_hide' # ========================================== # --- УВЕДОМЛЕНИЕ: СТАРТ ЗАГРУЗКИ --- # ========================================== - id: ntf_transm_torrents_start_download alias: "ntf|transm_torrents_start_download" trigger: - platform: event event_type: transmission_started_torrent action: - service: telegram_bot.send_message data: chat_id: - -1002006010424 - -1003233671944 parse_mode: html message: | ▶️ Старт загрузки торрента! 📄 Название: {{ trigger.event.data.name }} inline_keyboard: - '⬇️ Статус торрентов:/tr_control' - '🔙 Главное меню:/menu_back, 🗑️ Прочитано:/menu_hide' # ========================================== # --- УВЕДОМЛЕНИЕ: ОКОНЧАНИЕ ЗАГРУЗКИ --- # ========================================== - id: ntf_torrents_complect_download alias: "ntf|torrents_complect_download" trigger: - platform: event event_type: transmission_downloaded_torrent action: - service: telegram_bot.send_message data: chat_id: - -1002006010424 - -1003233671944 parse_mode: html message: | ✅ Загрузка завершена! 📄 Название: {{ trigger.event.data.name }} inline_keyboard: - '📥 Получить ссылки:/getfiles' - '⬇️ Статус торрентов:/tr_control' - '🔙 Главное меню:/menu_back, 🗑️ Прочитано:/menu_hide' # ========================================== # --- КОМАНДА: ДОБАВИТЬ ТОРРЕНТ (/add) --- # ========================================== - id: tg_add_torrents_transm_magnet alias: "tg|add_torrents_transm_magnet" initial_state: true trigger: - platform: event event_type: telegram_command event_data: command: '/add' - platform: event event_type: telegram_command event_data: command: '/add@ha_dddennnisss_bot' action: - variables: torrent_link: "{{ trigger.event.data.args | join(' ') }}" - choose: # Если ссылку не передали - conditions: "{{ torrent_link | length == 0 }}" sequence: - service: telegram_bot.send_message data: chat_id: "{{ trigger.event.data.chat_id }}" parse_mode: html message: "⚠️ Ошибка: Вы не указали ссылку.\nИспользуйте формат:\n/add magnet:?xt=urn:..." default: - service: transmission.add_torrent data: torrent: "{{ torrent_link }}" entry_id: "01JJCHRKJJ0GE2K3N9G4K20CB6" download_path: "" - service: telegram_bot.send_message data: chat_id: "{{ trigger.event.data.chat_id }}" parse_mode: html message: | 🔄 Пытаюсь добавить торрент: {{ torrent_link | truncate(100, true, '...') }} inline_keyboard: - '⬇️ Статус торрентов:/tr_control' - '🔙 Главное меню:/menu_back, 🗑️ Прочитано:/menu_hide'