May 182010
 

I have been into home automation and home entertainment for several years. When I was having my current house built, I had a lot of pre-wire placed in the walls for security keypads, thermostats, cameras, speakers, and video. And I also placed empty conduit in my walls in a few strategic places just in case I hadn’t thought of everything when I built the house (I didn’t, because I have already needed the conduit. Several times.) Here, I thought I would discuss my Home Automation (HA) setup.

First, I have the ultimate in home security, the Elk M1G. It is fantastic because it allows ethernet connectivity for monitoring by Elk specific programs or third-party applications, such as PowerHome. The end result is, if I open a door that is monitored by my security system, my home automation software, PowerHome, can detect that and react as I so designate. For instance, if I open my front door, the Elk tells PowerHome that the front door is open. PowerHome can check to see if it is dark outside, and if it is, it can turn my porch light on automatically. Then after I close the door, it will turn the lights off after four minutes. Want a text message if your security system alarm goes off? The Elk can handle this quite easily. Throw PowerHome on top of that and I could also have all the lights in the house start flashing. Starting to get the idea?

I have mentioned PowerHome already, so let me tell you about it. PowerHome is a very customizable and programmable Home Automation program. The best way to use it is to keep it running 24/7 on an HA PC. HA PCs are nothing special (but it is probably a good idea to find one that draws as little electricity as possible). I also use my HA PC as a Home Theater (HT) PC. PowerHome can easily interface with my security system, the Elk M1G, my lighting control system, Insteon, and other human interfaces such as infrared remote controls, email, and text messages. Because of the excellent integration between the Elk and PowerHome, I can easily write PowerHome programs to monitor my security system and react to changes. Similar to the example above, I have also written a PowerHome program that monitors my motion detectors in my house. If no motion is detected for 45 minutes and the system is not armed, PowerHome sends my work email and cell phones text messages asking if I forgot to set the burglar alarm. I can also monitor my garage door, turn on my garage lights automatically when I open the door, turn on lights at sunset and turn them back off at sunrise, and many other handy convenient features.

So, how do I turn on my lights? I use a lighting control system called Insteon. It allows me to link lights to switches in nearly infinite configurations. For instance, if I wanted my bathroom light switch to also turn on my garage light, I could do that. I don’t know why I would, but I could. I can also set up lighting scenes, such as movie watching and entertainment. Insteon devices primarily communicate with each other over the powerlines themselves, so they are very easy to set up. And the beauty of PowerHome and Insteon… they can talk to each other. PowerHome does this by the use of a USB Insteon module that plugs into a wall outlet. So, if I do turn on my bathroom light, PowerHome can also know about it and also open my garage door, or tun my stereo off. Again, I don’t know why, but I could. And PowerHome can also tell lights to turn on and off as well, such as at sunset/sunrise or upon a door opening.

Since my security system, lighting, and PowerHome are all so tightly integrated, I can also use a web browser from anywhere in the world, or my cell phone, and turn lights on and off, arm and disarm the system, and open and close the garage door. Not only is this convenient, but it also increases the home security and safety of the house. I don’t forget to arm my alarm, close the garage door, or turn the porch light on at sunset. Lights come on as I enter dark rooms. And I can monitor the whole system very easily.

May 112010
 

I’ve mentioned my Panasonic BL-C1A network cameras before in a post about monitoring the garage door. I happen to have two of these cameras, and I have automated them to do quite a lot for me. The software that comes with the cameras is pretty lousy, and it makes you think you have to use Internet Explorer and nothing else to look at the images coming out of the camera. Well, I can tell you it’s not true. Although, if you want to use the ActiveX controlling software that comes with the camera, you are limited to only IE. Not good enough for me. I want to be able to see the images on my cell phone, and I don’t like being tied to a single browser, especially IE. For instance, wget (as I used in yesterday’s post about pulling images from a web site) could be used to pull the images from the camera. I also want the images to be saved on a web server so that if my cameras themselves are stolen, or if my home computer is stolen, I will still have a backup of the images. Now, I don’t normally store or watch video from the cameras, but instead focus on storing still images. I can watch video, but I don’t currently know of an easy way to save the video to my web server.

There will be several steps to this process. First install the camera. Next, set up the port forwarding on your router so you can view the camera from outside your local network. Then we will set up some cron jobs on the web server to retrieve and save the images. Finally we will set up a web page so we can view the images that have been saved. If desired, the entire system can be controlled by the home automation system, and I will show you how I did that as well.

The first thing to do is install the cameras. Install the cameras using the software provided, but don’t worry. We won’t be sticking with that software. Make sure you can connect to your camera from a computer on your local network, using the software provided. I would now recommend that you set static IP addresses for your cameras. It defaults that way, so this should not be a problem. The default IP address should be something like 192.168.x.253, where ‘x’ is the same number as the rest of your networked computers, probably a 1 or a 0. Also, set the port to some high number, such as 8001. You will also want to set usernames and passwords for the camera. Next, using the IP address for the camera, use your NON-Internet Explorer web browser to view the images by going to this website:
192.168.x.253:8001?mode=local
If that works, then we have lots of other options:

http://192.168.x.253:8001/SnapshotJPEG?Resolution=320×240&Quality=Precision&mode=local

http://192.168.x.253:8001/SnapshotJpeg?Resolution=640×480&Quality=Standard&mode=local

http://192.168.x.253:8001/ImageViewer?Resolution=640×480&Quality=Standard&mode=local

