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…

6 thoughts on “Doorbell Smartener”

  1. This is awesome I have been looking at a similar setup for my house. What did you use to convert the 24v AC to 3.3v DC of the esp?

    1. I’m taking advantage of the fact that I have a light right there, and I’m using a lamp holder with an outlet on it to plug in a USB power adapter (the ESP8266 breakout I’m using, the D1 Mini, has a micro-USB port that can be used to supply 5v power to an onboard regulator).

      Running it off the 24VAC would certainly be possible. You would need to rectify the AC into DC (a “through hole bridge rectifier” would be easily mounted to a protoboard), add some capacitors for smoothing, and then pass the output of that into a DC/DC buck converter to drop it down to 3.3v for the ESP. You could probably put that together for <$10, but if you've got an outlet nearby (or can add one easily) a cheap USB power supply is the way to go.

  2. Thank you this is exactly what I’ve been working on. One question, I don’t have a user name or password setup on my mqtt server, how would I edit the program for it to work with my mqtt server? thank you

      1. Thank you. I understand that the door bell is connected to the D2 and GND on the esp8266 but I’m not sure where to connect the relay. Which pins connect the esp8266 with the relay? On my relay there are 3 pins on both sides (vcc,gnd,in) on one side which I’m assuming connects to the esp8266, then the other side has (no,com,nc) which I think is where one wire from the transformer and one wire from the bell go into. So which pins connect the esp8266 with the relay?

Leave a Reply

Your email address will not be published. Required fields are marked *