• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Make Your House Talk > Scheduling and Logic

4.5. Scheduling and Logic

There are many different ways you can tell your computer to read you the weather. The Control Distribution phase of Chapter 9 shows you how to do it with an IR remote. If you'd rather use a wall switch or an X10 remote, review Chapter 2—the Perl script can listen for X10 signals and launch the script on demand.

For this project, I decided to keep things simple and launch the script at a regular time every day. (My favorite user interface is when the user remains completely passive.)

4.5.1. 1. Install the Firecracker, Perl, and Perl X10 modules

As described in Chapter 12, install the Firecracker wireless X10 interface, Perl, and the Perl X10 modules.

4.5.2. 2. Create the script

You need to turn on your wireless speakers, call your C# application to retrieve the current temperature, create an English sentence, and send that sentence to the C# application that synthesizes it into the spoken word. As with most projects, Perl is my choice for gluing multiple components together. Type up the following script and save it as C:\homehacking\SpeakWeather.pl, then download it, along with any updates I've made, from http://www.homehacking.com.

Various applications make it easy to edit Perl scripts, but Notepad works just fine too.

	use lib './blib/lib','./lib';

	my $speaker_unit = "N3"; #Set to house code of cameras
	my $zipcode = "01801";

	my ($OS_win, $serial_port);

	# Load the proper SerialPort module based on platform
	BEGIN { $| = 1;
	  $OS_win = ($^O eq "MSWin32") ? 1 : 0;

	  if ($OS_win) {
	     eval "use Win32::SerialPort";
		 die "$@\n" if ($@);
		 $serial_port = Win32::SerialPort->new ("COM1",1);      
	  else {
		 eval "use Device::SerialPort";
		 die "$@\n" if ($@);
		 $serial_port = Device::SerialPort->new ("/dev/ttyS0",1);
	die "Can't open serial port: $^E\n" unless ($serial_port);
	$serial_port->write_settings || die "Could not set up port\n";

	use ControlX10::CM17;

	$CurrentTemp = 'GetTempFromZip $zipcode';
	chomp $CurrentTemp;
	# Send on signal to speakers
	&ControlX10::CM17::send($serial_port, $speaker_unit . 'J');
	print 'Say Good morning. The current temperature is $CurrentTemp degrees.';
	&ControlX10::CM17::send($serial_port, $speaker_unit . 'K');

	# Release  the serial port
	$serial_port->close || die "\nProblem closing serial port\n";
	undef $serial_port;


You need to define two variables at the beginning of the script. Set $speaker_unit to the house and unit code of the X10 appliance switches that you connected to your wireless transmitter, receiver, and speakers. Set $zipcode to your ZIP code.

4.5.3. 3. Run the script from the command line

To run the script, open a terminal and switch to the directory you saved it in (I suggested C:\homehacks\). Then simply type the name of the script:


Assuming that Perl and the required modules have been installed correctly, the script will run, send the signal to turn on the speakers, retrieve the current temperature using web services, and read it as part of a sentence.

4.5.4. 4. Schedule the script

For your script to run, your computer needs to be running, but at some point you're going to need to shut your system off or at least reboot. Follow these instructions to configure your script to run automatically at startup:

  1. Go to Start All Programs Accessories System Tools Scheduled Tasks. The Scheduled Tasks window appears, as shown in Figure 4-7.

    Figure 4-7. Use Scheduled Tasks to program your script to run each time your computer starts.

  2. Double-click Add Scheduled Task and click Next.

  3. Click Browse and select the C:\HomeHacking\ReadWeather.pl Perl script. Click Next.

  4. Click Daily as shown in Figure 4-8, and then click Next.

    Figure 4-8. Simply scheduling your script to run daily can make your life a lot easier.

  5. Specify the time you want the computer to speak, then click Next.

  6. Enter the username and password you use to log onto the system. Alternatively, if you're concerned about security or don't want the window open when you're logged in, you can create a new user account with limited privileges, and specify that account. Click Next.

  7. On the last page, select "Open advanced properties for this task." Click Finish.

  8. The Properties dialog for the ReadWeather task will appear. In the Run field, select your Perl script from the C:\homehacking\ReadWeather\ folder. Click OK.

  9. Since you made a change to the task, you'll need to provide your account information again. Click OK.

  10. Test the task out by right-clicking it and clicking Run. You should hear the current weather announced. You're done!

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint