How I Built a Multi-User Door Buzzer for Our Apartment

Full disclosure: a lot of people have talked about this idea, this is just my implementation of it for our apartment. You can check out Buzzeromatic.com if you want someone else to administer yours or post to Elance/oDesk/HackerNews/Twitter to get someone to build it for you. Look for something cool from @gregkoberger with all those features I left out (user management, UI, adding new roomies, adding more numbers etc.)

Making a Present for My Roommates

About a month ago, I moved to a 3-story loft in SOMA with my husband Kevin and our good friends Park and Kat. My sister also graduated college and joined a local startup, so she’ll be moving in with us next week. With 5 people living here and only 2 master keys to the front door, we had a bit of an access problem right away. My roommates, knowing I haven’t had a chance to code since the move started, were nice enough to suggest a build an app with my Twilio skills (full disclosure: I work there) and we tested it out last night – it works, so I’d love to share.

How A Call Box Works

If you’ve lived in an apartment with a call box for buzzing people into your apartment before, this will sound pretty familiar. There is a list of names and corresponding codes listed on the callbox display, you dial the number and it rings the person who lives there, they press a key and the door is unlocked.

What happens inside the callbox is a little more interesting – because the sound the keypress makes, which is called a DTMF tone, is actually a pretty amazing little thing. Tone dialing was arguably one of the earliest massive implementations of human-to-computer communication.

Phreaking Out the Phone with DTMF Tones

There is a long history of phreaking (the image to the right is of a bluebox built by Steve Jobs and Steve Wozniak, on display at the Computer History Museum) by playing DTMF tones and other tones (pulses, pins, etc), and the things telecommunications hackers achieved without any kind of API like Twilio is pretty amazing. In my case, the call box just requires the person who receives the call to press 6 to open the door, and responds when the 6 DTMF tone is played. This tone doesn’t have to come from pressing a key though, I can just play the audio file into the phone to mimic the action of a keypress – and the doors opens!

The simplest implementation of this is just to have the door automatically open when anyone dials your extension. I don’t recommend setting your callbox up this way, because you might accidentally let in people who are messing with the box looking for a way in so they can do bad things. My street has a lot of bums and other riff-raff on it, so I wanted something with a couple different types of security. So here’s what I did.

Setting Up My Call Box with Twilio

If you haven’t heard of my company, Twilio, before the really quick elevator pitch is that we are the AWS of telecommunications, making it easy to send/receive calls and text messages programmatically and only paying for what you use. It’s pretty sweet, its a startup, and I’d love your feedback on it. So here we go:

Get a local Twilio number (or you can use the sandbox number for free)

Tell your building administrator to add your name/number to the box

Build a simple app that forwards the call to your cell phone so you can make sure the box can recognize DTMF tones passed from a forwarded call

Doing this test before you build your full blown app is really important, it will save you from debugging an issue outside of your control. You just need to create this little callbox.xml file, save it somewhere on the web (publicly accessible on Dropbox is a handy option, our try Twimlets)

callbox.xml (replace 415-555-1212 with an actual phone number)

<Response>

<Dial>415-555-1212</Dial>

</Response>

If you are using your Twilio trial account, make sure you use the Twilio sandbox number and remember your pin code for testing (or email me at danielle@twilio.com and I can manually remove this restriction from your account). If you run into problems just email help@twilio.com for 24/7 support, or tweet @twilio

Building the Full App

Now that your testing is done, it’s time to build the full app with just a little PHP. This took me about 25 minutes to write from scratch in Emacs, probably will take you a whole lot less with all the sample code. Here’s the spec for how the app should work:

Need to have:

visitor or roommate dials our extension in the call box and our Twilio number is called

menu is read to visitors, giving them the option of which roommate to contact

roommates have a secret code they can punch in to bypass the menu and open the door

if the visitor selects one of the roommates from the menu options, that roommate gets a call and presses a number on their cellphone dialpad to buzz in

Nice to have:

menu selections can be made at anytime, without waiting for the menu to finish, because that is just annoying

roommates can be simultaneously dialed on multiple numbers (cellphone, work, house phone) if they want

fun audio files can be played when someone is let in

callbox.php – this file controls what happens when the callbox is dialed

Two important things to point out here. First, notice that the menu options in the tag are nested within . This is awesome, because it means Twilio is listening for a keypress the entire time and you can interrupt the menu with your selection at anytime. Also, you’ll see if you check out the Twilio example code that usually includes the numDigits parameter, but we’re excluding it on purpose here because we want to accept secret pin codes in addition to single digit selections. You’ll see why in a moment.

doorbell_gather.php – this file determines what to do with the keypad data we just received

Note on this code: There are definitely more elegant ways to write this, but in my mission to convert all my roommates to geeks I’ve opted for something they can easily understand in case they want to change their secret codes without my help. All pincodes have been changed for this example.

