Wednesday, December 30, 2009

Most Downloaded of 2009

Since 2009 is the first full year I developed applications, I thought it would be interesting to see which ones were most popular. I know 2009 isn't over yet, but the #1 app certainly won't be unseated by year's end. Here are the 10 most downloaded DoghouseLabs applications for 2009.

1. EventGhost xPL Plugin - 125 times
2. BlueTracker - 33
3. Blabber - 24
4. SageTV xPL Plugin - 20
5. xScript - 18
6. xPLSerial - 17
6. xEKG - 17
8. xPLAudreyTTS - 15
9. xPLGCal - 11
10. OSDBuffer - 9

Looking at the numbers, other than the EventGhost plugin, that's not a lot of downloads. Volume has never been my aim - these are things that I use in my home automation system and sharing them is my way of giving back for all the cool software and ideas I've benefited from over the past 15 years. I am surprised by how popular the EventGhost plugin is compared to all the other xPL apps. Also, I'm curious if anybody really uses the SageTV plugin besides me - as only one person has ever asked anything about it. Anyway, thanks for using my apps and reading my blog in 2009 and happy automating in 2010.

Sunday, December 27, 2009

New App: Noise

No, I haven't fallen off the face of the earth, but I admit that it's been a while since I last posted. I've been taking a break from automation stuff over the holidays, but I did work on something I've always wanted to implement...

Have you ever wanted to be automatically told that the baby is crying or the dog's barking? Introducing my latest xPL app, Noise. It uses your PC's mic (or possibly other input device), samples the input for a period of time, and issues an xPL sensor.basic message with information about the noise it detected, if any. You can read more about it here.

Tuesday, December 8, 2009

xPL Tweeting

I'm not sure why this hasn't been done earlier, but it looks like I'm the first to integrate xPL and Twitter. It was really easy to do and only took a few hours. A lot of the time was just figuring out what API to use and investigating OAUTH. I ended up using twitterizer's API, which doesn't support OAUTH. That's fine because I want this app to run standalone without any user interaction required for login, which OAUTH requires. The downside is the tweet source will show Twitterizer and not xPLTweet. Twitter no longer takes registrations for apps that do not use OAUTH, so there's no free publicity for my app in your Twitter streams. Bummer.

xPLTweet grabs OSD.BASIC messages explicitly targeting it (ie doghouse-xpltweet.yourinstance). It grabs the text portion of the message and tweets that. That's pretty much all it does. A future enhancement I may do will be to monitor who you're following and issue OSD.BASIC messages when they update their streams, but it could be messy if you follow many active Twitterers.

In any case, you can grap xPLTweet here.

Thursday, December 3, 2009

Debugging ECM-1240 Setup

I've made some good progress on my ECM-1240 interface. It's a good thing I'm running it on xPLserial, where I can easily make changes to the script instead of having to recompile if it were an application. I found some problems in my script that caused it to miss a byte here or there and seems to be the source of the instability I was seeing. The current script has been running for 5.5 hours (since a power outage ended this morning) without having to reset the counters.

My script is no longer sending the readings over xPL, instead it's doing direct writes to MySQL. It was a pain trying to get ODBC working with XP Embedded, but eventually I did find an ODBC add on for HP thin clients. It doesn't say it supports the T5700, but it works anyway. Now, I'm updating power usage everytime it changes instead of whenever the xPL message was received.

As for this morning's blackout, it was quite a racket. I was awaken around 4AM to a symphony of beeping UPS's - 9 of them to be exact. I really need to open up a few of them and cut the buzzer wires. Some are really way too loud. I also discovered a couple with dead batteries. Good thing I got a couple more UPS's on Black Friday. It's actually cheaper to replace the low end ones instead of buying new batteries.

Tuesday, December 1, 2009

Random Progress

I was having some problems talking to the ECM-1240 through a virtual serial port and Lantronix MSS-100. It would occasionally lose its connection. I ended up deploying my leftover HP T5700 thin client, connecting it directly to the ECM-1240. I've got xPLSerial running on the thin client and it issues xPL messages every 60 seconds with the current power consumption. I'm still getting some weird problems with the ECM-1240 where the counters get out of whack on an Aux channel and exceed the usage on the main channel. This causes me to have to reset the counters and lose the cumulative statistics. I need to figure out how to work around this issue so I can get some valid full-day consumption readings.

I've also moved some xPL and xAP applications off my other 2 servers onto the thin client since it's not really doing a whole lot. It's chugging along at around 10% CPU utilization with about 5 apps running. I tried to run xPLSys on it, but it's crashing. There doesn't appear to WMI in the XPe build on the thin client. I may have to figure out a different method of getting the statistics.

Ironically, I've also been working on my automation interface GUI in expectation of buying some touchscreens. However, as the world found out yesterday, the Crunchpad died before birth. I was planning on buying several of those for touchpanels around the house. Hopefully, there will be some ChromeOS or Android tablets in the near future.

Tuesday, November 24, 2009

First Power Graph

I got around to putting the data into RRDTool. I just updated the post with some better looking graphs. I used this guide for creating stacked, outlined area graphs.






Sunday, November 22, 2009

Back to Juggling Multiple Projects

