I am having a really hard time trying to get a working automation that will show the name of the last torrent started in qbit. I have read the documentation but the action seems only half explained.
Does anyone do this and can share their yaml?
End goal is to trigger another automation if the name of the last torrent to start downloading contained ABC
There is a way to send a webhook from Qbittorrent to HA. I’ll have to wait 'til I get home to take a look at it as it’s in a batch file that automatically runs after torrent added.
OK, in Qbittorrent, Options, Downloads. Check ‘x’ “Run external program on torrent finished”, then in that field, put “C:\downloads\notify.bat %N”.
*I just thought, you probably won’t need a batch file, just put the curl command instead of the above notify.bat, but I’ve typed all this so it’s staying.
Then make that batch file “notify.bat”
In the batch file
curl -X POST -H "Content-Type: application/json" -d "{\"torrent_name\":\"%1\"}" http://[YOUR-IP]:8123/api/webhook/qbittorrent_torrent_added
Don’t forget to add your HA IP address.
This is your automation, put notifications or whatever in the actions:
alias: New Torrent Added
description: ""
triggers:
- trigger: webhook
allowed_methods:
- POST
- PUT
local_only: true
webhook_id: qbittorrent_torrent_added
conditions: []
actions:
[YOUR ACTIONS HERE]
mode: single
Thanks for all your help again. I am running qbit in a docker container on Debian.
It took some iterations, but I finally got it working. I couldn’t get a curl command to work directly in qbit, so ended up with a bash script. Even then, any _ would cause an issue for some reason.
For anyone else that might find this, the final solution for me was as follows:
In qbit, tick the run external option in downloads and add this:
/config/ha.sh "%N"
Then in the qbit config folder add the file ha.sh with the following contents:
curl -v POST -H "Content-Type: application/json" -d '{"torrent":"'"$1"'"}' http://[YOUR IP ADDRESS]:8123/api/webhook/qbittorrent_torrent_added
In HA you can then have an automation with triggers and actions like these (this one just sends the torrent’s name through to Telegram for example)
- id: '123'
alias: New Torrent Added
description: "Torrent added"
triggers:
- trigger: webhook
allowed_methods:
- POST
- PUT
local_only: true
webhook_id: "qbittorrent_torrent_added"
action:
- data:
message: "{{ trigger.json.torrent }}"
service: notify.telegram_me
mode: single