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¶m=addlogmessage&message=SabNZB Status: "+state)
#uploading values to domoticz
url = ("http://" + domoticz_host + ":" + domoticz_port + "/" + domoticz_url+ "?type=command¶m=udevice&idx=" + domoticz_sabnzb + "&nvalue=0&svalue=" + state)
urllib.urlopen(url)