Earlier this week, I started work on a new xPL app, currently called xPLSys. It monitors disk space, memory and cpu utilization and sends xPL messages containing the data. I'm not exactly sure how I want to package those messages as there really isn't a schema to hold the info I want to send - so either I make up my own schema or send multiple messages - one for each stat being watched. It's been running for a few days now but has been pushed aside for something else.



My Brultech ECM-1240 power monitor arrived Friday, and I started installing it that evening. I finished up most of the wiring Saturday morning and have been deciphering the serial protocol for real-time updates. I've been using our xPLSerial app to interface to it and code up the interactions with the built in scripting engine. I have to say, it's a very cool app and you should download it and donate ;). Despite being distracted by CAL's upset of Stanford (HOORAY), I figured out the serial protocol last night and have now been fine tuning my script. I've been thinking about rolling this into an app, but there is virtually no cpu utilization with the script running in xPLSerial.



I did make a change to xPLSerial to assist with debugging and that change will get pushed out eventually. I'm also considering removing the xPL from the name and calling it something else. It's really a serial port scripting engine with built in xPL functionality, but doesn't require xPL. In the meantime, I need to figure out what I'm going to do with the power data I'm getting every second.

Saturday, November 14, 2009

Solar Contract Signed & ECM-1240 Ordered

We signed the contract a couple days ago with Real Goods Solar (Regrid Power) for a 3.68kW system. Projected install date is late February and power on in March. Might as well have it come online when there's more sunlight.

I also ordered the ECM-1240 power monitor from Brultech. I decided to put current transformers on the lines from the solar array, but I will have to extend those via Cat-5. They should be able to go 100 feet, but it looks like it will be very, very close to 100 feet or possibly more. Hopefully, it will work. I've already opened up a hole in the wall next to the sub-panel, installed a mudring and drilled through the stud next to the subpanel so I can pass CT wires from the subpanel to the mudring. I also ran a couple Cat-5 wires through the wall behind the subpanel to a closet in the adjacent bedroom. I'll need those to connect to the Cat-5 drops in that room to extend the solar array's CTs and possibly get the ECM-1240 on the network via a Lantronix MSS-100. With luck, it'll get here before the Thanksgiving break so I'll have time to work on it.

Tuesday, November 10, 2009

Power Monitoring

As we get ready for the solar panel installation, I've been looking into power monitoring systems. I'm going with the Brultech ECM-1240. This is their 2nd generation energy monitor and has been very popular with the Cocoontech crowd so it has been well tested in the real world. Brultech Support has been very helpful responding to my emails with timely replies. I am looking at purchasing Package A, which comes with the monitor, 2 200A split core current transformers (CTs) and 5 MicroCTs. I'll also need 8 more MicroCTs and possibly a couple of the 80 amp MicroCTs (for our AC unit).

We have a main panel with the electric meter that services the AC unit and a sub-panel inside our house. Everything else is fed from the sub-panel, so that's where the ECM-1240 will be. It will be easier because I can shut off the main breaker to the sub-panel, whereas the main panel has no shut off. The less I muck around in there, the better. I will have to connect the CTs from the AC breakers to the ECM-1240 upstairs by the sub-panel. The CTs can be routed over Cat-5, I just need to figure out how to get the CT wires out from the main panel and into my garage, but that can wait until the solar guys do the install. Maybe their electrician can help me out.

As for the solar install, we've finally decided on an array size, an inverter & an installer, but I'm waiting for the data access to be finalized before signing the contract. I've chosen not to use the ECM-1240 to monitor the solar array as I am working with the solar installer on getting access to the inverter via an RS232 add on board. They've been very responsive so far and hopefully this item will be resolved soon.

Friday, November 6, 2009

BlueTrackerScript Released

I figure everybody is tired of reading about solar and wants me to get back to automation stuff. I'm releasing BlueTrackerScript, an app that I use at work to tell if I'm at my desk (this affects forwarding for Google Voice Automation). Of course, you'll need a bluetooth adapter for your PC, leaving bluetooth running on your cellphone, and you'll need to add some actions to the included sample script, blue.js.

Since I use this on my work PC, I want it to be able to communicate with my home server without any interaction necessary (setting up ssh tunnels, etc.). So I created two special URLs on my public webserver, one for detection and one for timeout. The script will fetch the appropriate URL using Wget. On the webserver, it watches the access log for access to those specific URLs from a specific IP address (my work IP), and passes a message to the automation server if it detects those URLs have been accessed. The automation server then adjusts Google Voice forwarding.

BlueTrackerScript is available here.

Thursday, November 5, 2009

Cleaning Solar Panels Uneccesary?

Yup, I'm still on my solar tangent. Getting close to deciding on a contractor, but not yet. I ran across this Google study on their solar installation. Their study shows that tilted panels, like virtually all residential rooftop mounted systems, don't need to be regularly washed. Rain does a good job of cleaning off the dust. This would discount SunRun's solar panel washing benefit. Panels that are installed horizontally do benefit greatly from a cleaning, however. To see more details on the Google study, check out their slides.

Friday, October 30, 2009

Solar Spreadsheet