There is a little more information about these addresses here:

http://tatethatcher.com/wp/archives/57

Great. Now we can see the images with any web browser. Video still requires a web browser that can handle java. Now let’s set it up so we can view the images from outside our local network by using port forwarding.

If you have a cable modem or DSL that is connected to the internet all the time, then you can probably set up port forwarding with that device. I use the world famous Linksys WRT-54G with the upgraded firmware DD-WRT. I certainly can’t tell you how to do this on every device out there, but port forwarding is quite common and searching google for “port forwarding yourdevicename” should give you a good place to start. However, the idea is simple. You want your router to recognize incoming traffic on a certain port and then automatically forward it to another port, such as 8001 in this case. The idea here is that you could be on a public computer in your library and go to http://some_site_yet_to_be_named.com:someportnumber and you will see the video on that camera. If you have more than one camera, you would go to the same site, but a different port number, such as http://some_site_yet_to_be_named.com:someotherportnumber. I used the same portnumber, 8001, but you could use a different one. So I can go to http://mysecretsite:8001 from any browser and see the video. So I need to go into the firmware settings for the router, and I will want to forward any traffic that comes into http://mysecretsite:8001 to http://192.168.x.253:8001. The port forwarding rules will not need to know anything about “mysecretsite”, so you won’t find any place to enter that setting. All you will have to enter is the incoming port, outgoing IP address and outgoing port. The incoming and outgoing ports in this case are both 8001 and the outgoing IP address is 192.168.x.253. At this point you could check and make sure the port forwarding is working by going to your router’s IP address (find it by going to http://whatismyip.com) followed by :8001, such as http://123.45.67.890:8001.

Related to the port forwarding is dynamic DNS. If you are lucky enough to have a static IP address, you can skip this paragraph. Otherwise you will need to follow the steps here to create a dynamic DNS host name. You can set up a free account at http://dyndns.com. Once your account is set up, add a host service with a hostname that you can remember. Have it point to your current IP address for now, but you will want to configure automatic updating. You can either use free software or even easier, you might be able to configure the automatic updating right within your router. If it works, you should be able to go to your new host:

http://mynewhost.homedns.org:8001/SnapshotJpeg?Resolution=640×480&Quality=Standard&mode=local

and see the images from the camera. At this point step two is complete. You can save that URL and you will always be able to view your camera from any web browser on the internet.

