Doorbell Smartener

My wife and I have several small children, and a love for Amazon Prime. Separately, these are both wonderful things. Parental fulfillment, and convenient consumerism… what could be better… Unfortunately, combined they are a recipe for interrupted nap times, as the delivery driver is compelled to press the doorbell in the middle of the day (thereby setting off the dogbell).

So it’s time for a little better living through science!. We have a very old-fashioned doorbell. Effectively a big loop connecting the button and the chime, powered by a 24v AC transformer. The switch inside the button is normally open, and when the button is pushed, the contacts close. This allows power to flow to the chime, activating an electromagnet, which in turn pulls the striker against the metal ringy thingy (highly technical doorbell terminology, be sure to Google it if you get lost).

Here’s a diagram:

And here’s a picture of the transformer, along with the cables going off to the button and the chime:

I have two main goals with this project. The first, and most important, is to be able to selectively turn off the chime based on the kids’ sleep schedule. The second is to be able to feed the ‘ring’ event into my home automation platform, which enables various other forms of notifications (text message, push notification, etc).

So here’s the plan…

I’m going to add an ESP8266 and a relay into the circuit, near the transformer. I’ll wire the doorbell button to a GPIO pin, and connect the transformer/chime to a relay. The ESP8266 will then be able to detect the button being pushed and take several actions based on that input. First, it will send an event to Home Assistant via MQTT. Then, if enabled, it will ring the chime by closing the relay. The chime state will also be set via MQTT. The microcontroller will store that state locally, so it can make that decision instantaneously.

Here’s the code.

Note that we’re looking for the GPIO attached to the doorbell button to go “low”. The esp8266 has built-in pull-up resistors on most of its GPIO lines, so it’s generally easier to trigger them by pulling the pin low (the two wires coming from the button are connected to pins D2 and GND).

Another important consideration is the use of the ‘retain’ flag for MQTT messages. This is a really useful MQTT feature which causes the broker to store the last seen message for a given topic and replay it whenever a client reconnects. That means when either the Doorbell Smartener™*, or Home Assistant are restarted, they come back up knowing the current state of things (otherwise they could end up out of sync until the state was updated again).

So now all that’s left is to hook it up and configure Home Assistant.

Here’s another helpful diagram of how I hooked it up:

And a picture of the installed Smartener™ (before I tidied it up into the electrical box):

As far as Home Assistant goes, that couldn’t be easier. I set up the switch for turning the chime on and off, as well as automation to notify me when the button is pushed:

And that’s really all there is to it. We now have a doorbell we can turn on and off as needed (plus some scheduled automations to turn it off during nap time and overnight), and we get notifications on our phone when the doorbell is pushed.

* I don’t actually intend to enforce a trademark on “Smartener”… It’s just a joke… Calm down…