A lot of the solar quotes I've gotten will take your current usage to show a cost-benefit analysis. What I want to see is what happens to that benefit when my usage changes. When sizing our prospective array, I want to see how much more electricity I can use before the costs really blow up. Ideally, I want to keep grid usage in the lowest 3 tiers. So I created this spreadsheet to help with planning.

It's based in Google Docs. It's read-only but if you go to File->Make a Copy, you can save yourself an editable copy. There is a 2nd sheet in the spreadsheet called 'info' that contains instructions on how to get the data for your specific scenarios. The information is based on California's PG&E standard residential service. You can adjust the formulas, tiers, rates, etc. based on your situation. Also note that many solar households go to the time of use rate schedule instead of the standard schedule, so that will affect calculations. For simplicity, I've chosen the standard schedule. Let me know if I've mucked anything up.

Thursday, October 29, 2009

Ladders & Solar Financing

Our home is two stories and you need at least a 15' ladder to reach the lowest part of the roof. So far, of the 2 companies that have done a roof survey, both of them have showed up with a 13' adjustable ladder. When the first guy visited, I saw him pull out his little ladder and I figured it wasn't going to be high enough. After a couple minutes of watching him reposition his ladder, I offered my 17' ladder. When the other installer came, I was in the house watching him on our cameras while he tried to figure out how he was going to get up on the roof with another 13' adjustable ladder. Again, I came to the rescue and offered my ladder. These guys seriously need to think about carrying a longer ladder. If I didn't have a long enough ladder, these guys would have really pissed me off. I would have taken time off from work for nothing and would have had to reschedule.

Anyway, all these solar installers are pushing this long term lease thing - the most common is by a company called SunRun. There are a couple different options - but they both have an 18 year term. The idea is they pay the installer for the system after its installed - so they own it. Then, they lease it to you over an 18 year period. At the end of the 18 years you can sign another lease, ask them to remove the system or purchase the system at some yet to be determined amount. You can pay either a lump sum amount or monthly. Its lure is that your initial outlay, if you do the lump sum, will be less than your cash purchase price before the federal tax credit.

So for example (assuming you live in California like me), if you purchased a $22,000 system, you would receive about a $3500 state rebate. Typically, you sign the rebate over to the installer and the out-of-pocket cost would be $18,500. Then a 30% federal tax credit shaves the net cost down to about $12,500.

With SunRun, you would pay a lump sum of about $13,000 for 18 years. Of course, they throw in a few more goodies. They extend the warranty of the system from the 10 year installer warranty to cover the entire 18 years. They provide monitoring for the duration of the lease (some installers offer it for 10 years and others charge for it). If they detect something wrong, they'll send a crew over to fix the problem. They'll also come out and wash the panels once a year. Finally, they'll replace the inverter since they typically have a 10-12 year lifespan. They want you to believe this is an added $6200 worth of goods.

