O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Smart Home Hacks
By Gordon Meyer
October 2004
More Info

HACK
#53
Outdo Big Ben
The classic Westminster chimes ring forth from your home automation system.
The Code
[Discuss (0) | Link to this hack]

All of us crave it, but only a select few of us obtain it. I'm referring to acceptance of our home automation hobby by our spouses, of course—the elusive SAF . We can wax quite eloquently of the benefits of computer-controlled lighting , talking CID , driveway vehicle detectors , and automated sprinklers . But seldom do we get more than a glazed look in return. Well, here's a simple hack that will add a touch of class to your home, and might get a smile from your better half.

All you need is a computer in a room where it can be heard easily (or, ideally, a whole-house audio system) and some quality chime recordings. In fact, the hardest part is finding a quality recording of the chimes—you'll need each hour's chime in a separate sound file. A search at the HomeSeer message board (http://ubb.HomeSeer.com/) will turn up many to choose from, or visit the Smart Home Hacks web site (http://www.oreilly.com/catalog/smarthomehks) for pointers to appropriate files.

The Code

Before we set up HomeSeer to play at the proper times, first let's cover the script that plays the chimes. We want the chimes to play only between the hours of 8:00 a.m. and 9:00 p.m. (Try that with a grandfather clock!) So, the first thing the script does is to make sure it's between those hours. If it's not, no chimes are played and no one will be disturbed:

	sub main()
	dim h
	dim prior_volume_level_left
	dim prior_volume_level_right
	dim chime_volume_level
	dim start_time
	dim end_time
	chime_volume_level = 3

	if now() > cdate(date() & " 7:15:00 AM") and now() < cdate(date() &  " 9:
	05:00 PM") then

TIP

Note the space in the code between the time and AM or PM; it's necessary for the comparison to work correctly.

Next, examine the hour of the current time (h) and reduce it to a 12-hour clock, if necessary. That is, if the hour is 18, change it to 6 so that the correct sound file will play:

		h = datepart("h", now())
		h = cint(h)	
	 if h > 12 then h = h –12

The script saves the current sound volume settings so that they can be restored later, then calls the hs.setvolume function to adjust the volume of the right and left channels to a lower level so that the bells aren't too loud:

	prior_volume_level_left = hs.getvolume(0,0)
	prior_volume_level_right = hs.getvolume(1,0)
	hs.setvolume chime_volume_level,chime_volume_level,0

TIP

Loud sound files result in low SAF.

A simple select statement plays the correct sound file, based on the hour value. HomeSeer's hs.PlayWavFile expects a complete path to the WAV file to play, so this script assumes the sound files are stored in the HomeSeer\ sounds directory:

	select case h
		  case 1
			hs.PlayWavFile "sounds\One.wav"
	      case 2
			hs.PlayWavFile "sounds\Two.wav"
          case 3
			hs.PlayWavFile "sounds\Three.wav"
          case 4
			hs.PlayWavFile "sounds\Four.wav"
		  case 5
			hs.PlayWavFile "sounds\Five.wav"
		  case 6
			hs.PlayWavFile "sounds\Six.wav"
		  case 7
			hs.PlayWavFile "sounds\Seven.wav"
		  case 8
			hs.PlayWavFile "sounds\Eight.wav"
		 case 9
			hs.PlayWavFile "sounds\Nine.wav"
		 case 10
			hs.PlayWavFile "sounds\Ten.wav"
		 case 11
			hs.PlayWavFile "sounds\Eleven.wav"
		 case 12
			hs.PlayWavFile "sounds\Twelve.wav"
   	   end select

Finally, the sound volume is restored to its previous setting:

	  hs.setvolume prior_volume_level_left,prior_volume_level_right,0	 
end if
   end sub

Next, create a HomeSeer event that executes this script. I have it trigger at the top of every hour; it exits without playing the chimes if the time is outside the time range specified in the script.

My family really enjoys our virtual Big Ben, and my sons actually learned to count (to 12) by listening to it. Most importantly, though, my wife actually likes this feature of our home automation system. Who could ask for more?


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.