<Say>I’m sorry, but the person you attempted to reach is unavailable. Please try again later.</Say>

</Response>

So Twilio is passing the keypress data as ‘Digits’ and we’re telling Twilio where to go depending on what was pressed. Pretty simple. The little bit of TwiML at the bottom only plays if the roommate called doesn’t answer their phone.

So now we need to create:

roommate.xml – which calls the selected roommate so they can buzz in their guest

secret-roommate.xml – which automatically opens the door when the code is entered

You might be wondering why everyone has their own secret-roommate.xml file, when they all do the same thing. I decided it would be fun to prank my roommates with a funny theme song or movie quote before the door would unlock…

To complete this code, you’ll need to get an audio file (.wav or .mp3) of the DTMF tone you want to play back to the machine. I used this awesome DTMF generator, and they host the audio file for you.

roommate.xml - the file that calls the selected roommate

<Response>

<Say>Connecting you to [Roommate’s Name] now</Say>

<Dial>415-555-1212</Dial>

</Response>

secret-roommate.xml – the file that opens the door is the roommate enters the correct pin code. The first <Play> contains a fun audio clip from Back to the Future, the second one plays the DTMF tone that will open the door (make sure to change this depending on which tone will open your specific door).

So there you go, now you can manage a callbox for a bunch of roommates, add secret pin codes, and even give selective access to delivery people, cleaning staff, or whoever else is coming by to visit. Let me know if you find any bugs or have ideas for how to make this cooler in the comments.

Great article. I assume that the phone to door interface was existing? If you did build that, can you expand your tutorial to include that part?

Thanks.

Jordan

Nick Reed

ala Buzzer-o-matic!

http://twitter.com/chadsmith Chad Smith

I love it! Now I want to move to an apartment just to try it out.

http://www.danielbrim.com Daniel

That is pretty seriously incredible. I wish I had an apartment or lived in a housing complex so I could actually use it.

http://www.daniellemorrill.com Danielle Morrill

Hey Jordan – yes the door to phone thing was the callbox already outside that is usually configured to just call a landline inside the apartment.

Hey Nick – Seattle represent!

If anyone implements this I’d really love to hear about the reactions from your roomies

Maverick

Is your next post “How to build an asterisk system from scratch, buy a switch, some did’s, contract with a telco, and eliminate the need for a telephony api like twilio?”

http://www.daniellemorrill.com Danielle Morrill

If I knew the answer to that, I’d be building a better Twilio. In the meantime, our Asterisk geeks are hard at work

Utah_Dave

Can’t Twilio generate dtmf tones? Seems like a common enough pbx function to include in their API

This is a really cool app! I did something similar at work using our existing asterisk server. I play audio over our paging system as well if people don’t answer their phones.

http://eapen.in eapen

Nice usage!

At my place, I have a group (“Gate”) set up in Google Voice which forwards the number to my cell phone and if I can’t access my phone, then the custom voicemail that caller hears is the DTMF key (“9″ in my case) sound and so if I am not able to get the phone, it will automatically buzz them in.

http://theshayne.com Shayne

Huh… how funny. I just wrote an script that does exactly this last week. I’m using Twilio as well– coincidence? Ha!

http://www.apartmentsurabaya.com Apartment

Nice article. I like to read it. Thanks for sharing

http://www.daniellemorrill.com Danielle Morrill

Hopefully someone can successfully productize this, it isn’t a technological breakthrough but the right marketing could make it into something of a geek fad. Whether it is a product, or just a feature of some broader home automation tool, or even just a clever marketing gadget for some home owners association… I don’t know. Googling around, it looks like hacking the callbox has been popular even longer than I thought (and much longer than Twilio has been around).

RE: “can’t Twilio send DTMF tones” — Yes it can on if you want it to automatically play the tone upon answer, but in my case this didn’t make sense for how I was using it.

As a long time customer and advocate of Twilio, I am beside myself that you, an employee of Twilio, have the audacity to write this post.

http://www.daniellemorrill.com Danielle Morrill

Hi Mike, I’m sorry that you find my writing this post offensive – I absolutely appreciate that you are a long time customer and supporter of Twilio and I’d really like your feedback on why you think writing this post is such a bad thing?

Not what I had hoped to find – I have a non-call box, but well done. We have a direct buzzer system that seems to have tiny mice carrying signal back and forth. Love the roommate code. Answer me these questions three….

You have such brilliant idea in thinking of a way on how to have access with permission by using the call box equipment. And I agree with you that it would not be enough security measures in one apartment because there are dubious people always on the look out. So much better to install modern widgets giving outmost privacy and security for your comfort.

http://www.dmcihomes.com/ condo in philippines

Good to know this piece of information about call box, but then still annoying to display, better to used some electronic gadgets.

Passing by…

Completely unrelated, but, I must say it….Danielle you are very beautiful, I am so sad that you are already spoken for…
If you find yourself un-married, just send smoke signals and I will come find you.