They say monitoring is worth $2000, but since we've already got a home automation system & server running, I can get a Brultech monitor for about $250 and monitor it myself. Maintenance is supposedly a $2700 value, but that's hard to quantify. The system is supposed to be maintenance free, and I suppose I can climb up on our roof and hose the panels down once a year (but will I do that when I'm 50 or older???). Finally, they peg the inverter replacement at about $1500. If these inverters are $1500 in 10-12 years, to me, it assumes that there have been no technological advances in that time span. In all, I would derate the maintenance costs by 50% and say the inverter will cost $500 when it needs replacing. For our situation, this gives SunRun's perks a value of $250 (monitoring) + $1350 (maintenance) + $500 (inverter) = $2100, about 1/3 of what they claim.

If we take those "perks" and add it to the net purchase cost of $12,500, we get $14,600. Compared to SunRun's $13,000 cost, the purchase will cost $1600 more, but I get years 19-30 for "free." With SunRun, after 18 years, I could either fork out some unknown amount for a new lease or to buy the system from them. Either way, it's going to cost more than a purchase. Otherwise, how would they make money?

They really push the upfront cost advantage of SunRun vs. purchasing, and that really gets people interested. Then they throw in their perks/scare tactics, to help push you over the edge, which seems to work because solar systems are not very common (and people still buy extended warranties for tv's and other household items). It seems like an OK way if you don't have the cash for a purchase, but you could probably do a home equity loan and get the tax write off for that.

Monday, October 26, 2009

More Solar Thoughts

The system I'm currently leaning toward consists of 16 Sharp 230W panels and a Sunny Boy 3kW inverter. Apparently, due to what's called stringing limitations, I cannot install a Sunny Boy 4kW inverter with 16 panels. If I chose 14, 20 or 22 panels, it would work. That changes my expansion plans.

One suggestion would be to install 16 Enphase micro-inverters instead of a central inverter. The microinverters would allow each panel to turn on individually, instead of having to wait for the array voltage to reach a certain level before a central inverter turns on. Microinverters could possibly boost output 5-10% because the panels will generate sooner and stay on later and are supposed to work better in shade and on hazy/cloudy days. Also, if one dies, the rest of the array will still produce. However, there appears to be a $2000 premium based on my system size and they are relatively new technology (but have a 15 year warranty). There is also the issue of replacement in case of failure - someone would have to hike up to the roof and possibly remove panels to get access to a failed microinverter (depending on how they do the installation). I have also been told that around 10-12 years, normal inverters will probably need replacement, so I assume around 15 years, the microinverters will need to be replaced - and there is extra labor associated with their replacement. Finally, with so many microinverters, there is an increased number of points of failure vs. a single regular inverter.

Panel brands is another topic of interest. One installer is very high on Evergreen Solar and how their panels are rated 0-10% above spec vs. other brands which can be +/- 5% or so. Sunpowers are high end, high efficiency, but somewhat restrictive with their installation. Perhaps this is why none of the 5 quotes I received used Sunpower. Sanyos are also high efficiency and high priced, but are manufactured/assembled all over the place. Obviously, each dealer will tout the panels whose manufacturer they have deals with or which provides them the largest profit margin.

For the consumer, it ultimately comes down to cost, wattage and size (room for future expansion) - at least it does for me. When you start to use the more exotic panels, it's hard to justify the longer breakeven period. I chose the 16 230W panels instead of 20 175W panels due to density - I want to have room on the roof for future expansion. The 20 175s would nearly occupy the entire back roof. I could get 16 Sanyo 215W panels for a $2000 premium (and 240W less output) vs the Sharp 230W. The Sanyo's are about 8" narrower so I could squeeze 2 extra columns - or 4 more panels - in the space of the 230W Sharps. Overall, I could squeeze up to 27 Sanyo's vs 20 Sharps - 5.8kW vs. 4.6kW output - a pretty large difference.

I am leaning toward the 3kW inverter at this point. In the future, if we need more capacity, I could then go with microinverters for the additional 4-6 panels that there's room for. With today's panels, I have room to go from 3.7kW to 4.6kW, but in 5 years, panel density will be better - so I should be able to get more power out of the remaining roof space.

Wednesday, October 21, 2009

Planning to go Solar

I just had a site evaluation with an installer we're considering. He checked a few things out - the roof - and it's in great shape and the electrical panel - which can easily accommodate the extra amperage. Then he ducked into the attic to check the structure and take a few pictures. While on the roof, he took measurements and made note of obstructions like vents. Some short vents can be cut even shorter and panels can be installed over them. The lowest efficiency we'll have would be about 98% due to our back neighbor's Italian Cypress, which will cause some shading in the early morning. I may ask the neighbor if we can cut it down a little. Our back roof has a SE facing, while not optimal, is still very good in terms of sun exposure. Based on this, we should qualify for 92% of the California solar rebate. Next step is for the installer to send a couple plans with different panels and outputs. We're looking at a 3.5-4 kW system which will reduce our yearly electricity bill by about 72%. I also need to think about future needs and roof space for expansion like an EV car or 40" LCD touchpanels for automation ;) The installer has a bit of a backlog, combined with the winter weather and holidays, the soonest they could start would be January. Power on might not happen until March due to inspections from the city & utility. I have 3 other installers to look at, but I'm leaning toward this one as they did a great job on my co-worker's array several months ago and have had an answer for every one of my questions (I ask tough questions! ;)

Tuesday, October 20, 2009

xPLSerial Released

It's been a while since I released an app. xPLSerial gloms together a generic serial port interface, xPL and a scripting engine. Read more about it and download it here.

Monday, October 19, 2009

xPLSerial

I've decided I needed to code up something to deal with serial port devices I may want to interface with. I've put serial device handling into my starCOMUltra hosted script as well as in my sCU-xPL bridge (xPL sCU), but while I'm debugging stuff, I don't want to keep reloading those apps as much of the HA system relies on it functioning correctly. There doesn't appear to be an xPL app that allows generic serial port interfacing, so I figured this would be a good (and easy) app to write. A majority of the code comes out of xPL sCU since it already does serial & xPL as part of its features. Because of this, I've already got a prototype running. It relies on an internal scripting engine to set up the serial port, send data to it and parse data from it. You can then issue xPL messages as necessary. Right now, I'm working on interfacing to an Ocelot I just acquired.

Thursday, October 15, 2009

Cheap Low Tech Home Security

Recently, I've gotten tired of coming home from work to find random flyers attached to my front door. Aside from the hassle of having to toss the papers in the recycle bin, the flyers are an obvious hint to thieves that there's probably nobody home. I stuck a "No Solicitors" sign on the front door a couple months ago and have had good luck so far. Our security cameras have captured a number of these spammers walking up the driveway, but once they get close to the porch and see the sign, they turn right around leaving nothing. No flyers and no door-to-door solicitors makes the WAF high and makes this a high bang for the buck "project."

Monday, October 12, 2009

Updated Cellphone to Windows Mobile 6.5

I finally got around to updating my HTC Touch Pro from WM 6.1 to 6.5 using this build. I've been playing around with it this weekend reloading and re-customizing. It seems a little snappier than 6.1. I like it.

Sunday, October 11, 2009

Homemade Avermedia Quad Viewer

I've been working on more web pages for our user interface (much cheaper than constantly buying hardware!) I thought I'd share some code on a simple quad viewer I coded up. I previously had single camera views on our floorplan GUI so this was really easy to add. Since our floorplan is web based, it will work on all platforms, which is great since the Avermedia software only works on Windows.

The Avermedia software has special URLs where you can view compact images of each camera. With a little JavaScript, you can have them refreshed at periodic intervals. First off, you start off with an HTML shell that defines the cameras - let's call it cam.html:

<html>
<head>
<SCRIPT SRC="cam.js" language="JavaScript"></SCRIPT>
</head>
<body onLoad="refreshCam();">
<img src=images/blank.png id=livecam0 style="position: absolute; left: 263px; top: 15px;">
<img src=images/blank.png id=livecam1 style="position: absolute; left: 620px; top: 15px;">
<img src=images/blank.png id=livecam2 style="position: absolute; left: 263px; top: 255px;">
<img src=images/blank.png id=livecam3 style="position: absolute; left: 620px; top: 255px;">
</body>
</html>

A few key things are the reference to the JavaScript file, cam.js and the call to refreshCam() when the HTML loads. Each img tag defines a camera view for each of the 4 cameras (you would put more if you have an NV5000 with more cameras).

The JavaScript file, cam.js, is below:

var camNum=0;
function refreshCam() {
t=0.2;
if (camNum==0) {
document.getElementById('livecam0').src="http://10.10.10.10:5550/mobile/channel01.jpg";
} else if (camNum==1) {
document.getElementById('livecam1').src="http://10.10.10.10:5550/mobile/channel02.jpg";
} else if (camNum==2) {
document.getElementById('livecam2').src="http://10.10.10.10:5550/mobile/channel03.jpg";
} else {
document.getElementById('livecam3').src="http://10.10.10.10:5550/mobile/channel04.jpg";
}
camNum=(camNum+1)%4;
refreshCamId=setTimeout("refreshCam()", t*1000);
}

Every time refreshCam is run, one of the camera views is refreshed depending on the camNum variable. The URL given is the special Avermedia URL - and each image in the HTML is associated with a camera's URL. Every iteration, camNum is incremented and the sum has a modulo 4 operation done on it - resulting in a value that changes from 0 to 3. The setTimeout function causes refreshCam() to be run every 0.2*1000 milliseconds. That's pretty much it. You can use any camera server you want - just substitute the URLs in the JavaScript.

Monday, October 5, 2009

Snagged Free Win7 Ultimate



I went to Microsoft's The New Efficiency Event and got a free copy of Windows 7 Ultimate. I don't have a machine to install it on though. I'd like to eventually port my apps to Win 7.

Other than that, I've just been re-theming and updating my ASP pages and doing some reading on PHP & MySQL.

Friday, September 25, 2009

A Search Engine for the HA System

As I've mentioned many times before, all system status (server status, starCOMUltra variables, TimeCommander+ devices, etc) is mirrored in a MySQL database. Many times when I'm debugging stuff, I sift through a logfile to find values or open up an ASP page containing flags, variables, etc. As a twist on this, I decided to make a search engine of sorts, where I could specify a portion of a name in the database and have all matches and their values returned. My initial try focused on writing some JScript to work with our IM interface and that's what I'm going to write about.

Each table in the Autohouse database is a category, like flags and variables.

mysql> show tables;
+---------------------+
| Tables_in_autohouse |
+---------------------+
| ai |
| calendar |
| debug |
| di |
| flag |

Typically, each table consists of a device and its corresponding value:

mysql> select * from locals;
+-------------------------+------------+
| device | value |
+-------------------------+------------+
| AirQualityO | 27 |
| AirQualityP | 46 |
| BWDownDaily | 0.246 |
| BWDownMonthly | 46.297 |

Not all the column names are the same, so we have to parse them out. For example, the database records the past 10 temperature readings for all temp sensors:

mysql> select * from lrtem
+------+---------+
| id | value |
+------+---------+
| 10 | 73.625 |
| 9 | 73.5125 |
| 8 | 73.5125 |
| 7 | 73.625 |

In scripting this up, we'll need the MySQL commands to get the data we want. First off, show tables gives the table names. Next, we'll iterate through each of the tables and grab their column names with show columns from <table name>. Finally, we'll do a case insensitive search in that table for the matching device: select * from <table name> where device like '%<name to match>%'.

Here's the code snippet I've implemented in my xPL scripting engine to handle queries via the IM interface. This sets up the MySQL access from JScript:

mysql=new ActiveXObject("ADODB.Connection");
strConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost; \
DATABASE=autohouse; UID=user;PWD=password; OPTION=3";
mysql.Open(strConnectString);

And this is the actual code to handle everything:
            
} else if (Mycmd[0] == "query") {
// Mycmd[0] is the command, Mycmd[1] is what we're looking for
txtBody = "\n";
var fieldArray=new Array();
// get all table names
query="show tables";
rs=mysql.execute(query);
while (!rs.EOF) {
// iterate through each table finding their column names
query2="show columns from "+rs('Tables_in_autohouse');
rs2=mysql.execute(query2);
var i=0;
while (!rs2.EOF) {
fieldArray[i] = ""+rs2('Field');
rs2.MoveNext;
i++;
}
// now search the table for a matching name in the first column
query3="select * from "+rs('Tables_in_autohouse')+" \
where "+fieldArray[0]+" like '%"+Mycmd[1]+"%'";
rs3=mysql.execute(query3);
while (!rs3.EOF) {
// build the output text
txtBody = txtBody + " " + rs('Tables_in_autohouse') +
" - " + rs3(fieldArray[0]) + "=" +
rs3(fieldArray[1])+"\n";
rs3.MoveNext;
}

rs.MoveNext;
}

The text gets passed back to the IM interface and the result is something like this:

me: query ring
autohouse:
di - Ring=0
flag - RingFlag=0
flag - RingFlag2=1
timer - ring_timer=0
var - ring_cnt=226

The resulting search returned the names and values of a digital input, two flags, a timer and a variable. This can be easily extended to a webpage so you can build your own Google for your home automation system.

Wednesday, September 23, 2009

Excellent, Free MS SAPI Voice for XP

Check out this CT thread on how to get the Microsoft Anna voice running on XP. The tip about Universal Extractor is also a great idea.

And don't forget to get the latest Picasa, which has auto face tagging.

Saturday, September 19, 2009

A Little Lull

I haven't been working on too much the last couple weeks. I think I've run out of things I want to do. One thing I've contemplated is automating opening/closing the vertical blinds in our family room, but it's not used very much anyway. I also thought about adding a magnetic lock on a gate, but they are a little pricey and I haven't found any that would default to locked on a power outage (can they even do that without power?). In the meantime, I'm just kicking back doing a little reading and watching some football. I think I deserve a break ;)

Monday, September 14, 2009

First Rain Brings Death (Of UPS)

Last night, we had our first rain of the fall (well it's almost fall) and it was enough to cause brownouts. This proved fatal for the UPS in the wiring closet. Fortunately, the TimeCommander+, a couple routers & switches and the NSLU2, which were on the UPS, were spared. The NSLU2 doesn't power itself back on when power is restored so I just realized it's resting quietly in the wiring closet instead of serving up http://www.doghouselabs.com. That's now fixed and a temp UPS has been installed. I'm not having luck with power related gear lately.

Wednesday, September 9, 2009

Building the W800 Antenna

I decided it's time to get rid of the original whip antenna that came with my W800 and build this antenna. Acquiring the parts became a treasure hunt. I picked up the nuts, bolts, washers and crimp lugs at Home Depot then headed over to Radio Shack for the SO-239 parts. Turns out the F to SO-239 Adapter isn't a regularly stocked item around here. I could order it or go to a Shack 30 minutes away and get it. Instead, I left empty handed and headed over to Fry's. There I found the Chassis Mount UHF SO-239 Coax Connector for a mere $1.49 vs. $3.69 at the Shack, but they didn't have the F to SO-239 adapter. They did have a BNC Female to SO-239 adapter and I happened to have a spare BNC Male to F connector at home.



I had still one more stop as I couldn't find the 1/16" brass rod at Home Depot. I stopped by my local Orchard Supply Hardware and found 3 packs of 1/16" x 12" brass rods for $1.79. Good enough.



Finally, I was able to start the project. Instead of a hacksaw to cut the rods, I used diagonal pliers. I also crimped the lugs after I inserted the rods - then I soldered them. Other than that, I followed the directions in the write up. I've got it temporarily hanging in my office but plan to put it in the attic this weekend. The whip antenna is in the attic but it can't see a Hawkeye motion sensor I just put in the backyard. The new antenna, on the other side of the house, can pick it up sometimes, so it should be a lot better in the middle of the attic.

Update: I've hooked it up to the RFID reader via a coax splitter and I have not had any dropouts! The antenna is still sitting in my office.

Tuesday, September 8, 2009

CCTV Server Power Supply Croaked

My HA server's power supply died back in March and the CCTV server's power supply died yesterday. It wasn't even 2 years old (the supply started off in the kitchen PC which was sporadically used. It wasn't used 24x7 until the CCTV server was created less than a year ago. Very disappointing. I've installed my backup ATX power supply, which has an intake fan over the CPU. The old supply didn't and rarely turned on its fan. It was a very quiet server, with just a slow case fan running. You can see the CPU temp is dramatically lower with the backup supply. The D201GLY2 got pretty hot at times, but was within specs. Now I need to hunt for a new 80Plus power supply.



Sunday, September 6, 2009

A Quiet Long Weekend Without Automation Projects

I took off work Friday and got started on my latest project - mortaring down a flagstone walkway on the side of our house. In 3 days, I've finished about two-thirds of it, but I'm thinking of taking tomorrow off since my knees are killing me. Maybe it's time to go back to doing some automation projects ;) Here's a peek at it from the dog cam which is connected to the 9100a.



Thursday, September 3, 2009

AJAX Cross Site Scripting Problem...Solved

As I've mentioned, our HA GUI is built with AJAX, and I thought that I was able to easily integrate the Aviosys 9100A. Turns out some browsers and/or operating systems weren't so willing to allow access to the 9100A since it has a different IP address than the web server. It works great on Firefox on XP, but for some reason, won't on Vista. Opera on Wii wasn't too keen on it either.

Since our GUI runs on the Apache web server, I can take advantage of mod_rewrite, which rewrites the requested URL on the fly. Let's assume my server runs on 192.168.100.100. I've got this code in an html file:

<div class=camera style="z-index:5; position: absolute; left: 49; top: 355px; cursor: pointer;">
<img src=images/camera_left.png border=0 onmousedown="javascript:selectCam('SideCam');" id=SideCam>
</div>

The selectCam function:

function selectCam(camera) {
var newurl,xyz;
if (camera=="SideCam") {
// set channel on 9100A
newurl="192.168.100.200/SetChannel.cgi?Channel=0";
// AJAX call to load URL
xyz=loadXMLDoc(newurl);
}
}

What I need to do is make the AJAX call look like it's going from the same address as the web server. I just need to edit the httpd.conf file for Apache and enabled mod_rewrite and proxy modules:

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Then, I need to turn on the rewrite engine and give it a rule to rewrite certain URLs:

RewriteEngine On
RewriteRule ^/9100a/(.*) $1 [P]

The above rule will rewrite any URL containing /9100a/ with the text following /9100a/. Now, I can change the URL in the selectCam function above as follows:

newurl="/9100a/http://192.168.100.200/SetChannel.cgi?Channel=0";

This will trick the cross site scripting checks since the URL appears to be local. The URL is rewritten by Apache to http://192.168.100.200/SetChannel.cgi?Channel=0, Apache will serve as a proxy to that URL and everyone's happy!

Internet Channel Now Free on Wii

You can now install the Internet Channel free on your Wii. This lets you browse the Internet on your Wii with the Opera browser. It's a little cumbersome typing in URLs with your Wiimote, but the cool thing is our AJAX based floorplan GUI works great on the Wii! Bet you can't do that with HSTouch, CQC or Main Lobby ;)

Tuesday, September 1, 2009

New Toy: Aviosys 9100A Video Server

As I upgrade cameras, I keep the old ones around just in case I find some use for them. The main cameras are connected to an Avermedia NV3000. The leftovers are connected to modulators so we can watch our dog on Slingbox. I decided to get an Aviosys 9100A to get those cameras web enabled. It was easy to install and I've got 2 cameras running right now. I've integrated it into our Floorplan GUI using the device's special URLs described here. It works well, but the camera switching is a tad slow.

Saturday, August 29, 2009

Automating the Dog Feeder

We have an older version of this dog feeder. Programming it always was a chore and after a while, it stopped accurately dispensing food - almost always giving too much. Whenever we use it now, it's just as a single meal dispenser and that makes the programming even more annoying. So this was a great opportunity for automation.

The feeder takes 3 D batteries so I dug out a 5V wall wart from my junk drawer. I opened up the feeder and found the motor that dispenses the food. After using a voltmeter to figure out the polarity, I soldered the wall wart to the motor, routed the cable out and closed up the feeder. The wall wart was then plugged into an appliance module.

The next step was to build an easy to use interface, which was a simple HTML form. The data gets loaded into starCOMUltra, and at the appropriate time, sCU turns on the feeder for about 45 seconds to dispense the food. Since it's a single serve feeder now, the feeder is disabled until programmed again.



Friday, August 28, 2009

New Bullet Camera

I just put up a new bullet camera Wednesday to replace my main front camera, which is an aging 10 year old B&W camera I got from Target. The new camera is a day/night camera with a Sony CCD so it's a marked improvement in resolution & clarity. However, at night time, it's still not as good as the old Target cam even with the help of the front floods. The old camera moved over slightly and is angled toward the opposite direction for better coverage. The new camera is my first "real" camera, as it has a BNC connector and I had to run it over RG6. As I was prepping to run the new RG6, I took some time to clean up the messy wiring from the other cameras. It was definitely something that needed to be done. I also ordered another different day/night cam to replace another old camera and it should come next week. I plan on moving the older camera to a different location.

Tuesday, August 25, 2009

Score!

My Craigslist bot script found a Squeezebox MP3 player with the enhanced screen for $20! This is the 3rd Squeezebox deal I got off Craigslist. The first I got several years ago for $35. The 2nd I found for $10, but it had a broken display & IR receiver. However, the folks at SlimDevices GAVE me a free replacement screen & IR receiver. Of course, those guys rock. This latest Squeezebox is replacing my office Rio Receiver and is paired with a ThingFling Altec Lansing SoundBar.

Saturday, August 22, 2009

Google Voice Automation

We've been using Google Voice since it was Grand Central. The one number for life really is a great convenience. I like having it ring all the phones I have when I get a call - so if my cell coverage is weak or I'm running out of minutes, I can just answer a landline. Realistically though, I only want it to ring all the phones that I can answer based on where I am. Recently, I found pygooglevoice, which exposes the Google Voice API to Python. This is exactly what I need - now I can write a script to choose which phones to forward calls to - based on where I am. No sense on forwarding calls there if nobody's there. Also, if my wife's at home but I'm at work, there's no need to bother her by having my calls forwarded home. With our Bluetracker software, the HA system can tell if we're at one of our homes and execute a Python script to forward to the appropriate phones.

A sample script follows, based heavily on the gvoice script included in pygooglevoice:

import sys
from atexit import register
from optparse import OptionParser
from googlevoice import Voice,util
from googlevoice.util import LoginError,input,print_

parser = OptionParser(usage='''gvoice [-e -p ] commands
Where commands are

home
work
home2
out''')
parser.add_option("-e", "--email", dest="email", default=None,
help="Google Voice Account Email")
parser.add_option("-p", "--password", dest='passwd', default=None,
help='Your account password (prompted if blank)')
options, args = parser.parse_args()

def login(email=options.email, passwd=options.passwd):
global voice
try:
voice.login(options.email,options.passwd)
except LoginError:
if input('Login failed. Retry?[Y/n] ').lower() in ('', 'y'):
login(None, None)
else:
sys.exit(0)

try:
action,args = args[0],args[1:]
except IndexError:
print "you need to give a command"
sys.exit(2)

voice = Voice()
login()

register(voice.logout)

if action == "home":
voice.phones[0].disable() # work
voice.phones[1].enable() # mobile
voice.phones[2].enable() # home
voice.phones[3].disable() # home 2
elif action == "work":
voice.phones[0].enable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].disable()
elif action == "home2":
voice.phones[0].disable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].enable()
elif action == "out":
voice.phones[0].disable()
voice.phones[1].disable()
voice.phones[2].enable()
voice.phones[3].disable()