The last step is to set up some cron jobs on your web server to grab the images from your camera and save them to a specific directory on your web server. This way you will be able to review past images as needed. It will require you to have a web server that you have shell access to. Some web hosts out there that do allow shell access do not allow scripts to run for extended periods of time. I use dreamhost (http://dreamhost.com), which works perfectly.

#!/bin/bash
# getfamroomwebcam.sh

while :
do
THISFILE=`date +/home/httpdocs/FamilyRoomWebCam/%Y%m%d%H%M%S.jpg`
wget --http-user=camera_user --http-passwd=topsecret -O ${THISFILE} -q http://mynewhost.homedns.org:8001/SnapshotJpeg?Resolution=640x480&Quality=Standard&mode=local
sleep 20
chmod 644 ${THISFILE}
done

As long as this script is running it will grab a new image from the camera every 20 seconds. It saves the images with a timestamped file name. You could configure this to start running at server startup, maybe have a cron job that checks to see if it is running periodically (like once an hour) and if it finds that the script is not running, restart it. I have it set up so that whenever I arm my burglar alarm (Elk M1G), the elk sends an email to my web server with a special code. Procmail reads the email and if it sees the special code, it starts (or stops, on disarming) the script. Here is my Procmail script to start the web cam:
:0
* ^Subject:.*SecretStartCode
{
:0w
| /home/script/getfamroomwebcam.sh &

:0
/dev/null
}

Finally, I have another cron job to delete old pictures every night. Otherwise the picture directory would get very full very fast. I don’t think dreamhost would like that at all.

find /home/httpdocs/FamilyRoomWebCam -mtime +3 -exec rm {} \;

This will delete any pictures older than three days old.

The very last step is I wrote a small web page to display the images. It uses javascript to play the images in a slideshow, or it can display all images from a specific time period. For now I will leave that up to you, but I will post the code for it in a few days.

May 102010
 

This isn’t just another “how to rotate your Windows Desktop image” post.  Search for that on Google and you will find many solutions for that.  I am going to show you how to use a specific image that is posted periodically to the web and have that as your desktop image.  For instance, let’s say your favorite cat photo website has a feature where they post the Cat Photo of the Day.  If they always post that image with the same file name (cpotd.jpg, perhaps), each day over-writing the image with the new image, then you could use that image as your windows desktop wallpaper, and whenever the photo is updated, you would have the latest photo on your desktop as well.  Now, there are RSS solutions to do something similar, but the difference here is that the file must always be named the same each time they update the photo.  Actually, this method is quite common for images that are updated periodically.  Many weather sites use the same image name for the latest weather map, for instance.  And many sites that do have a photo of the day feature as I described above use this method of updating their image.  Ready to do it yourself?

There are three parts to this.  First we need to identify an image that is suitable for our needs.   Remember, it must always have the same filename.  This method won’t work if today they name the image “20100509_cpotd.jpg” and tomorrow they name it “20100510_cpotd.jpg”.  Although with a little creative programming (perhaps using windows power shell), this could be worked around quite easily.  Step two involves writing a batch file and creating a shortcut to pull these steps into one small program. The final step will automate a means to download the updated images on schedule.

I am going to use an image from a very cool website, http://www.die.net/earth/.  This site displays an image of the earth rendered in real time, with a correct display for where it is daylight and evening.  It also shows the latest cloud cover.  It makes for a really cool image and it can easily be used for your desktop image.  But first, we need to make sure that the image filename is always the same.  Right click on the image and choose “Copy image URL”.  Then paste the image URL into the address bar of your browser and hit enter.  You should see a “web page” with nothing more than the image itself.  And we can now see the image URL, http://static.die.net/earth/mercator/1024.jpg.  Ok, it doesn’t look like they have any time or date strings in there, so my guess is, the filename is always the same.  But why is it named 1024.jpg?  1024 is a common width for desktop resolution, and is a common width for online images as well.  I wonder if a higher resolution is also available?  Let’s change the 1024 to 1600 and see what happens.  Sure enough, that gives us a larger image.  We will use http://static.die.net/earth/mercator/1600.jpg as our source image.  Now, how often is the image updated?  Well, I have been looking at this site for a little while, and it would appear that the image is updated about every half hour.  I’ll keep that in mind as we go along.

Next, we need a means to automate the download and storage of the image.  I like a program called wget which is originally a command line tool for unix/linux just for retrieval of web pages and images.  It’s actually a quite powerful tool, and of course it is free and yes, there is a windows version available for us right here. After you are done with this exercise, I am sure you will find other uses for wget, such as backing up your website. Go ahead and install the windows binary for wget.  I used the “Complete package, except source” setup file.  If you prefer zipped files, go ahead and choose that.  When the installation is complete, wget should be installed in your c:\Program Files\GnuWin32\bin folder.  Open a command prompt by clicking on the start menu and typing “cmd” and pressing enter.  Then type

cd c:\Program Files\GnuWin32\bin

(here’s a hint:  try typing cd c:\Pro{Tab}\Gn{Tab}\bin{enter}).  Once you are in the correct folder, type

wget http://static.die.net/earth/mercator/1600.jpg

and press enter.  You should see wget do its thing and download the file.  The only trouble is, the file is downloaded to the current folder–not a really good thing to do.  Let’s make a folder just for our Earth Image and tell wget to store the image in that folder.  Make a suitable folder somewhere and name it something appropriate.  I used c:\users\skip\Pictures\EarthImage.  I would recommend using a path that has no spaces, like “My Pictures”.  Spaces can sometimes mess up automated programs like this.  Now that we have created that folder, let’s run wget again, this time using the -O option.  Option O tells wget where to store the output.  So the command this time will be: (type this command all on one line. Do not type the &&. That just shows that this line continues to the line below.)

wget -O C:\Users\skip\Pictures\EarthImage\earth.jpg &&

http://static.die.net/earth/mercator/1600.jpg

Note that I also changed the name of the file itself to earth.jpg.  Look in the folder and you should see our earth.jpg image, saved and ready to be used.  Now let’s see if we can apply that image as our wallpaper. I like a free program called “command line wallpaper changer portable”. Once it is installed, you just open a command prompt and enter

C:\Users\skip\CLWCP.exe C:\Users\skip\Pictures\EarthImage\earth.jpg

And you should see the image on your desktop. As you can see, I copied the executable clwcp.exe to my profile folder, but you can run it from wherever you want. If that works, step one is complete.

Step two is to automate the retrieval of these images. I want to do a few things to make the scheduling go easier and I also want to prevent the command prompt window from taking focus when it runs (I would like to update the wallpaper in the background without you really noticing that it is happening.) To do this, we will make a batch file called “GetEarthShot.bat” and save it somewhere like a utilities folder (I save mine in my profile folder, c:\users\skip). The batch file will only have two lines:

"C:\Program Files\GnuWin32\bin\wget.exe" -O C:\Users\skip\Pictures\EarthImage\earth.jpg http://static.die.net/earth/mercator/1600.jpg
C:\Users\skip\CLWCP.exe C:\Users\skip\Pictures\EarthImage\earth.jpg

Can you see how it works? When this batch file runs, it will execute those two lines. First it will download the latest image. Then it will apply the image as the wallpaper. Save the file and double-click in in Explorer and you should see the command window pop up and see the two commands execute. Now, in order to make the command window itself NOT pop up (I find it distracting, and it can take the keyboard focus away), we will create a Windows shortcut to the batch file and set some properties to make sure it runs in the background. Right click on the GetEarthShot.bat file in Explorer and choose “Create Shortcut”. You should see the shortcut appear in explorer. Rename it so the “- Shortcut” isn’t there. I renamed mine to the same thing as the batch file itself: “GetEarthShot.bat”. Now right click on the shortcut and choose properties. You should see that the target is set to point to your batch file. Change the “Start in” parameter to “C:\Program Files\GnuWin32\bin\” (including the quotes). Finally set the “Run” parameter to “Minimized”. Click OK to save the changes and test it by double clicking the shortcut. If you watch VERY carefully, you might see the window pop up for a very, very brief moment, and then you may notice the icon on the task bar indicating that the batch file is running. After two or three seconds, the icon should go away and your desktop image should be updated. Now, if you are running this right away after initially setting the image when we first tested it, you may not be applying a NEW image, so you may not notice anything different. Step two is complete. Now let’s automate the whole process.

Go to Control Panel -> Administrative Tools -> Schedule Tasks.  On the left side, if you click on Task Scheduler Library, you will see all of your scheduled tasks in the center pane.  On the right, click on “Create Basic Task”.  I used “Update Earth Image” as the name and I gave it a nice description as well.  Click the “Next” button.  For the trigger, choose “After logon”.   Click “Next”.  Under “Action”, chose “Start a program”.  After clicking “Next” you will enter

c:\users\skip\GetEarthShot.bat.lnk

And under “Start in”, enter

c:\Program Files\GnuWin32\bin\

Note that the full path to wget is in the command line.  Click “Next”.  Click to enable to “Open the properties dialog for this task when I click finish” and then click finish.  The properties dialog should pop up.  Click the Triggers tab and then “Edit”.  Under Advanced setting, click the “Repeat task every” and set the frequency to 30 minutes, for a duration of Indefinitely.  Click OK to exit and save the task.  This task should now run every 30 minutes.  So now, every 30 minutes, that folder will be updated with the latest earth image, over-writing the image already there.  If you right click on the task and choose “Run”, the task should run. You should see the batch file run minimized as we did before. If all is well, reboot your computer to get the task going. Step three is complete and you are done.

Using the process here, you could do a lot of things with wget setting up some cool rotating images. Good luck!

May 082010
 

Do you have billions and billions of password to remember? Well, maybe not quite that many, but I can tell you that I currently have 113 username and password pairs that I am remembering, mostly for logins to different websites. What if I told you that most of my passwords are something like “L6qjB5NM04GEXjTTeXeQ”. I try hard to not use the same username and password for every site I visit. I used to. It’s the only way you could possibly remember all those passwords.

Now I use a free program called KeePass to manage my passwords. Every time I register for a new account at a new website, I fire up KeePass and add a new entry. KeePass already has generated a password similar to the one I showed above. I then copy and paste that pre-generated password in the desired password field on the registration for on the website. If the website accepts the new password I save the entry in KeePass. The websites almost always accept the generated password from KeePass, but would you believe that sometimes my passwords are too long and the website forces me to trim down the length of the password? Sad. And that’s it. No more having to remember passwords.

Ahh, but you don’t want to use a password manager because you have multiple computers and you will need access to your passwords no matter where you are. I get that. That was what kept me away from such a program too. Well, I have the perfect solution. And it comes with lots of nice side effect features too. Get yourself a free Dropbox account. Dropbox is a file synchronizer that allows you to automatically sync up files and folders over the internet. If you work on some files at home and work, then you have undoubtedly forgotten your thumb drive once before, or forgot to copy over the latest version before you left. Well, dropbox can easily solve that problem for you. The Dropbox program watches a certain folder (or folders) on your computer. Whenever a file is added, changed, or deleted in that folder, the change is propagated automatically over the internet to any other computers on which you have installed dropox. So when you get to work after adding a new file to your dropbox at home, the file is happily waiting for you in your dropbox folder at work. So, to make this work with KeePass, just save your “key ring” (your database) to the dropbox folder. KeePass allows you to save and open database files from any folder, so this works quite well. Then all you have to do is install KeePass on your work computer too, and tell it to look in the DropBox folder for the key ring, and you will see all of your entries saved their. Now you can easily add new entries on either computer, and the change will be propagated to the other computer. Of course you could also install Dropbox and KeePass on your laptop too, so that you have access to your passwords (and files) when you travel.

Finally, there is an Android app for KeePass too. There is not a dropbox app, so you will have to periodically copy over (or email) the latest database to your phone so it has (a somewhat) up to date database. I try to do it around once a month or so. This also has the added benefit of backing up my database. Dropbox is pretty good about recovering accidentally deleted files, but really bad things can happen, and losing every password would be really bad. By having a copy in my email that I can go back to retrieve a copy, I know that I will always have a fairly recent backup that I can rely on.

And for the record, even though Lifehacker has also given instructions on how to do this, I figured it out before they did :) I just wasn’t smart enough to blog about it.

