Page 1 of 1

SabNZB Status

Posted: Tuesday 08 September 2015 19:58
by galadril
But with these script, you get the status of your sabNZB server

Prepare Domoticz
If you don't know how to create a virtual sensor chances are you have never done this before.
- Go to "Hardware"
- Fill in the name field with a desired name (like "Virtual")
- Choose for type the "Dummy, does nothing, use for virtual switches only"
- Click on "Add"
- The added hardware is now added to the hardware list. In the same row there is a "Create virtual sensor" button shown. Click on it.


Hardware
Now you are ready to create virtual devices.
- Go to "Hardware"
- Press "Create virtual sensor".
- Fill in the name field with a name like 'SabNZB'


Devices
Now you are ready to create a virtual device.
- Go to "Hardware"
- Press "Create virtual sensor".
- Fill in the name field with a name like 'SabNZB'


SabNZB script
Config the parameters in the Ginlong script:

Code: Select all

#config
sabnzb_key 			= '' 
sabnzb_server 		= '' 
sabnzb_port			= ''
	
#domoticz settings
domoticz_host      	= ''
domoticz_port      	= ''
domoticz_url       	= 'json.htm'
domoticz_sabnzb		= ''

Put the script under /domoticz/scripts and make the script executable:
"sudo chmod +x /home/pi/domoticz/scripts/sabnzb.py"


Test
Run the script by calling:
"sudo python /home/pi/domoticz/scripts/sabnzb.py"


Create the Cronjob
Now all ingredients are available to read the data from the portal and insert them into Domoticz.
- execute "sudo crontab -e"
- add the following line "*/5 * * * * /home/pi/domoticz/scripts/sabnzb.py"
- exit crontab. Now everything should be working for you.

Scripts
sabnzb.py

Code: Select all

#!/usr/bin/python
import urllib, urllib2, hashlib
from xml.etree import ElementTree as ET

#config
sabnzb_key 			= '' 
sabnzb_server 		= '' 
sabnzb_port			= ''
	
#domoticz settings
domoticz_host      	= ''
domoticz_port      	= ''
domoticz_url       	= 'json.htm'
domoticz_sabnzb		= ''

#building url
requestURL = 'http://'+sabnzb_server+':'+sabnzb_port+'/sabnzbd/api?mode=qstatus&output=xml&apikey='+sabnzb_key

#call sabnzb api
returnvalue = urllib.urlopen(requestURL)
root = ET.parse(returnvalue).getroot()
state = root.find('state').text

print 'SabNZB Status: '+state
urllib.urlopen("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=addlogmessage&message=SabNZB Status: "+state)

#uploading values to domoticz
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command&param=udevice&idx=" + domoticz_sabnzb + "&nvalue=0&svalue=" + state)
urllib.urlopen(url)

Re: SabNZB Status

Posted: Tuesday 08 September 2015 23:50
by Raspberry Piet
Sabnzbd my favorite!
I had a bash script once to get data like this into Domoticz. (i lost it)
Tried your script, and works. (use a virtual text sensor)

We can use [url]http://ip:port/sabnzbd/api?mode=queue&output=xml&apikey=xxxxxxxx[/url] to get more advanced data from Sabnzbd.

Re: SabNZB Status

Posted: Tuesday 08 September 2015 23:56
by galadril
Raspberry Piet wrote:We can use [url]http://ip:port/sabnzbd/api?mode=queue&output=xml&apikey=xxxxxxxx[/url] to get more advanced data from Sabnzbd.
You;re correct, i'll add some extra data to the scripts!
Thanks :)

Re: SabNZB Status

Posted: Friday 11 September 2015 16:15
by remb0
nice scripts. nzbget performance is much better on a synology so I don't use sabnzbd anymore..
anyone such nice scripts of nzbget?

Re: SabNZB Status

Posted: Friday 11 September 2015 17:56
by Egregius
Really? I like the way sabnzbd works. Nothing to worry about.
I do have quite a strong Syno, maybe that's way I don't notice it.

Re: SabNZB Status

Posted: Friday 11 September 2015 19:04
by galadril
I really like sabnzb, but Ill check nzbget to create a script

Re: SabNZB Status

Posted: Saturday 14 November 2015 13:40
by dutchnld
Hi thanks for your instructions!

I got the script working. At least when I run the test I received the SabNZBD status. :)

But I'm not so sure what type of virtual device I should use after clicking 'create virtual sensor'?

And what's the name of this variable? -> domoticz_sabnzb = ' '
Should that be the ID of the virtual sensor I have to create?

I'm quite new to crontab, when I edit this I read this example: 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
In your instructions it starts with a '/'. Is that correct? -> /5 * * * * /home/pi/domoticz/scripts/sabnzb.py

Re: SabNZB Status

Posted: Saturday 14 November 2015 13:54
by Raspberry Piet
dutchnld wrote:Hi thanks for your instructions!

I got the script working. At least when I run the test I received the SabNZBD status. :)

But I'm not so sure what type of virtual device I should use after clicking 'create virtual sensor'?
create a virtual text sensor
dutchnld wrote:And what's the name of this variable? -> domoticz_sabnzb = ' '
Should that be the ID of the virtual sensor I have to create?
yes idx number of the virtual text sensor you just made

dutchnld wrote:I'm quite new to crontab, when I edit this I read this example: 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
In your instructions it starts with a '/'. Is that correct? -> /5 * * * * /home/pi/domoticz/scripts/sabnzb.py
I use this for creating cronjobs : http://www.corntab.com/pages/crontab-gui

Re: SabNZB Status

Posted: Saturday 14 November 2015 15:11
by dutchnld
Thanks! I got it working now.

For the cron part I checked the log using 'grep CRON /var/log/syslog'
and got this error 'No MTA installed, discarding output'

I fixed that by using: sudo apt-get install postfix

Re: SabNZB Status

Posted: Wednesday 18 November 2015 22:36
by BazemanKM
Had to enter an extra s in the URL, because i was using https:

#building url
requestURL = 'https://'+sabnzb_server+':'+sabnzb_port+'/sabnzbd/api?mode=qstatus&output=xml&apikey='+sabnzb_key