Addon to wakeup and shutdown/suspend XBMC when using TVHeadend
#1
Hi there, i've created an addon that will suspend/wakeup xbmc for tvheadend recordings, and i'm wondering where i should share it... i tried putting it in this post, but there was too many characters... i looked at the wiki, but couldnt immediately figure out how to create a page...

thoughts? or maybe noone is interested?

Nathan
Reply
#2
if you don't want to do the obvious thing and host it in a scm somewhere, use a pastebin site.
Reply
#3
Thumbs Up 
Hi Nathan,
Is the addon related to the Python script you wrote?
I tried the script, it was pretty cool and I'd love to test your addon.
Hooman
Reply
#4
Hi there, yes the python script i posted somewhere earlier was a first pass, but that script was not integrated as an addon (no xbmc gui stuff). I'm trying to figure out the googlecode thing, but dont know svn, so it may take a little time. Is there an easier scm (I had to google what that meant Smile) than googlecode where i can just dump the source files? Or maybe a googlecode/svn for dummies tutorial.... theres only about 5-7 files, so its mot a huge amount of code...
Reply
#5
I don't think you have to check in your code.
According to this, you should be able to upload your packages in the Downloads tab:
http://code.google.com/p/support/wiki/GettingStarted

There's sourceforge too, but I believe Google code is more popular these days.
Reply
#6
I have started puuting the code up at googlecode
http://code.google.com/p/pvruptime/downloads/list

Theres no real outline of how to make it work... but the files are there.... i'll try getting some documentation together shortly...

NAthan
Reply
#7
Hi Nathan,

I'm going to give this a try tonight - I should be able to figure out where each file needs to go to get it working, but would still appreciate any documentation you may already have...

Cheers,
Adam.

**************
Never mind - just read the readme more closely and it clearly shows where each file needs to live, should be pretty straight forward to test.
Reply
#8
good luck, let me know if you have any problems... it's been working fine on my ion330, with tvheadend, and harmony remote... I have changed a value in the default.py file to increase the time difference calculation to 60 seconds from 30... sometimes the wakeup is > 30 seconds from what gets set in ACPI..

Let me know how you go...

Cheers,

Nathan
Reply
#9
Hi Nathan,

Ok, installed it last night, but not quite running right. Few minor issues to get it running (wrong indentation on line 60 - in default.py from memory), had to set tvheadend password as appropriate (is hardcoded in checkRecording function), set write/execute permissions where required to allow upload of files and to create the log file, but nothing too tricky.

However, when the script runs, I just get the message 'Determining recording status....' and the 2 buttons to choose from - return back to XBMC works as expected, but the 'Shutdown XBMC' button gave me the message 'Are you sure you want to shutdown with active recordings' even though I didn't have any recordings active or scheduled.