http://lifehacker.com/5063176/how-to-use-dropbox-as-the-ultimate-password-syncer

May 072010
 

As I was flying to Japan today, I crossed 11 time zones. When I was in the Navy, I had to really understand time zones because I was regularly working with other commands across many different timezones. Today’s posting is intended to teach you a little more about time zones.
There are 25 world time zones. Each time zone is centered upon every 15 degrees of longitude (7-1/2 degrees on each side of the 15 degree increment) except for the two time zones on either side of the international date line. Those are each only 7-1/2 degrees wide.
Each time zone is represented numerically by a number and a plus or minus sign, such as -5. That number indicates what you need to add to GMT in order to calculate the time in that time zone. In the example of -5 (which happens to be the time zone for EST, or the east coast of the United States in the summer time), we need to add -5 hours to the local time in GMT to determine the local time in the -5 time zone. GMT is centered on the prime meridian, or 0 degrees longitude. It is twelve hours from the international dateline.
The time zones are also represented in the US military by a letter. This works out great since there are 25 time zones and there are 26 letters (want to guess which letter is not used?). GMT (also called UTC for Universal Time Code) is represented by the letter Z, or the word ZULU. The first zone to the west of GMT is labeled N. But it is 1 hour before GMT, it is also labeled -1. To put it all together, we usually call that time -1N (and we usually use the phonetic spelling of N, which is NOVEMBER). So if you were talking about that time zone, you would refer to it as “minus one November”. The next time zone to the west is mike, and it is -2. The first time zone to the east of GMT is A (or alpha) and is labeled +1. And so on. See the table below for the list of all time zones and it’s letter designation.

