minimalmac:

Airlock allows your Mac to lock itself, plain and simple. Using your iPhone or iPod Touch, Bluetooth, and a smidgen of pixie dust, Airlock determines whether you’re near your computer. When you leave the room - poof! - your Mac locks itself. “And when I come back?” You guessed it: your Mac unlocks. You can also customize Airlock to perform specific actions as you come and go - have your computer talk to you, log-in or out of iChat, walk the dog, and such.”

Another very flexible alternative is Proximity, which allows you to trigger Applescripts when the bluetooth device comes in/out of the range.