Doorbell Butler

Smart doorbell that responds to you and tells jokes

2 minute read

2 min read

My house didn’t have a doorbell when I moved in so I made my own! Instead of the traditional “ding dong” it plays a jingle written by my friend Nick Dahlquist.

The button is connected to an ESP32 which publishes on an MQTT topic and triggers a sound module to play an MP3.

A normal doorbell button with LED illuminatation.
A normal doorbell button with LED illuminatation.
The white and red wires are connected to the button.
The white and red wires are connected to the button.

The design

The implementation

The button

Low voltage LED

The speakers

Used Dfplayer mini Loaded sd card with Mp3

ESP32

#include <WiFi.h>
#include <PubSubClient.h>
#include <DFRobotDFPlayerMini.h>

#define BUTTON_PIN 23

const char* ssid     = "your_network";
const char* password = "your_password";
const char* mqtt_server = "ip.address.of.broker";
const char* mqtt_username = "your_username";
const char* mqtt_password = "your_passowrd";

WiFiClient espClient;
PubSubClient client(espClient);

long lastRing = 0;

HardwareSerial dfSerial(2);
DFRobotDFPlayerMini dfPlayer;

void setup_wifi() {
  delay(10);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  randomSeed(micros());
}

void setup_mqtt() {
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);

  reconnect_mqtt();
}

void reconnect_mqtt() {
  while (!client.connected()) {
    String clientId = "ESP32Client-";
    clientId += String(random(0xffff), HEX);
    
    if (client.connect(clientId.c_str(), mqtt_username, mqtt_password)) {

      client.publish("doorbell/status", "connected");
      client.subscribe("doorbell/manual");
    } else {
      delay(5000);
    }
  }
}

void setup_dfplayer() {
  dfSerial.begin(9600);
  
  if (!dfPlayer.begin(dfSerial)) {
    while(true);
  }
  
  dfPlayer.volume(25);
}

void setup() {
  setup_dfplayer();
  setup_wifi();
  setup_mqtt();

  pinMode(BUTTON_PIN, INPUT);
}

void callback(char* topic, byte* payload, unsigned int length) {
  if ((char)payload[0] == 'r') {
    dfPlayer.play(1);
  }
}

void loop() {
  if (!client.connected()) {
    reconnect_mqtt();
  } else {
    client.loop();
  }

  long now = millis();
  if (digitalRead(BUTTON_PIN) == 0 && now - lastRing > 2000) {
    lastRing = now;

    client.publish("doorbell/ring", "Ding dong!");
    dfPlayer.play(1);
  }
}

The notifications

The ESP32 Speaker publishes on MQTT topic doorbell/ring when the button is pushed.

Home Assistant listening to doorbell/ring and triggers Telegram message.

- id: doorbell_ring
  alias: Doorbell alerts
  trigger:
    - platform: mqtt
      topic: 'doorbell/ring'
  action:
    - service: notify.telegram
      data:
        title: 'Ding dong!'
        message: 'Someone is here for you, sir.'
        data:
          inline_keyboard:
            - 'One minute:/command1, Be right there:/command2'
            - 'Not here right now:/command3, Go away!:/command4'

https://notevibes.com