Abbreviation Full name Time zone Start Long. Center Long. End Long.
Z Zulu Time Zone UTC -7.5 0 7.5
Y Yankee Time Zone UTC – 12 hours -180 -176.25 -172.5
X X-ray Time Zone UTC – 11 hours -172.5 -165 -157.5
W Whiskey Time Zone UTC – 10 hours -157.5 -150 -142.5
V Victor Time Zone UTC – 9 hours -142.5 -135 -127.5
U Uniform Time Zone UTC – 8 hours -127.5 -120 -112.5
T Tango Time Zone UTC – 7 hours -112.5 -105 -097.5
S Sierra Time Zone UTC – 6 hours -097.5 -090 -082.5
R Romeo Time Zone UTC – 5 hours -082.5 -075 -067.5
Q Quebec Time Zone UTC – 4 hours -067.5 -060 -052.5
P Papa Time Zone UTC – 3 hours -052.5 -045 -037.5
O Oscar Time Zone UTC – 2 hours -037.5 -030 -022.5
N November Time Zone UTC – 1 hour -022.5 -015 -007.5
A Alpha Time Zone UTC + 1 hour 007.5 015 022.5
B Bravo Time Zone UTC + 2 hours 022.5 030 037.5
C Charlie Time Zone UTC + 3 hours 037.5 045 052.5
D Delta Time Zone UTC + 4 hours 052.5 060 067.5
E Echo Time Zone UTC + 5 hours 067.5 075 082.5
F Foxtrot Time Zone UTC + 6 hours 082.5 090 097.5
G Golf Time Zone UTC + 7 hours 097.5 105 112.5
H Hotel Time Zone UTC + 8 hours 112.5 120 127.5
I India Time Zone UTC + 9 hours 127.5 135 142.5
K Kilo Time Zone UTC + 10 hours 142.5 150 157.5
L Lima Time Zone UTC + 11 hours 157.5 165 172.5
M Mike Time Zone UTC + 12 hours 172.5 176.25 180

So, what happens when daylight savings kicks in? Daylight savings (also known as “Summer Time”) affects the zone descriptions. Assume one day I am on standard time and I have a particular zone description (say, -5R). When daylight savings kicks in, I will then have a different description (in this case, -4Q).
The time zones do not follow the 15 degree +/- 7-1/2 longitude lines exactly. Sometimes the lines are adjusted for political reasons or convenience.
What’s more, there are some areas that are 1/2 hour ahead/behind the nearest time zone instead of the usual hour and there are even some areas that follow quarter-hour differences.

May 052010
 

Inevitably after I get comfortable in my couch to watch a good movie, I realize that I haven’t set my room lighting to the optimal levels. Or I realize that I have left lights on upstairs. Because I am lazy, I don’t want to get off the couch to dim the family room lights or even worse, go upstairs to turn those lights off. Instead, I just press a button on my Harmony remote control and the lights are set however I want. You will also need an USB-UIRT to receive the IR signals and a 24/7 computer running PowerHome to do the work (I use my HTPC). Of course, you will also need some type of automated lighting. I have Insteon to control my lights.

You could do this with an old, unused remote, but I don’t like to have any extra remotes lying around my family room, so I really prefer the Harmony remote for this. If you don’t have a Harmony remote, and you don’t want to bring another remote into your living room, one other option would be to assign an unused button on your current remote control to be your lighting button. The whole idea here is you need transmit a unique IR signal such that whenever it is seen, it will, say, turn your upstairs lights off. If you do have a Harmony, you can add a new device that you don’t currently have in your home theater (you don’t want to be sending out signals that actually do something). Then you can go to the adjust buttons menus and Rename the labels for the soft buttons. Label one “Upstairs” and one “Fam Room”. It doesn’t matter what the IR command is. It could be channel up, the number 8, video toggle, mute, or anything else. We will learn the commands into the USB-UIRT and PowerHome, so it doesn’t matter what command is coming out of the remote.

Next, install the USB-UIRT and make sure it is working. To do that, just… um.. plug it in. They are pretty much fool-proof.

Next, we need tell PowerHome that you have a new controller. Go to the PowerHome explorer and expand the Setup branch and add a new Controller. You will see that there is already support for the USB-UIRT. Go into the settings for the device and set the type to “Pronto”. Shut down PowerHome and restart. PowerHome is now ready to receive IR triggers.

Next go into the PowerHome explorer and expand the Setup branch once again. This time go to Devices. Add an IR device and set it for about 20 IR commands. Then you can expand the newly added device in the navigation tree and start learning IR commands. Right click on a blank row and choose “Learn IR”. Take your remote control to the USB-UIRT and press the button corresponding to the command you are learning. I have found that you have to get an inch or two away from the UIRT when learning commands. If it learns OK, you should see an ASCII string representing the command.

Now we need to add a trigger for the newly learned IR command. But before we can do that, we need a macro that will be executed whenever the IR command is detected. Build a macro that has the one line INTSTEON GROUP OFF and select the group corresponding to your upstairs lights. Run the macro and ensure your upstairs lights turn off. Now build that trigger. Select the trigger type to be IR, select the device and command. Enter in the macro to be run and you should be good to go. Press the button on your remote and the lights should turn off.

The final step is to click over to your HTPC, start a movie that you have ripped to your hard drive, turn off the lights and enjoy :)

May 042010
 