I tried setting up a recording (both running at the time and one scheduled in a few hours time), but the prompts never changed. If I select the button to go ahead and shutdown xbmc despite an active recording (even if there isn't really an active recording), it just returns me back to xbmc regardless.

Looking in the checkRecording function, none of the messages to indicate that the system is currently recording, or has an upcoming recording ever get written to the logfile, or displayed on screen. The logfile just fills with 'starting the process' 8 times over (I tried clearing it).

I started mucking around last night trying to debug by writing something else to screen or the logfile and see where the script is getting stuck, but I've never played with python before (though I used to code in php years ago as a web develoepr) and I ran out of time to keep playing with it.

Any tips on what to try before I keep fumbling my way through?

Cheers,
Adam.
Reply
#10
i'd never played with python before this either Smile
If you could post your tvheadend status.xml, as i'm pretty sure my logic for determining recording status is not right... it works for me, but its not 100% that much we know.

If I dont have a recording it is like this
Code:
<currentload>
<recordings>
<recording>
<next>2058</next>
</recording>
</recordings>
<subscriptions>0</subscriptions>
</currentload>

if i do have a recording it is like
Code:
<currentload>
<recordings>
<recording>
<start>
<date>2011/02/04</date>
<time>06:29</time>
<unixtime>1299191395</unixtime>
</start>
<stop>
<date>2011/02/04</date>
<time>06:58</time>
<unixtime>1299193125</unixtime>
</stop>
<title>Digimon Data Squad</title>
<status>Recording</status>
</recording>
</recordings>
<subscriptions>1</subscriptions>
</currentload>

What does yours look like...?

The "Shutdown XBMC" option doesnt do anything yet, not sure if it is needed either.

Logging is not complete either, i just had it in some places to get it wot work... most everything needs improvement, so thanks for your feedback! Smile

Nathan
Reply
#11
ok, only just got a chance to have a look at this again... My status.xml looks like this with no recordings and nothing scheduled:

Quote:<?xml version="1.0"?>
<currentload>
<recordings>
</recordings>
<subscriptions>0</subscriptions>
</currentload>

and here's what it looks like recording a program right now and with another program scheduled to record shortly:

Quote:<?xml version="1.0"?>
<currentload>
<recordings>
<recording><start><date>2011/02/08</date><time>00:07</time><unixtime>1299514020</unixtime></start><stop><date>2011/02/08</date><time>01:02</time><unixtime>1299517320</unixtime></stop><title>Super Rugby Extra Time</title><status>Recording</status></recording>
</recordings>
<subscriptions>1</subscriptions>
</currentload>

Same format as yours by the looks of things... Maybe I'm not understanding the intended functionality correctly either. When the script runs, should the resultant screen stay there for a certain timeout period before it shuts down (assuming no recordings or upcoming recordings in the next 10 mins), or should you see the updated message indicating a shutdown and the system suspend straight away?

Cheers,
Adam.

-----------------------------------------------------

Just remembered I forgot to check that Wake on RTC was enabled in my BIOS, which I'm guessing it isn't - might be causing the shutdown.sh script to not work or hang - will check that and see what effect it has...
Reply
#12
Hi there.... the intended function is sort of like this

Every 20 seconds a timer thread kicks off, and the status is determined from the status.xml

If the script determines that tvheadend is recording, it
* checks to find out when the current recordings will finish,
* writes the currently recording title to the screen
* then starts another 20 second counter thread.

If the script determins that tvheadend is not recording, it
* checks to find out when the next recording is due to start
* runs the shutdown.sh (to set wakeup time etc)
* computer goes into suspend mode
* computer wakes up
* script determines if the computer woke itself up, or was a user command
* if user command, exit the pvruptime (return to xbmc)
* if computer wakeup, start another 20 second counter thread

Theres a bunch of settings (minimum sleep time, time to resume before recording etc)... but thats the basics of it...

The keys are
* run the shutdown.sh script outside of pvruptime addon, to makesure you have the shutdown/wakeup working properly.
* permissions can be a killer, so i added shutdown.sh to sudoers
* mapping the powerdown remote button to the pvrprtime addon, so that instead of shutting down, the pvruptime addon runs, and either keeps the machine awake (to record), or suspends the machine (with a wakeup time set for next recording).

I hope that helps...

Cheers,

Nathan
Reply
#13
Sweet! finally got it working. Major issue was permissions (I had the wrong details wrong when trying to add shutdown.sh to sudoers). shutdown.sh was running fine when not called from the addon script, so that was the big clue...

And I also hadn't enabled Wake on RTC in BIOS, that was obviously the first problem.

A couple of other points i noted were:
  • If i had no current or scheduled recordings, the 'next' element didn't exist in status.xml and the script would stall at the first screen, so I added an if statement to check for the 'next' element first and set closestRecordingDateTimeStart to None if it didn't exist


  • When the next scheduled recording isn't due to start within 24 hours, the difference between closestRecordingDateTimeStart and currentTime is in the format "N days, HH:MM:SS, and the .seconds attribute ignores the days component and sets the wakeup far sooner than expected (unless we're currently recording and it doesn't set a wakeup). I'm not sure if there's a way to get the .seconds attribute to work around this or if it will have to be calculated manually.

I uploaded the changes I made to default.py to: http://pastebin.com/jnqaCam7 in case any of it helps - apologies in advance as I deleted some of your commented out stuff (e.g. process detection for commercial detection), changed timer values and printed more info to the log to help me figure out where output was stalling.

Happy to help test anything further - my python skills are limited to a quick google search for now...

Cheers,
Adam.
Reply
#14
This is something I was looking for. Thanks.

I'm gonna play with it when I have some free time. Does it prevent computer suspend while you are watching a movie or listening a music (or when they're paused atm)?
Reply
#15
It doesn't automatically suspend your computer - suspend still only happens by pressing the power button on your remote.

But then the script intercepts the process, works out when the next wakeup for recording is due, and writes it to the RTC alarm before suspending (or if you're recording something at the time, it waits until recording is finished before suspending).
Reply

Logout Mark Read Team Forum Stats Members Help
Addon to wakeup and shutdown/suspend XBMC when using TVHeadend0