MQTT Doorbell

Hey, finished building this last night. Working well but I think there may have been a couple of false triggers.

Could be interference as mentioned below? I’ll have another look tonight but I have some spare reed switches so tempted to try the @adwolters solution.

Thanks again :slight_smile:

I have also experienced some false triggers. Not sure how to fix it. Is it enough to use a shielded cable?

I implemented the design here: http://www.redgrendel.com/the-doorbell/
It is basically using a sonoff on the high voltage side to control the door bell.
It works well and I have HA sending me push notifications when the bell is rung with access to my camera to view who is at the door.
Only thing is I do get some false triggers which can be annoying.
Still trying to figure out what can be done about that.

1 Like

Do your false triggers actually ring the bell? Or just false notifications? I’ve had two false triggers of the relay today which has rang the door bell. Confused everyone at home today haha

Triggers. It happens sometimes when i turn the lighting on in the bathroom. haha :see_no_evil:

I can see that the Wemos board send a MQTT message when this happens so i guess i should try using a shielded cable instead and see if this helps with anything.

Haha! I had to disconnect mine last night.

It triggered 5 times yesterday on it’s own.

Going to look at the magnet/reed solution next.

@christian.ek
Do you mind sharing your sonos_doorbell script?

I’m trying to do the same as you with a different approach but getting errors with the scrip I’m using.

Do you mean the automation? Here it is:

#################################################################
## Doorbell automation
#################################################################

- id: doorbell_ringing_daytime
  alias: Doorbell ringing daytime
  trigger:
    platform: mqtt
    topic: home/outdoors/doorbell
    payload: 'on'
  condition:
    condition: time
    after: '07:00:00'
    before: '19:00:00'
  action:
    - service: shell_command.sonos_play_doorbell
    - service: shell_command.doorbell_notification
    - service: notify.iOS
      data:
        message: "Dörrklockan ringer!"
        data:
          push:
            category: camera
          entity_id: camera.huvudentren

- id: doorbell_ringing_nighttime
  alias: Doorbell ringing nighttime
  trigger:
    platform: mqtt
    topic: home/outdoors/doorbell
    payload: 'on'
  condition:
    condition: time
    after: '19:00:00'
    before: '07:00:00'
  action:
    - service: shell_command.sonos_play_doorbell_night
    - service: shell_command.doorbell_notification
    - service: notify.iOS
      data:
        message: "Dörrklockan ringer!"
        data:
          push:
            category: camera
          entity_id: camera.huvudentren
2 Likes

Good to see that so many people want to automate their doorbell. I wanted to do the same but without interfering with the existing system.

In the first version I measured the voltage on the A0 pin of a Wemos but after reading an article in the German c’t magazine I created a version 2 with an optocoupler. Now it’s just a digital input on the Wemos board and the two circuits are nicely separated.

On the Wemos I used Homie software to connect to the MQTT and from there on it’s handled by Home Assistant. For now just a message to a slack bot but once you capture the signal in HA it’s up to you.

A detailed description of the setup is on my Github page.

5 Likes

How do you got telegram working. Mine failed

Did you ever work out the 8v problem?
My doorbell is 8v 0.6A too and would like to achieve the same.

The way I did is to simply put an octocoupler in and connect it to a NodeMCU. Everytime the doorbell is pressed the pin of the NodeMCU turn to high and it sends a simple message to HASS over MQTT. Not home now, but if you want I can post a photo how it looks (its real silmple).

This is the code I use on the node:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

//WIFI
const char* wifi_ssid = "SSID";
const char* wifi_password = "PASSWORD";

//MQTT
const char* mqtt_server = "MQTTIP";
const char* mqtt_user = "MQTTUSER";
const char* mqtt_password = "MQTTPASSWORD";
const char* clientID = "CLIENTNAME IE doorbell";

//VARS
const char* doorbell_topic = "home/outdoors/doorbell";
const int doorbellPin = D3;
int doorbellState = 0;

WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
  Serial.begin(115200);
  pinMode(doorbellPin, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  
  setup_wifi();
  client.setServer(mqtt_server, 1883);
}

void blink_now(){
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
}

void setup_wifi() {
  //Turn off Access Point
  WiFi.mode(WIFI_STA);
  delay(10);
  
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(wifi_ssid);

  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    blink_now();
  }
  
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    blink_now();
    // Attempt to connect
    if (client.connect(clientID, mqtt_user, mqtt_password)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish(doorbell_topic, "Doorbell connected to MQTT");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  doorbellState = digitalRead(doorbellPin);

  if ( doorbellState == LOW ) {
    // Put your code here.  e.g. connect, send, disconnect.
    Serial.println("Doorbell is pressed!");
    client.publish(doorbell_topic, "on", true);
    blink_now();

    delay( 3000 );
  }
}

In HASS I’m sending it to pushbullet via an automation.

2 Likes

I know this is an old post, but one way you could achieve that without having to use a plug would be a relay operated by the same ESP, which it energises when you want to run the doorbell via HA changing over the button wires to the ESP, and leaves the wiring running through its NC contact to the existing doorbell system for use in its de-energised state. That way if HA is down, the ESP would not have energised the relay and your existing doorbell continues to function.

I am now using shielded Cables between wemos and the doorbell button.

I still get the false triggers sometimes when someone flicks the switch in the bathroom. Not sure how i can fix this? Anyone with any tips? =)

@armandjanssen I copied your setup and code and with some small issues it’s pretty well working.
Got some issues with false switchings, looks like that the input is floating, did you got the same issues or somebody else can assist?

What are the options?

  • Input High for minimum 1,5 / 2 seconds? And how can I add that easily to the code?
  • Pullup Resistor?

Thanks in advance

Had an ESP laying about and a cheap 433mhz door bell just gave this a go, i fitted the esp to the ringer box rather than the actual bell working well ! Now to solder :slight_smile:

1 Like

Anyone tried the reed switch in the bell? So that when the traditional bell rings it creates a magnetic field and closes the reed switch… was planning on testing this… got the bits just haven’t had time.

I want the original bell to operate as normal but make it “smart” in a non-intrusive way.

I removed the relay method a while ago because of false triggers. Haha! The family got very confused by the phantom door bell but it was quite entertaining for a couple of days!

Works as intended, No false or missed triggers so far :slight_smile:

Did some testning with a arcard button, notification with the phone works just perfect and sound.

Only thing left is the light in the button

Hi,

It loses sometimes the connection to my MQTT server. Due too the fact I’m rebooting HASS.IO etc etc.
But does not always reconnect it, what you already described in your code.

But is there some update or idea how to solve this?
I’am quite new to arduino so need to get a bit more experience how program it.