I hate it when I send an email only to get an email back from the recipient saying that I forgot to include the attachment that I referred to in my email.  How annoying.  I also hate it when I forget to fill in the subject line.  I don’t like receiving emails with no subject lines and I hate it even more when I accidentally send one myself.  So I found some VBA macros that I could add to Outlook which will look for certain criteria which may indicate a forgotten attachment.  The missing subject line is a little more straightforward. I always want a subject line and when I hit the send button, it’s either there or it isn’t, but the attachment detector has to first figure out if I intended to attach something.  So, let’s just jump into the code.  I found the majority of this code at http://msmvps.com/blogs/athif/pages/48968.aspx but you will see that I made some changes to it to suit my needs.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngres As Long
If InStr(1, Item.Body, "attach") Or InStr(1, Item.Subject, "attach") <> 0 Then
If Item.Attachments.Count = 0 Then
lngres = MsgBox("word 'Attach' found, but no attachment - send anyway?", _
vbYesNo + vbDefaultButton2 + vbQuestion + vbSystemModal, "You asked me to warn you...")
If lngres = vbNo Then Cancel = True
End If
End If

If InStr(1, Item.Body, "include") Or InStr(1, Item.Subject, "include") <> 0 Then
If Item.Attachments.Count = 0 Then
lngres = MsgBox("word 'include' found, but no attachment - send anyway?", _
vbYesNo + vbDefaultButton2 + vbQuestion + vbSystemModal, "You asked me to warn you...")
If lngres = vbNo Then Cancel = True
End If
End If

If InStr(1, Item.Body, "enclose") Or InStr(1, Item.Subject, "enclose") <> 0 Then
If Item.Attachments.Count = 0 Then
lngres = MsgBox("word 'Enclose' found, but no file enclosed - send anyway?", _
vbYesNo + vbDefaultButton2 + vbQuestion + vbSystemModal, "You asked me to warn you...")
If lngres = vbNo Then Cancel = True
End If
End If

strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub

The first thing to notice is that this macro is executed whenever you click the send button (or press ctrl-enter). Whenever you start the send process, this macro executes. The first three parts of the code look for the words “Attach”, “Include” and “Enclose” in the body of the email as well as the subject line. Sometimes I just send an email with the subject line “Final report attached” and nothing in the body. I want the trigger to recognize this. Also, the triggers are not case sensitive and they will also hit on other forms of the word, such as “Attached”. So, if one of those key words is found, it will then check to see if there are any attachments in the email. If there are no attachments, a dialog box is presented stating that one of the keywords was spotted yet there were no attachments found. Do you still want to send the email? It can happen that you might be replying to a quoted email that someone sent you and had the word “attach” in it. Most people when they reply to an email, they include the original sender’s quoted email. You may not have any intention of including an attachment in this case, but the macro will still find the word “attach”, so it gets triggered. I wish there was a way to have the macro only look at the new text that you added, but there doesn’t seem to be. If you answer “No” to the question “Do you still want to send”, then the send process is cancelled and you will have a chance to add your attachment. If you choose “Yes” then the email is sent as usual.

The last section of code looks for blank subject lines. The methodology is the same as the other sections, and is probably self explanatory.

To make this code work in your Outlook, just copy the code to the clipboard, open Outlook and press alt-F11. On the left side, you will see a standard navigation tree. Under Project1 (VbaProject.OTM) expand Microsoft Office Outlook Objects. Double Click on “ThisOutlookSession” and then paste the code in the code pane. Save your work, close Outlook and restart it. Try and test the code by sending yourself some test emails.

I hope this helps some of you.

May 042010
 

This week I am flying to Japan for a business trip. I have only been there once before for another business trip and I really enjoyed it, so I am really looking forward to going again. Except for the whole 15-hour flight part. That part isn’t so great. But it is good to know that Great Circle Routes can shorten the travel distance (and time) considerably.  Compare the great circle route shown in this picture with the straight heading route from the image below.  Note that it almost passes north of Canada and Alaska, and skirts along the eastern coast of Siberia.  In fact, when we take off, we will be heading close to a northerly direction (approximately 332 degrees).  Along the way, the plane will have to alter its heading to stay on this route.  In fact, as we approach Japan, we will be heading almost due south.  The entire route will be a big sweeping left turn.  Every 30 minutes or so the plane will alter course by about 8 degrees to the left.  This seems a little confusing because the equator is a great circle, and if I flew a path between two cities on the equator, that would indeed be the great circle route and the shortest route.  But I wouldn’t have to change course from either due east or west.  That’s only because the equator just happens to be a great circle that lies on a cardinal heading (east-west).  Also, if you were flying a great circle route that had you going either due north or due south, you would not have to alter your heading during the trip.  In this case you would be flying along a line of longitude.  Other than these two special cases, all other great circle trips require periodic heading alterations to stay on course.  So let’s analyze my trip.

The Newark airport is at 40° 41′ N 074° 10′ W and the Narita airport in Tokyo is at 34° 45′ N 140° 22′ E.

Using regular trigonometry we can calculate the distance between these two airports using the fact that on average a degree of latitude is about 69.1 miles long and a degree of longitude is about 53.0 miles long. So all we do is calculate how many degrees of change in latitude and how many degrees of change in longitude there are between the two points, and multiply it by the mileage factors. Now, this formula makes one big (incorrect) assumption. That is, that the distance between two points long a line of longitude is the same at all latitudes.  In just a minute, we will correct for that. So, using Pythagorean, and taking the north-south change as the “X” and the east-west change as the “Y”, we can calculate the length of the hypotenuse.

