Page 1 of 1

Script to sleep PC if Sabnzbd queue is empty

Posted: May 21st, 2009, 7:29 am
by relman
I wrote this as I want my PC to come on at 4am check for downloads , download them and then go back to sleep. As sometimes there is more to download then other times there was no sure way of specifying a time to shut it down unless I said ok well max time will be 4 hours so shutdown at 8am, however sometimes it may finish in an hour so 3 hours wasted. So I wrote this VBScript to check the queue and if 0 to put PC to sleep. This is then ran as a scheduled task and repeated for 4 hours.

Code: Select all

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("http://localhost:port/api?mode=qstatus&output=xml&ma_username=<username>&ma_password=<password>&apikey=<apikey>")
strQuery = "/queue/noofslots"
Set colItem = xmlDoc.selectNodes(strQuery)
For Each objItem in colItem
IF objitem.text = "0" Then
set objShell = wscript.createObject("wscript.shell") 
objShell.Run "%comspec% /c rundll32 powrprof.dll,SetSuspendState"
Set objNet = Nothing         
Else
End If
next
An easy way to wake a PC from sleep is to make a scheduled task, check this link out. http://on10.net/blogs/sarahintampa/Make ... matically/

Re: Script to sleep PC if Sabnzbd queue is empty

Posted: May 21st, 2009, 11:30 am
by doubledrat
sorry if I've missed the point, but doesn't SABNZBD do this for you?  In the SMPL layout (and maybe others) in the queue section there's a

"on queue finish" option which can be used to shutdown, suspend, run scripts etc.

Re: Script to sleep PC if Sabnzbd queue is empty

Posted: June 7th, 2009, 3:17 pm
by relman
for me the point is my PC gets powered up at say 5:30am it grabs the lowdef copies of tv shows then and sometimes can take till 12pm to pick up highdef. So my queue could empty before hand. Ok I could just have a script runs which runs the API command to set end of queue to sleep but heres the point.

That is only useful if I have items in my queue. I don't wanna shutdown too early but then again at 12pm there might be nothing to download so a script which checks if my queue is empty works best. I did try setting end of queue to shutdown but you have to have something download first to then empty the queue first. Just setting it to that when the queue is already empty will not work.

I hope that explains my need for the script i wrote. If no one else needs it , well I am just sharing.

Re: Script to sleep PC if Sabnzbd queue is empty

Posted: November 24th, 2009, 11:01 am
by spammy
I'm actually having sleep problems with sabnzbd as per http://forums.sabnzbd.org/index.php?topic=2974.0 so taking power management out of its hands is quite useful for me. Thanks for the script!