Using a building callbox as a keyless entry system

Jonathan Kim
6 min readJun 23, 2020

--

I’ve always kept a spare key in a lockbox outside my apartment. That habit has saved me many times when I locked myself out or had a friend stay over while I was out of town. When I got a dog, it was a convenient way to let the dog walker in.

My current apartment building doesn’t allow lockboxes and removed dozens of them—mine included—shortly after I moved in. In order to keep the convenience and make sure our dog walker could still get in on the weekdays, I found a way to repurpose the building’s callbox for an even more secure and convenient solution.

If you’re not familiar with building callboxes, they’re like a phone directory for residents. A visitor can cycle through the list of residents and make a normal phone call to any of them. That resident can then press a key to open the door for you. It’s technically keyless but requires human authorization.

In searching for a solution, I came across this awesome blog post by Danielle Morrill. It’s a decade old at this point but still has some handy tips. Like Morrill, I also used Twilio for this, but thankfully the technology has changed a lot, even while I was making this, in ways that make this even simpler.

😴️ tl;dr: skip to the end if you just want instructions on how to build this yourself.

Attempt #1: Twilio Functions 👎🏽

Spoiler: it was not all that easy.

My first shot at this used Twilio Functions. If you know a bit about coding, Twilio Functions let you run short snippets of code that you can write directly in the browser without the overhead of worrying about servers. If you’re a professional programmer, Functions is Twilio’s implementation of AWS Lambdas, with all of the same benefits and drawbacks (more on that later).

Because I thought I was being clever, this initial script expected verbal passphrases like a speakeasy. Groups of people could be associated with the same passphrase, and you can see a few places where I annotated future improvements.

In response to saying the right passphrase, this snippet would simulate pressing “9#” to unlock the door. If you didn’t say the right thing, it’d just connect you to my phone like normal.

Though this seemed like a decent approach, Twilio Functions didn’t work very reliably. When I first wrote this in early 2019, functions would stop running after 5 seconds, which made collecting user input infeasible. That limit was lifted to 10 seconds in September 2019, but would still timeout or terminate unexpectedly.

Twilio Functions provided good logging for the errors, but ultimately it wasn’t dependable enough to be useful.

Attempt #2: Twilio Studio 👍🏽

When my building removed my illicit lockbox in February, I tried again and met success. This time I used Twilio Studio, a visual workflow builder that displaces much of the functionality of Functions without the need to write (much) code.

Here’s how it works:

  1. 🤖 Visitors are greeted by my bot and asked to input their unique 4-digit code.
  2. ✅ If they put it in correctly, the bot welcomes them and simulates pressing “9#” to let them in.
  3. 📳 Upon being let in, I get a text notification with the specific code that was used. This is super nice.
  4. 🤔 If they input the wrong code, they’re given a second chance.
  5. 🙅‍♂️ On the second failed attempt, they’re routed to my phone number so I can talk to them.

And here’s what that looks like in Twilio:

The text message notifications quickly became my favorite feature. I can now know how much exercise my dog got or when my wife locks herself out.

Building this for yourself

Making this with Twilio Studio, especially with the diagram above as a reference, is mostly straight-forward. Twilio does allow you to export the diagram’s code for others to use, but it includes user- and account-specific information that make sharing it more trouble than it’s worth.

Step 1: Acquire a Twilio number

The first thing to do was get a programmable number from Twilio. I immediately sent that to my building manager and asked him to switch it out for the one I had currently.

Twilio’s pricing requires you to buy a number and credits. You can get a number for $12/year and be comfortable with $5–10 in credits per year.

Step 2: Generate your DTMF tone

Unlike the code version, Studio gave no way to play the digits back that would unlock the door. For that, I used a free online DTMF tone generator. Once you download your audio file, upload it using Twilio Assets.

⚡️ I highly recommend adding some pauses before, after and between your digits. If your building’s code is 9#, input <space>9<space>#<space> into the generator so your building’s machine can process it more clearly.

Step 3: Create your flow

Twilio calls these diagrams “flows,” so you’ll want to create one of those from the Manage Flows Console.

The “widgets” you’ll need are:

  • count_attempts (Set Variables)
  • limit_attempts (Split Based On…)
  • gather_input (Gather Input On Call)
  • await_keypress (Split Based On…)
  • welcome (Say/Play)
  • open_door (Say/Play)
  • notify_person (Send Message)
  • connect_human (Connect Call To)

Most of the widgets have simple configuration that’ll be clear once you start trying to replicate the diagram. The two exceptions are count_attempts and gather_input, so I’ve included screenshots of those below.

`count_attempts` counts the number of times the widget is invoked, which then affects how the `gather_input` widget responds.

This took a lot of trial and error on my part, so hopefully this saves you time.

Step 4: Connect your number to your flow

The last step is to connect your new number to this Flow. If you want to test this before adding it to your callbox, you can call the number yourself and try putting in the right or wrong passcodes. If that doesn’t work for some reason, you’ve missed a step along the way.

Making it even better

My wife is probably right about this being over-engineered, BUT if I ignore that—and I will—there are numerous ways this could be better.

  • Find a way to issue new codes without having to log into Studio and make changes.
  • Add logic so that certain codes have limited uses or expire after a certain amount of time.
  • Log every attempt—success and failure—to a Google spreadsheet to create a digital logbook.
  • Round-robin between me and my wife when connecting to a human. Better yet, add in a priority based on our schedules.

--

--