We are basically trying to calculate the length of this line:

That is the route you would take if you pointed your plane right at Tokyo and flew straight at it the whole way.  As you know, when you fly on a great circle route, you have to periodically alter your heading  to stay on the route.

x= 69.1 * (lat2 - lat1)
y = 53.0 * (lon2 - lon1)

For the math to work out, north latitudes are positive and south are negative; east longitudes are positive and west are negative, and we need to convert the degree-minutes-seconds into decimal degrees

dist = \sqrt{x^2 + y^2}

Newark, NJ
lat1 = 40+41/60 = 40.6833
lon1 = -74+10/60 = -74.1667

Tokyo, Japan
lat2 = 34+45/60 = 34.75
lon2 = 140+22/60 = 140.3667

x = 69.1 * (34.75 - 40.6833) = -409.9910
y = 53.0 * (140.3667 - -74.1667) = 11370.2702

dist = \sqrt{11370.2702^2 + -409.9910^2} = 11377.6596 miles

But now let’s try and adjust for the difference for different distances at different degrees of latitude.

The improved formulas are:

AvgLat = (lat2 + lat1)/2
x = 69.1 * (lat2 - lat1)
y = 69.1 * (lon2 - lon1) * cos(AvgLat)

When taking the cos calculation, make sure you are calculating in degrees mode, not radians.

dist = sqrt(x^2 + y^2)

Substituting our values in

AvgLat = (40.6833 - 34.75) / 2 = 37.7167
x = 69.1 * (34.75 - 40.6833) = -409.9910
y = 69.1 * (140.3667 - (-74.1667)) * \cos(37.7167) = 11726.6589

dist = \sqrt{11726.6589^2 + (-409.9910^2)} = 11733.8239

Which, interestingly, is higher than the first approximation, yet is considered more accurate. However, it probably is pretty close to the actual distance that would be traversed if that route were indeed chosen. The number does make sense though.  The circumference of the earth is about 24,000 miles.  I am not going quite half way around, so a number a little less than half seems to be about right.  I would not recommend choosing that route though because the great circle route is shorter by several THOUSAND miles. Let’s calculate it.

First, convert all the lats and longs to radians.

Newark, NJ
lat1 = 40.6833 / 57.29577951 = 0.7101
lon1 = -74.1667 / 57.29577951 = -1.2945

Tokyo, Japan
lat2 = 34.75 / 57.29577951 = 0.6065
lon2 = 140.3667 / 57.29577951 = 2.4499

The formula for great circle distance is

3963.0 * arccos[\sin(lat1) * \sin(lat2) + \cos(lat1) * \cos(lat2) * \cos(lon2 - lon1)] 3963.0 * arccos[\sin(.7101) * \sin(.6065) + \cos(.7101) * \cos(2.4499-(-1.2945))] = 6788.5935

For these calculations, you will need to do the trig functions in radians mode.

Google earth calculated 6724.76 miles. It looks like they are off by about 60 miles :)

Actually, I did some rounding along the way here, and these calculations are very prone to precision errors.

But what a difference!  As you can clearly see, the great circle route is the way to go here.

Finally, even though this is the shortest route, it may not be the fastest route. The airlines are pretty smart about taking other things into consideration, namely the high altitude weather. They like to fly with the wind on their tails to give them a little boost. Sometimes it can be quite significant.

Now, I have not gone into why great circle routes are the shortest routes.  Hopefully you already understand that, but if you are a little rusty on that concept, there is plenty of reading material available on the web.  But as you can see from our simple calculations here, the distance saved is significant by choosing a great circle route.

The formulas for calculating great circle distances are well documented and are known as the spherical laws of cosines.  I used this web page for most of my verification.

May 022010
 

This functionality has been evolving as of mid 2011 and may not work for you. Sirius/XM has been changing the format of their online streaming. Watch http://www.permanence.com/sirius/ for the latest information.

If you are a Sirius online subscriber, then you can listen to most of the Sirius channels online in most web browsers.  It’s a very nice way to listen to Sirius at work.  The quality is quite good too.  But did you know you can easily add the same Sirius channel lineup to your Windows Media Center?  Here’s how I did it.

First, of course you will need a computer with Windows Media Center.  I happen to be running Vista x64, but I believe this will work on all versions of WMC.  Next, you will need to get a small, free program called “Sirius XM streamer“, which basically sets up a proxy on your computer to the Sirius streams.  To install it, you will have to have the .Net 3.5 framework installed on your computer (also free).  Installation instructions are available on the Sirius XM streamer website.  When you get the streamer installed on your computer, go to the configuration page and enter your Sirius username and password.  The streamer should also work for XM streaming, but I don’t have XM, so I can’t speak for that.  For the default stream protocol, choose HTTP and for the format choose ASX.  Leave Listening IP set to All and listening port set to the default 51710.  Your published URL should look like http://127.0.0.1:51710.  The TVersity Media Server details can be ignored.  On the options menu, enable the start server automatically option.  Start the server and after a few seconds you should see the server running messages.

For each channel that you want to appear in the Radio list in WMC, you will need to create two text files and one JPG.  Place these files in your

C:\Users\USERNAME\AppData\Roaming\Media Center Programs\Radio

folder.  Of course replace USERNAME with whatever username you use when you run WMC. You may need to create the folder.  Here are the two text files I needed for Sirius Hits One.  I named them “Hits One.mcl” and “Hits One.htm”.  And I created a subfolder C:\Users\USERNAME\AppData\Roaming\Media Center Programs\Radio\Sirius for the icon images.