You give it three options - your email address, your password and the command (in this case home, home2, work and out):

gvforward.py -e ABCdefGHI9876543210@gmail.com -p password work

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 20, 2009

Remove Hidden & Ghost Hardware from XP

Wow, it's been 2 weeks since I've posted. I don't really have any excuse, although my HAI UPB PIM died after less than a year. No warranty, of course, since I got it cheap off eBay. Anyway, I've been cleaning up my HA server today and thought this would be a useful topic.

One very annoying thing I've run into as I'm installing/removing hardware from my server is that I end up with unusable serial ports. For example, I was removing the bluetooth adapter quite often without uninstalling it. As as result, in the Device Manager, I ended up with things like Bluetooth Device (Personal Area Network) #26 and Standard Serial Port over Bluetooth link(COM25). Every time I unplugged the adapter, I lost 2 serial ports and created 2 more when I plugged it back in. This can cause a problem because some software isn't very happy with COM ports over a certain number. I suppose the easiest thing is to make sure to uninstall USB hardware like the bluetooth adapter before unplugging it, but sometimes you forget. In that case, here's a tip to help you uninstall the ghost devices and recover their resources. Thanks to this, I'm back down to COM11 instead of COM26 :)

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.

Tuesday, August 4, 2009

Remote W800 Deployed & Remote System Summary

