SabNZBD Rest Sensor Help

Hiya Wonderful people. I was wondering if anyone can help me out with a Rest sensor at all.

I am using one to pull up my recent SabNZBD downloads,

- platform: rest
  resource: http://192.168.2.1:8080/sabnzbd/api?output=json&apikey=redacted&mode=history&start=START&limit=10
  name: 1
  method: GET
  value_template: '{{ value_json.history.slots[0].name }}'

but I would like to try and strip down the end of the filename and remove the parts I dont need so it sits better in HA. The results I get are something like,

Linux.ISO.debian-9.0.0-amd64-xfce-CD-1

Would it be possible to say removed everything after something like “-xfce*” so it would just leave, `Linux.ISO.debian-9.0.0-amd64.

Is there some kind of template to remove everything after a set value of X, like everything after “-amd64*”

Many thanks in advance.

you could look at switching to a command line sensor and piping the curl output through sed.

As per your example, the sed command would be along the lines of

sed -e 's/\-xfce.*//'

Which returns the ouptut:

Linux.ISO.debian-9.0.0-amd64

With the full command for the command line sensor looking like:

command curl 2>/dev/null http://192.168.2.1:8080/sabnzbd/api?output=json&apikey=redacted&mode=history&start=START&limit=10 | sed -e 's/\-xfce.*//'

But if the downloads are gonna be all sorts of different file names, you could find yourself in regex hell quite quickly.

1 Like

Thank you for the reply @matty87a.

Tried your code out,

- platform: command_line
  name: 1
  command: "command curl 2>/dev/null http://192.168.2.1:8080/sabnzbd/api?output=json&apikey=<redacted>&mode=history&start=START&limit=10 | sed -e 's/\-xfce.*//'"

but it seems to be throwing up an error, looks like the API key isn’t getting passed through in the curl command I think.

pi@hassbian:~ $ command curl 2>/dev/null http://192.168.2.1:8080/sabnzbd/api?output=json&apikey=<redacted>&mode=history&start=START&limit=10 | sed -e 's/\-xfce.*//'
[1] 12334
[2] 12335
[3] 12336
[4] 12338
[2]   Done                    apikey=<redacted>
[3]-  Done                    mode=history
[4]+  Done                    start=START
pi@hassbian:~ $ {"status": false, "error": "API Key Required"}pi@hassbian:~ $ {"status": false, "error": "API Key Required"}

and then I have to control C to get out of it.

Dont suppose you have an idea’s at all.

Many thanks in advance.

Worked for me using my own API key so im not sure.

you may also need to employ grep to isolate the slots currently downloading when using just a curl:

$ curl 2>/dev/null "http://127.0.0.1:8080/api?mode=queue&output=json&apikey=2faacb89addxxxxxxx0c540804ae4af&mode=history&start=START&limit=10" | jq . | grep filename 
"filename": "Download.mkv",

(n.b - jq is used purely to tidy up the json)