Hits One.mcl

<application  name="Sirius 1 - SIRIUS XM Hits 1"		
 url="Hits One.htm" 			
 startimage="Sirius\Sir001.jpg" 		
 thumbnailimage="Sirius\Sir001.jpg" 		
 description="The sound of generation Now!" 			
 category="1" 				
 companyname="">				
 <capabilitiesrequired  directx="false" 	
    audio="true" 				
    video="false" 				
    intensiverendering="false" 		
    console="false" 			
    cdburning="false" 			
 />					
</application>

Hits One.htm

<script>							
function IsMCEEnabled()					
{								
return true;						
}								
window.external.MediaCenter.PlayMedia(1, "http://127.0.0.1:51710/xm?channel=2&format=asx" );
window.external.MediaCenter.Experience.GoToFullScreen()    
window.external.MediaCenter.CloseApplication();		
</SCRIPT>

You can see where the mcl file points to the jpg image to use for the icon. Those images are 124×124 pixels, regular jpg files. I didn’t do anything fancy with them, but I did try using gifs and tried to get the transparency to work, but it would not. If you have better luck, let me know. Also, I do not know what the difference is between “startimage” and “thumbnailimage”. As you can see I set them both to point to the same image, and it seemed that it had to be that way. Again, if you figure something else out, let me know.  Place the images in the Sirius subfolder created above.

I have uploaded a zip file with all of the images for each Sirius channel here

May 012010
 

I am paranoid about closing my garage door. Or leaving it open. Whatever. I don’t think I’ve ever had anything stolen out of my garage, or any nefarious person (or varmint) enter my house through my open garage door, but I am paranoid about it nonetheless. Have you ever left for work in the morning, walked out to your car to see your garage door wide open?  Or have you ever come home from work to see you garage door open because you forgot to close it on your way out of the driveway in the morning? Me too. So I take matters into my own hands now. It would be impossible for me to leave my garage door open with me at home or away. Can’t happen. Would you like to know how I do it?

First, the required equipment and software:
I have an Elk M1G Security system
I use PowerHome for home automation
Optional, for the really paranoid, I have a Panasonic network camera which can watch the door
and I needed one addition magnetic zone sensor

My house did have a burglar alarm installed when I bought it, with sensors on all of the first floor doors and windows *except* the overhead garage door. I believe this is common practice for new homes, but I may be wrong. My house also came with a very inexpensive, builder’s grade burglar alarm. I immediately replaced it with the Elk M1G because it offers so much in the way of home automation. More about the M1G in later posts here for sure. I then installed a magnetic sensor on the garage door so the M1G would know when the door was open and closed. I have a home theater personal computer (HTPC) which also does my home automation. It is on 24/7 and I don’t know how I would live without it. It is the same closet where my burglar alarm is installed. I have PowerHome installed on that computer, which is capable of communicating with the Elk over IP. Finally, I ran a pair of wires in parallel across the “doorbell” switch in the garage back to a relay output on the Elk. The Elk has inputs and outputs, just like any computer. Zone sensors are inputs, but in this case I hooked up this wire pair to an output. The Elk can control the output (that is, electrically close or open the output) as required. It’s nothing more than a relay. The idea here is I want the Elk to be able to close the garage door, so I gave the Elk its own set of wires which bypass the doorbell switch in the garage. With that, I have everything that I need to complete this project.

The Elk keypads have four programmable buttons which can also be illuminated based on rules. I wrote a rule and function to illuminate a button whenever the garage door was open. I wrote a function to close the output that I connected the doorbell wires to above for one second when I press that button. So I press the button on the Keypad, the Elk interprets that and says “oh, he pushed the button, so I need to close this relay for one second”. Closing the relay for one second is the same thing as pressing the doorbell switch in my garage for one second because I have wired that relay as a bypass in parallel across the doorbell switch. I also added some logic so I can’t accidentally open the garage door from the keypad. The logic checks to see if the door is already closed, and if it is, it doesn’t do anything else. Therefore it won’t accidentally open the door. Great, so I can so look at any keypad in my house and see if the door is open or closed. And if it is open, I can close it. But that’s not good enough.

The Elk M1G is also capable of voice enunciations. I have my Elk connected to a couple of in-wall speakers throughout my house. Now, whenever my garage door is opened, the Elk starts counting down from 60, decrementing by one each minute. When it hits zero it announces throughout my house “Garage door is open” and then resets the counter. So I get hourly reminders that my garage door is open.

I also have PowerHome check to see if the garage door is closed seven minutes after the security system is armed. If the door is not closed, then PowerHome sends me, and my wife text messages on our cell phone, and our work email address a notification that the burglar alarm is armed, but the garage door is open. PowerHome has a built in web server and I have written a front end that can also display the status of the garage door, and of course, it also has a button that I can click and close the garage door. All this is accessible with our cell phones or any web browser.

And yes, I am really, really paranoid, so I also have a Panasonic IP camera in the garage so I can pull up a web page that stores the most recent images from the camera and verify visually whether on not the door is closed.  More on the Panasonic cameras in a later post.

As you can see, I am really paranoid about my garage door.  But I can tell you I have not left it open overnight in years.  Nor have I come home from work to see it wide open either.  This functionality gives me a lot of peace of mind and I am really glad that I have automated every aspect of my garage door.