MQTT Doorbell

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.

Is there a way to report the mqtt state to “off” after x amount of time. I only receive “on” message via mqtt when door bell is pressed, would be good to monitor the state of the door bell. Can this be done within Homeassistant ?

My setup sends an Off Status after 3 seconds when the button gets pushed. This also prevents the system from multiple commands per seconds if some kids have fun with your doorbell. Within those 3 seconds the system is on hold and wont send any other status.

Hope this helps

delay(3000);
Serial.print("Send message: ");
Serial.println(offMsg);
client.publish(outTopic, offMsg);
1 Like

perfect thanks :slight_smile: