Showing posts with label SageTV. Show all posts
Showing posts with label SageTV. Show all posts

Friday, August 21, 2009

TV Lineup Changes = Bad For SageTV

TV lineup changes are one of the downsides of a non-TiVo DVR. I have always found TiVo soooo good at updating channel lineups. I haven't been so lucky with SageTV. So rather than deal with a missed recording, I wrote a script to download the latest TV lineup from our cable provider and compare it to the previous day's lineup. If there are any differences, it will fire off an email to me with the changes. That way I know when I have to rescan the lineup for the HDHomeruns and SageTV if SageTV hasn't already done the right thing.

I'd love to publish it, but it's one of those things that I'm afraid could get blocked if too many people are using it and that would backfire on me. I do my best to disguise the user-agent and randomize the time of day the script runs to make it seem less bot-like.

In any case, it took all of 10 minutes to code up in Perl, so maybe this will inspire others to write their own should they feel the need.


Thursday, August 6, 2009

My Take on SageTV Server Power Savings

I've been working off & on with the media server's power management. Since we have a DirecTiVo, most of our live viewing is done on that along with some recording, so the Sage server doesn't need to be online unless we're watching some recorded content from it or it's recording. So I can really keep this thing powered down 70% of the time, and almost 90% of the time since it's summer. So I spent some more time figuring out when SageTV is being used and came up with this write up. My solution, like our home automation system, integrates a lot of separate pieces to get things just right.

Let's get to it. First off, as in my previous post, we use the exported sage schedule. Grab this Perl file and save it as a .pl file. The script is fairly simple. It takes a command line argument, the path to the schedule file, and figures out what hours of the day SageTV is recording. It puts that info into a mySQL database called mystuff with username and password as the login credentials. You don't have to use mySQL, that's just what I use to pass data between different components of our system.

The next step involves our xPL Plugin for SageTV and your favorite xPL scripting engine. The engine we use is our homebrew xPL sCU - an xPL bridge to starCOMUltra, the HA software we use. With the xPL plugin for Sage, you can query it for which clients & extenders are currently playing media (or you can rely on the hidden feature where the plugin will check the playing status whenever it receives any xPL message - it will send an update only if the status has changed). In xPL sCU, I've scripted up logic for processing those updates:

function xPLReceived(e,schema,source,dest,msgtype) {
switch(schema.toLowerCase()) {
case "doghouse-sagetv.media":
if (schema.toLowerCase()=="media.mptrnspt") {
mpName=e.XplMsg.GetParam(1, "mp");
mpCommand=e.XplMsg.GetParam(1, "command");
mpStatus = mySQLQuery("locals","value","SagePlayerStatus");
switch (mpName) {
case "LR":
mpID=0;
break;
case "FR":
mpID=1;
break;
case "Master":
mpID=2;
break;
}
if (mpCommand=="play") {
mpStatus=mpStatus | Math.pow(2,mpID);
} else {
mpStatus=mpStatus & (7-Math.pow(2,mpID));
if (mpStatus==0) {
sTimers.load("SageClientIdleTimer",20*60);
}
}
if (mpStatus!=0) {
sCUDevices.Flags.Item("SageClientIdle").State=0;
}
}

What the snippet does is process xPL messages about the media players' state. If any player is in use, it clears the SageClientIdle flag in starCOMUltra. If a player becomes idle, it checks to see if all the players are idle and starts a 20 minute timer. Elsewhere in the code (not shown) is if that timer expires and all players are still idle, the SageClientIdle flag is set. You can choose your own idle timer length.

Now we have the player and recording status, but wait, what if I'm using the server for some other purpose? The only way I'd be using the server is via remote desktop, so i set up an EventGhost macro on the Sage server to send xPL messages when an RDP session is initiated or closed. A timeout period after a session is closed will determine if that aspect of the server is idle.

Finally, we have all the pieces in the place. In starCOMUltra, where everything comes together, we have this piece of code that runs hourly (along with the parseSage.pl script):

// to prevent unneeded throttling, we'll check if sage is currently
// recording or will need to in the next 3 hours
sageRecord=0;
for (i=0;i<4;i++) {
if (mySQLQuery2("sagesched","value","hour",TimeHour()+i)==1) {
sageRecord=1;
}
}
// check if media server is awake and no RDP sessions open and no recordings
// for the next 3 hours and no players in use - then 10 after the hour
// we'll put the server to sleep
if (mySQLQuery("locals","value","MediaAwake")==1 && \
mySQLQuery("locals","value","mediaRDP")==0 && \
Devices.Flags.Item("SageClientIdle").State==1) { \
sageRecord==0 && mins==10) {
LogDevice("# stop sage server");
HibernateMedia();
}

To wake up the server manually, all our viewing areas have a 3Com Audrey touchscreen nearby. It has a screen to wake up the media server which takes a few minutes. Not perfect, but like I said, we use the DirecTivo for most of the on demand TV watching. Plus, most of the time, we watch recordings during prime time and the server is already on.

"That's all!" ;) Obviously, this is very specific to our setup and situation, but hopefully there are ideas and code bits that may be useful to you.

Friday, July 17, 2009

xPL Plugin for SageTV released

I have released my first rev of the xPL plugin for SageTV. You can read more & download it here.

Wednesday, July 15, 2009

xPL SageTV Plugin Update

I've overcame my laziness, well most of it, and implemented a majority of the xPL media schema. I am still leaving in the capability to send the actual SageTV commands for specific control. I have also added the ability for the plugin to respond to some queries, specifically what's currently playing and querying playlist items. Finally, I've peeled it out of InfoPop into its own JAR.



Monday, July 13, 2009

Touchscreen Thoughts & More SageTV-xPL

Touchscreens are a very popular add-on to home automation systems. A lot of people have been tying ELO touchscreens to HP thin clients or other low powered Windows boxes. We haven't deployed any touchscreens other than the few ancient 3Com Audreys we have sprinkled around the house. Personally, I'm holding out for some low priced tablets, and luckily, I'm OS agnostic. I built our automation GUIs using AJAX, so any modern browser can use them. Our screens may not be as fancy as some of the flash or application based screens (although with some graphics help, they could be), but they run great on our Windows machines, Nokia tablets and Linux netbook. I have been eyeing the progress of the Crunchpad, and I'm hoping they can hit their price targets. If they do, I'll be shifting my efforts to building screens.

In the meantime, I continue to plug away on xPL-SageTV integration. I've got one way control going now, sending xPL messages to my plugin. I added a property in sage.properties that maps the SageTV client names (MAC address and SAGETV_PROCESS_LOCAL_UI) to a more friendly name for the xPL messages (FR, LR, MasterBedroom, etc.) For the xPL control, I contemplated using the media.basic schema, but there's some overlapping stuff that I'm too lazy to implement. Also, I can't implement all the SageTV specific functions in the media.basic schema, so I'm opting to use control.basic to control the plugin. I'm using the 'device' and 'current' fields from control.basic, where device will be the friendly SageTV client name and current will be any SageTV command (Home, Play, etc.).

So far, I haven't separated it from the Infopop code as it shares so much overlap setting up the xPL side. Plus, I'm not sure how to build my own independent plugin. I'll figure it out at some point.

Saturday, July 11, 2009

New Project: SageTV & xPL

I finally got around to trying to customize SageTV. I've never written any Java before so it's been slow going. I don't have any Java books, but I always "learn" by doing - I figure out enough stuff to make things work.

I started off with the xPL4Java SDK and looked at the example code. I played around with the NetBeans development environment, but I didn't really like it. After getting the samples running, I took a look at the source for the SageInfoPop SageTV Import. It was built using Eclipse IDE, so that seemed like a natural one to use since this is the first thing I wanted to modify.

After about 2 days, I've managed to get xPL running with SageInfoPop. It takes in xPL osd.basic messages, extracts the message, initiates a connection to the SageInfoPop YAC port and sends it the data to display. I really wanted to send it directly to Sage, like SageInfoPop does, but couldn't get my mind around the OOPness to make it happen.

At some point, I should sit down with a good book on OOP and really understand it all. In any case, now I can program Java in addition to VB.net, C#.net, JavaScript, PHP, Python & Perl. Anybody want to offer me a job? ;)

Anyway, I'd like to continue to integrate SageTV & xPL so that I can have full 2 way control of SageTV over xPL. This was a good start.

Tuesday, June 30, 2009

Somewhat Quiet Last Few Months

I've been a little preoccupied with other things, but I have been working on some small projects here & there. I just haven't felt like writing about them. I'll try to summarize what I've been doing for the past several weeks/months.

Last night, I hardwired the sensor that detects when our alarm is armed. Originally, it was a CDS cell covering the armed LED on one of the alarm keypads. The sensor was then connected to the CDS input of an X10 Hawkeye. It worked well 99% of the time, but once in a while, it would a miss detecting a change due to some RF collision. Not a major problem as the alarm is completely separate from the HA system, but annoying for automating events. So, I ran a pair of wires from the CDS cell at the keypad to the wiring closet. I terminated it on the X-Axis of the third gameport controller I've deployed. It works perfectly now.

I've gotten fairly adept at fishing wire with no special tools. For the CDS wire, I routed it from eyelevel where the keypad is to just above the baseboard. I used a string with bolts tied on and dropped it into the wall from an eyelevel hole. I drilled a small hole above the baseboard and used a vacuum to suck the string out. I then fished the wire through by taping the string to it.

I also added a 2nd HDHomerun (which also involved fishing wires - some Cat-5E and RG6.) I have it currently connected to an HD antenna in the attic.

I've been slowly deploying more of the UPB modules I got on clearance from Fry's. As my UPB network got bigger, I started to notice some limitations in my handling of it. I wrote my own code to handle UPB since my old TimeCommander+ does not have the capability. It resides in my xPL starCOMUltra bridge as described here. It's actually just a generic serial interface in the bridge. All of the actual code handling UPB is in the hosted JScript.

To make a long story short, I was having problems with retries and sending commands to the UPB PIM too fast. I solved this by adding JScript code to build a command queue and beef up the retry/busy/NAK logic. It uses the built in Queue structure, similar to JavaScript and described here.

I also bought a couple more HP thin clients off of eBay. I am now planning on installing .NET on them, so I've also purchased these 512MB flash disks so I have enough room for it (.NET needs about 150MB free on the C: drive). I also found some cheap 512MB RAM upgrades as well. One will be deployed at our other house for more minor automation projects and the second one will replace the current T5700, which functions as a networked contact closure device. I want to test out & phase in the new one before taking the existing one offline to upgrade and move elsewhere in the house.

Thursday, June 4, 2009

Hibernating Sage Server & Waking Up HD Theaters

I've finally gotten around to optimizing the powered on time of the media server. To get started, I have Sage export its recording schedule to a network drive by setting this option in sage.properties: scheduler_export_file=. I just specify the path to the file I want it to dump to. It creates a tab delimited file containing the recording schedule for the coming week. I parse this file daily at 1AM and keep track of the earliest start time and latest end time for the day.

The server gets shut down sometime after we've gone to bed and after the last recording. It actually gets hibernated remotely from the HA server using psshutdown. I use the command psshutdown -h \\machine-name to initiate hibernate.

The problem with hibernate is that wake on lan will not work to bring the machine up, but it will work when the machine is shut down or in standby. I opted for hibernate since the machine comes up faster than from power off and uses less power than standby. I needed a way to automatically push the power button to turn on the server. I wired this relay to the power button, connected it to a 12v wall wart plugged into a UPB appliance module. Now, my HA server sends a UPB command to turn on the wall wart & then turn it off. This causes the relay to close and activate the power switch before the relay opens again.

Once Sage is awake, I have EventGhost macros that check to see if the server just came on or came out of hibernate. Those macros then kick off a python script that telnets to the HD Theaters and reboots them so they are powered up and waiting on the sage menu.



import telnetlib

tn = telnetlib.Telnet("192.168.1.2")

tn.read_until("login: ")
tn.write("root\n")

tn.write("reboot\n")


Sunday, April 26, 2009

Not Much Going On

I haven't been doing a whole lot lately. Part of that is a little HA burnout from my manic March. Part of that is a little disappointment over SageTV and the smushed screen. That's been finally resolved after beta updates of the server and the HD Theater firmware.

I did make the decision to turn off HAL Deluxe. It's always been a resource pig occasionally prone to 100% CPU attacks. The lack of voice mail functionality due to it crapping itself after a Windows update didn't help. And my failed experiment with microphone VR put another nail in the coffin.

Of course, turning off HAL comes with great benefits - lots of free memory and more stability. My two HALi apps also get turned off as well. The extra resources is letting me play with SageTV on my HA server. I moved the 1.5TB disk from the DVR machine to the HA server, migrated my SageTV settings over and have been running for a couple days. It's not a CPU pig but it is as fat as HAL. I've seen it well over 200MB and that has me thinking of bumping the HA server memory from 2GB to 4GB. The DVR machine will probably move over to our other house as the machines there are a little slow.

Finally, I snagged an HP T5700 (256MB RAM & flash) thin client off eBay 60 bucks (less 14% Live cashback and 1% FatCash). I'm going to see if I can use these as little xPL boxes. I want to distribute them around the house where I don't have enough wiring to support all the inputs I want to add to the system. For example, I want to move 3 current switches from DS10a's to a gameport (and add a few more contact closures). I don't have enough wiring there to get those outputs to the wiring closet nor is there enough wiring to put a gameport there using Cat-5 USB extenders. I thought about USB over IP devices but they cost twice as much as a thin client and obviously have much less functionality.

Saturday, March 28, 2009

HD Theater Smushed Screens

The family room TV is a 10 year old Sony 36XBR250 which has a vertical compression feature. There is a bug in the HDTheater firmware that activates that in the Sony so the menus are squished and the fonts are not very readable in things like the program guide. Supposedly, there will be a fix, but in the next beta of the server software. In the meantime, the family room unit won't be getting much play.

Friday, March 27, 2009

SageTV Coupon Code

As luck would have it, 4 days after I ordered my 2 HD Theaters and SageTV software, they are offering a coupon code for $20 off the HD Theater and $25 off the bundle. Argh. I've sent them an email and asked if they can give me an adjustment since I just dropped $500 on their stuff. We'll see...

The code for their online store @ http://www.sagetv.com is MMAD09 and expires April 1st.

Update: I received this email from them:

Unfortunately this coupon is for orders from 3-26-09 to 4-1-09.

Had I not ordered until today, I would have gotten one more HD Theater. SageTV is definitely no SlimDevices.


Tuesday, March 24, 2009

Sage, SqueezeCenter, SliMP3 and xPL

With 2 HDTheaters on the way, I've been working on ways to use our new SageTV DVR server as a third client for playback. I don't have an IR receiver for the PC and since I'm keeping costs low, I'm not going to buy one. However, it just so happens there's a SliMP3 by the TV that the DVR is connected to and they work great as IR receivers. But how do I get the IR from the SliMP3? That's easy! I already have SqueezeCenter & its xPL plugin running. Plus the xPL plugin's "Infra-red Processing" option is configured to "Both". This gets me xPL messages issued when any remote buttons are pressed.

I also had installed EventGhost on the DVR and added my xPL Plugin to it. The next step was to capture the EventGhost events that result from xPL messages that result from remote control button presses. With that, I created macros triggered by those events and had EventGhost issue keystrokes in response. As a test, I used an old TiVo remote and mapped the navigation and select buttons to keystrokes for up, down, left, right and enter. The result is this video that shows both the EG and SageTV windows while I use the TiVo remote to navigate around the SageTV interface:




Monday, March 23, 2009

DVR Server Update

The E5200 based DVR server is looking really good. With the 2 hard drives, it idles around 50 watts and gets up to about 90 watts playing a 1080i HD stream in SageTV through the onboard graphics. During playback, it used about 30% of 1 CPU. That means there's plenty of horsepower for it to do much more. I'm planning on moving SqueezeCenter and MediaNet over to it, but neither of those is CPU intensive. I need to see what other functions I can move over from the HA server. The cheap AirLink gig NIC works great. I was able to sustain 400 Mbps transfers between the DVR & HA server.

Update: I just purchased my SageTV license and 2 HD Theaters.

Friday, March 20, 2009

Slowly Piecing Together a Bargain DVR System

I just picked up an E5200 bundle from Fry's for $99. The E5200 is a 45nm processor that has low power consumption and pretty good horsepower compared to the Core2 E7300 (See review here). This goes nicely with the $85 1.5TB Seagate Drive I scored last month, the 2GB of of memory for $7 and the $3 Airlink gigabit NIC. I have a $19 MicroATX case, a spare $19 Seagate 200GB IDE drive for the boot drive (Staples Black Friday deal several years ago), and a spare $6 Antec 120mm Tricool fan. It will be running a free copy of Server 2003 courtesy of Microsoft DreamSpark and my wife who's taking a night class which qualifies her to get some free MS software. I just need an 80Plus power supply. I have a regular spare that I can use to get the system set up, but for the long-term, I'm going to find an high-efficiency power supply for this. Total cost so far is about $250 with the power supply left to buy.

Wednesday, January 28, 2009

HDHomerun Update

I found from the HDHomerun forums that I should update the firmware. I downloaded the latest and updated, and now I'm seeing about 14 Mbps, which is perfect. If I decide on another HDHR, I'm figuring about 56-80 Mbps of bandwidth. Since our house was wired back in 1999 with Cat-5 (not 5e), 100 Mbps is as fast as the network can run. Also, each SageTV HD extender can use up to 20 Mbps so in worst case, the network will be overloaded - for 1 NIC. Furthermore, where I want the PC located there is no cable jack so I can't create a local GigE network with the HDHRs and the PC. I do, however, have a Cat-5 run from the HDHR location to the PC location, so I can create a small 100 Mbps network with 1 NIC and the HDHRs. I can then add a 2nd NIC connected to the main LAN to handle regular network access and streaming to the HD extenders. One thing is the HDHR is a DHCP only device, but will default to a 169.254.x.x address if no IP address is handed out to it. I just need to set the HDHR connected NIC to 169.254.y.y with a subnet mask of 255.255.0.0 and the PC should see the HDHRs.

Edit: Turns out, the reduced bandwidth I was seeing was due to using VLC to view the streams. Using Sage, the bandwidth was still 30 Mbps. I have since installed the SageTV 6.5.8 release candidate and the bandwidth is now down in the 10 Mbps range.

Looking into SageTV

I've taken a break from automation stuff and I'm looking at media now. I've downloaded a trial of SageTV and I got an HDHomerun. I have things set up on an old Sempron 2800+ machine, which is adequate for recording and serving video (not at all for watching live HD though). The dual tuners on the HDHomerun use up 80 Mbps when bother are tuned to HD channels. This is clearly not usable unless I upgrade some parts of my network from 100 Mbps to gigabit. I have a few other issues to work out as well, but the Sage software and the HDHomerun seem to work well.