I just installed the new W800 at our other house. In keeping with my tradition of cheapness, I ordered the bare $49 W800 instead of the $75 kit. I made my own power adapter from a leftover 9V wall wart and a 3.5mm mono jack (tip positive). I had 3 different 9V wall warts to choose from in my junk box, one output 8.7V, one 10.5V, and the third put out 11.5V. The W800 would only work with the highest output wall wart, which jives with the output from power supply from the first W800. Instead of the kit antenna, I connected the W800 to a set of leftover TV rabbit ears. I'm not looking for long distance reception as it's a small place. Finally, I had an extra serial cable in a spare parts bin.

I'm using xPLW800 and it works perfectly. I installed a few devices from my leftovers - 2 DS10A's as leak detectors and a few Hawkeye motion detectors. The motion sensors, combined with the Bluetooth tracking, will allow the system to track occupancy and execute the security lighting scheme if we're not around.

So far, the remote thin client is loaded up with:
* CM11A on a USB-serial adapter, using xPLCM11 for lighting/device control
* W800 on COM1, using xPLW800 for occupancy, dusk/dawn & leak detectors
* xPL Rocket for remote pan/tilt control of the USB rocket launcher & AirLink netcam wire-tied to it
* BlueTracker for occupancy detection
* EventGhost with xPL Plugin for all automation logic

With those apps running, there's still about 190MB of RAM free after I did the 512MB upgrade. CPU utilization is low, typically around 5-10% and briefly jumping to about 20-25% when an X10 command is issued. I can probably add a couple more small apps without killing the system.

The thin client is turning out to be the perfect device for our application. It is slow, but we don't interact with it at all, unlike our main home's automation server. It has low power consumption (10-12W), solid state disk reliablity and auto-powers on after an outage. I thought about putting it on a UPS, but since we won't be at house very often, I'm wary of leaving a UPS there. I've had one UPS burn up after several months and 2 others ended up with cracked and leaking batteries.

I've been very pleased with EventGhost as the heart of the system. It's lightweight in memory and CPU, has many useful plugins (Network Sender & Receiver are key for me) and has tons of flexibility with integrated Python scripting. It wouldn't be very useful to me if it weren't for the great xPL plugin I wrote ;)

Saturday, August 1, 2009

XTB Update

I plugged in the XTB and plugged into it the TW523 from my TimeCommander+, and now I've got solid X10 to the dead zone in the family room. Something was completely killing the family room, but now all is good. I haven't noticed any odd things when there's UPB on the power lines. Thumbs up for a great product.