How To - Doorbell Automation Hack


  • Admin

    Hi Everyone,

    I put together this quick how to video for hacking your doorbell to work with MySensors. It's pretty basic and the code is based on the Relay Actuator sketch. It has two main features: controlling if the doorbell rings with an on/off switch and sending a triggered state whenever it's pressed. The silence feature can be useful if a child (or you) is taking a nap. The triggered state can be used for many different things like starting a security camera, sending an alert or text message, playing custom sounds via Sonos or other device, etc. Another note, the doorbell will still function even if your home automation the controller is down for some reason.

    Here are the additional details:
    Arduino Doorbell Home Automation Hack with MySensors – 08:18
    — Pete B

    Fritzing Doorbell Wiring_bb.png

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - PeteWill
     *
     * DESCRIPTION
     * This sketch is used to control a doorbell ring with a relay as well as send an
     * alert when the buttons is pressed.  Connect the button to ground and digital
     * pin 3.  The relay controlling the doorbell is conntected to pin 4.
     * 
     * Watch the How To video here: https://youtu.be/nMIcalwpstc
     */
    
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define NODE_ID 16 // or set to AUTO if you want gw to assign a NODE_ID for you.
    
    #define DOORBELL_PIN  3      // Arduino Digital I/O pin number for the doorbell button 
    #define RELAY_PIN  4         // Arduino Digital I/O pin number for the relay 
    #define DOORBELL_CHILD_ID 0  //ID of the doorbell
    #define SWITCH_CHILD_ID 1    // Id of the switch that will control doorbell sound
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    Bounce debouncer = Bounce();
    
    MySensor gw;
    MyMessage switchMsg(SWITCH_CHILD_ID, V_LIGHT);
    MyMessage doorbellMsg(DOORBELL_CHILD_ID, V_TRIPPED);
    
    unsigned int doorbellDelay = 1000; // interval at which to keep the doorbell button sensor triggered (milliseconds). This is used to stop people (kids) from pressing it too often
    unsigned int ringTime = 700; //How long the doorbell relay is on (in milliseconds)
    unsigned long doorbellMillis;  //Used to keep track of the last doorbell button press
    unsigned long doorbellTimer;  //Used to keep track of doorbell ring time
    byte doorbellPreviousVal;  //Used to keep track of doorbell button pressed state
    boolean ringDoorbell;  //Used to initiate the ring doorbell if statement
    boolean doorbellSound; //Used to keep track if the doorbell should sound or be silent.  Value recieved from doorbell on/off switch
    boolean doorbellOff = true;  //Used to keep track of doorbell ring state
    
    void setup()
    {
      gw.begin(incomingMessage, NODE_ID);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Doorbell Monitor", "1.0");
    
      // Setup the button and activate internal pull-up
      pinMode(DOORBELL_PIN, INPUT_PULLUP);
    
      // After setting up the button, setup debouncer
      debouncer.attach(DOORBELL_PIN);
      debouncer.interval(5);
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(SWITCH_CHILD_ID, S_LIGHT);
      gw.present(DOORBELL_CHILD_ID, S_MOTION);
    
      // Make sure relays are off when starting up
      digitalWrite(RELAY_PIN, RELAY_OFF);
      // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);
    
      // Set doorbellSound to last known state (using eeprom storage)
      doorbellSound = gw.loadState(SWITCH_CHILD_ID);
    }
    
    void loop()
    {
      gw.process();
        unsigned long currentMillis = millis();
      //Check to see if doorbell button was pushed.
      if (currentMillis - doorbellMillis > doorbellDelay) //used to stop doorbell from being pressed too frequently
      {
        debouncer.update();
        // Read doorbell button value
        byte doorbellDetect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
    
        if (doorbellDetect != doorbellPreviousVal)
        {
          //Serial.print("doorbellDetect Value: ");
          //Serial.println(doorbellDetect);
          gw.send(doorbellMsg.set(doorbellDetect)); 
          if (doorbellDetect == 1)
          {
            ringDoorbell = true;
            doorbellTimer = currentMillis;
          }
          doorbellMillis = currentMillis;
          doorbellPreviousVal = doorbellDetect;
        }
      }
    
      if (ringDoorbell)
      {
        if (doorbellSound)
        {
          if (doorbellOff)
          {
            digitalWrite(RELAY_PIN, RELAY_ON);
            //Serial.println("Doorbell sounded.");
            doorbellOff = false;
          }
          else
          {
            if (currentMillis - doorbellTimer > ringTime)
            {
              ringDoorbell = false;
              digitalWrite(RELAY_PIN, RELAY_OFF);
              //Serial.println("Doorbell off.");
              doorbellOff = true;
            }
          }
        }
      }
    }
    
      void incomingMessage(const MyMessage & message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
          Serial.println("This is an ack from gateway");
        }
    
        if (message.type == V_LIGHT) {
          // Change relay state
          doorbellSound = message.getBool();
          // Store state in eeprom
          gw.saveState(SWITCH_CHILD_ID, doorbellSound);
    
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        }
      }

  • Contest Winner

    Well done. I was thinking about the same hack. So that I can have my doorbell in silent mode, if one of the neighbor kids is playing ring-my bell and run away 😉

    I like your relay solution, that's something I'm gonna do as well.


  • Admin

    @TheoL Thanks! That's a good use case too. Dang kids. 😉



  • Great hack! A simple and compact board for this would be the Mini RBoard from itead, 37mm x49mm. Just plug in a nRf.



  • That looks like a perfekt board for this Hack



  • Great How To @petewill


  • Admin

    @Dwalt Nice! Thanks for sharing. That looks like a perfect board for something like this.


  • Hardware Contributor

    FYI for anyone who wants to make a more complicated version of this, take a look at LowPowerLabs door bell controller. There is some good docs there (and in the follow up articles) if you want to try and tap the door bell power source to power the arduino. There is also a nice explanation of how to detect when another circuit activates which might be handy for another application.



  • @TD22057 This was the route I was heading with adding the doorbell to my HA, but @petewill is awesome in doing this with the video. Me and my daughter where just trying to decide what would be the best way to hack the bell. We added a Ring.com Doorbell (trial period) and trying to decide if we like it or not. The notifications are 2 way so that is nice with video and audio. But they do not have an API. I think I will try to sniff out the Motion detection or use it from my notifications to tie into my HA.


  • Hardware Contributor

    @DrJeff Very cool. I have 2 HikVision cameras covering the front of my house so I think I'm going to try the DIY version of Ring.com. Both of the cameras have "alarm" input and output wires (12V signal) that you can use to start recording video using an external PIR or do something when the camera detects motion. One camera has an external Bosch PIR sensor that works really well. It's a 12 V NC signal wire connected to the camera and it has eliminated virtually all of the false motion alarms. The other camera is above the door and has a built in PIR sensor.

    Reading this thread made me realize that I should tap into the door bell signal and the alarm output wire on the camera above to the door and send that out as a MySensor message which will send an MQTT message to a script which can grab the camera feed and email me still images (or send me a link to a web page w/ the images) of who is coming up to the house.



  • great! i am going to add this to my home domoticz! Thanks



  • Going to install one of these very soon.

    How hard would it be to modify the sketch for a two door bell system?


  • Admin

    @drock1985 Sorry for the delayed reply! It shouldn't be too hard. You will just have to create another button input and relay output in the sketch. I haven't looked at the code but you should be able to duplicate what's in there just changing the names and pins where appropriate.



  • @petewill

    Awesome, thanks.I have the parts on order, minus the power supply (will power from AA batteries for now until I get in a DC-DC step down regulator).

    Just need to find a half decent chime now. lol



  • Hey @petewill

    Started working on the project this weekend. Didn't get the parts in this week due to the holiday. Did what I could though, and I have a schematic/drawing made up for the system. This is my first drawing in fritzing, so it's a little crude. I couldn't figure out how to add a 'T' section/junction in the wire, but it all lines up for reference anyways.

    I'll start working on the Arduino code next.

    MySensors_2Door_Chime_bb.png


  • Admin

    Why don't you send over the signal wirelessly between the two doorbells?



  • Hi @hek

    I'm not too sure I understand what you are referring to. If you are referring to the buttons themselves outside being wireless, I thought about it but wasn't too sure how long a battery would last and didn't want to be changing batteries. The way I plan to do this now, I can use the existing wiring for the doorbells that are already there, and splice into the power for the door bell to power the MySensors node.

    Plus, both chimes are in the same spot, one relay sets off one set of the three contacts (Wtih a common ground I believe) and the other will chime the second.


  • Admin

    @drock1985

    Ahh. nice. Thought you might have to run some new wires around the house.



  • @hek lol, no. Just hooking up everything to the internet that I can.


  • Admin

    @drock1985 Nice! Does your doorbell use DC so you can steal power from it? I wish mine did. That would have made things easier for me. Mine uses 16VAC... 😞


Log in to reply
 

399
Online

6.7k
Users

7.6k
Topics

80.3k
Posts

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.