Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. How To - Doorbell Automation Hack

How To - Doorbell Automation Hack

Scheduled Pinned Locked Moved My Project
106 Posts 29 Posters 93.5k Views 26 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BigDogB Offline
    BigDogB Offline
    BigDog
    wrote on last edited by
    #11

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

    1x Raspberry With Domoticz V2.3011 [Linux version 4.1.6+]
    PiRack With
    -1X PiFace Digital
    -1X RaZberry - OpenZWave
    1X RFXtrx433 USB Firmware: 183
    5X Arduino: mysensors V1.5(including)

    • First DoorBel Project -> WORKS! :)
      6x ESP8266: easy firmware(Testing)
    1 Reply Last reply
    0
    • D Offline
      D Offline
      drock1985
      wrote on last edited by
      #12

      Going to install one of these very soon.

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

      My Projects
      2 Door Chime Sensor
      Washing Machine Monitor

      petewillP 1 Reply Last reply
      0
      • D drock1985

        Going to install one of these very soon.

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

        petewillP Offline
        petewillP Offline
        petewill
        Admin
        wrote on last edited by
        #13

        @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.

        My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

        D 1 Reply Last reply
        0
        • petewillP petewill

          @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.

          D Offline
          D Offline
          drock1985
          wrote on last edited by
          #14

          @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

          My Projects
          2 Door Chime Sensor
          Washing Machine Monitor

          1 Reply Last reply
          0
          • D Offline
            D Offline
            drock1985
            wrote on last edited by
            #15

            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

            My Projects
            2 Door Chime Sensor
            Washing Machine Monitor

            1 Reply Last reply
            0
            • hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #16

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

              1 Reply Last reply
              0
              • D Offline
                D Offline
                drock1985
                wrote on last edited by
                #17

                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.

                My Projects
                2 Door Chime Sensor
                Washing Machine Monitor

                hekH 1 Reply Last reply
                0
                • D drock1985

                  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.

                  hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #18

                  @drock1985

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

                  D 1 Reply Last reply
                  0
                  • hekH hek

                    @drock1985

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

                    D Offline
                    D Offline
                    drock1985
                    wrote on last edited by
                    #19

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

                    My Projects
                    2 Door Chime Sensor
                    Washing Machine Monitor

                    petewillP 1 Reply Last reply
                    0
                    • D drock1985

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

                      petewillP Offline
                      petewillP Offline
                      petewill
                      Admin
                      wrote on last edited by
                      #20

                      @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... :(

                      My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                      BulldogLowellB 1 Reply Last reply
                      1
                      • petewillP petewill

                        @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... :(

                        BulldogLowellB Offline
                        BulldogLowellB Offline
                        BulldogLowell
                        Contest Winner
                        wrote on last edited by
                        #21

                        @petewill

                        Convert it!!!

                        you have the power

                        you have the technology

                        diode bridge

                        petewillP 1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          drock1985
                          wrote on last edited by
                          #22

                          Hey @petewill

                          They vary. Some of the more expensive ones I've noticed use DC (ex play custom songs/tones), while the cheaper ones use AC.

                          I built the project around the idea the wife would want something more elaborate than a simple ding sound, but I was wrong lol. So I picked up one that she looked last night, and I believe it uses AC, so I will be making a slight change to my design.

                          I'll end up putting in one of these I figure, just haven't quite figured out what size smoothing capacitor I will need.

                          Also, I'm not 100% sure yet (at work, hard to do research) but I may be able to get away with a simple 5v regulator once the power is converted to DC, in lieu of a variable buck converter.

                          http://m.wikihow.com/Make-an-AC-DC-Converter

                          My Projects
                          2 Door Chime Sensor
                          Washing Machine Monitor

                          DrJeffD 1 Reply Last reply
                          0
                          • BulldogLowellB BulldogLowell

                            @petewill

                            Convert it!!!

                            you have the power

                            you have the technology

                            diode bridge

                            petewillP Offline
                            petewillP Offline
                            petewill
                            Admin
                            wrote on last edited by
                            #23

                            @BulldogLowell Haha, I just took the easy way out and ran a 5V line :)

                            @drock1985

                            I built the project around the idea the wife would want something more elaborate than a simple ding sound, but I was wrong lol.

                            Yeah, that's happened to me as well on other projects :)

                            My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                            BulldogLowellB 1 Reply Last reply
                            0
                            • D drock1985

                              Hey @petewill

                              They vary. Some of the more expensive ones I've noticed use DC (ex play custom songs/tones), while the cheaper ones use AC.

                              I built the project around the idea the wife would want something more elaborate than a simple ding sound, but I was wrong lol. So I picked up one that she looked last night, and I believe it uses AC, so I will be making a slight change to my design.

                              I'll end up putting in one of these I figure, just haven't quite figured out what size smoothing capacitor I will need.

                              Also, I'm not 100% sure yet (at work, hard to do research) but I may be able to get away with a simple 5v regulator once the power is converted to DC, in lieu of a variable buck converter.

                              http://m.wikihow.com/Make-an-AC-DC-Converter

                              DrJeffD Offline
                              DrJeffD Offline
                              DrJeff
                              wrote on last edited by
                              #24

                              @drock1985 said:

                              I'll end up putting in one of these I figure, just haven't quite figured out what size smoothing capacitor I will need.

                              Add a cap .1uf input side of the 5V regulator and a 47-220uf on the regulated 5V . High freq and a low freq ripple.

                              That should do the trick same thing I was planning on doing. I bought the Ring Doorbell but still want to be notified of the actual ring into HA.

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                drock1985
                                wrote on last edited by
                                #25

                                Hi @petewill

                                I finally got the parts in to do the project. I've been working on the code, but I seem to be running into an issue. I have the four devices show up in Domoticz, but I'm not getting any feedback from the sensor. Would you mind looking at the code for me please? This is the first program I have ever worked on, and not much of a programmer mentality yet.

                                /*
                                 * 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
                                 * 
                                 * 2 Door Chime
                                 * Version 1.0 - ResentedPoet
                                 * DESCRIPTION
                                 * Original idea/concept by PeteWill. Modified code to add second actuator (relay)
                                 * door chimes with 2 doors. This will allow your home automation system to differentiate
                                 * between front and back door. As well, this allows current 2 door chimes to still have
                                 * their individual chimes. Pins 3 and 4 are used for door bell 1 and relay/chime 1 
                                 * respectively, and digital pins 5 and 6 for door bell 2 and relay/chime 2.
                                 */
                                
                                
                                #include <MySensor.h>
                                #include <SPI.h>
                                #include <Bounce2.h>
                                
                                #define NODE_ID AUTO // or set a manual ID in place of AUTO
                                
                                #define DOORBELL1_PIN  3      // Arduino Digital I/O pin number for the doorbell button 
                                #define RELAY1_PIN  4         // Arduino Digital I/O pin number for the relay 
                                #define DOORBELL1_CHILD_ID 0  //ID of the front doorbell
                                #define SWITCH1_CHILD_ID 1    // Id of the switch that will control front doorbell sound
                                #define RELAY1_ON 1
                                #define RELAY1_OFF 0
                                #define DOORBELL2_PIN  5      // Arduino Digital I/O pin number for the doorbell button 
                                #define RELAY2_PIN  6         // Arduino Digital I/O pin number for the relay 
                                #define DOORBELL2_CHILD_ID 2  //ID of the back doorbell
                                #define SWITCH2_CHILD_ID 3    // Id of the switch that will control back doorbell sound
                                #define RELAY2_ON 1
                                #define RELAY2_OFF 0
                                
                                Bounce debouncer = Bounce();
                                
                                MySensor gw;
                                MyMessage switchMsg1(SWITCH1_CHILD_ID, V_LIGHT);
                                MyMessage switchMsg2(SWITCH2_CHILD_ID, V_LIGHT);
                                MyMessage doorbellMsg1(DOORBELL1_CHILD_ID, V_TRIPPED);
                                MyMessage doorbellMsg2(DOORBELL2_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 doorbell1Millis;  //Used to keep track of the last front doorbell button press
                                unsigned long doorbell1Timer;  //Used to keep track of front doorbell ring time
                                unsigned long doorbell2Millis;  //Used to keep track of the last back doorbell button press
                                unsigned long doorbell2Timer;  //Used to keep track of back doorbell ring time
                                byte doorbell1PreviousVal;  //Used to keep track of front doorbell button pressed state
                                byte doorbell2PreviousVal;  //Used to keep track of back doorbell button pressed state
                                boolean ringDoorbell1;  //Used to initiate the ring front doorbell if statement
                                boolean doorbell1Sound; //Used to keep track if the front doorbell should sound or be silent.  Value recieved from doorbell on/off switch
                                boolean doorbell1Off = true;  //Used to keep track of front doorbell ring state
                                boolean ringDoorbell2;  //Used to initiate the ring front doorbell if statement
                                boolean doorbell2Sound; //Used to keep track if the front doorbell should sound or be silent.  Value recieved from doorbell on/off switch
                                boolean doorbell2Off = true;  //Used to keep track of front doorbell ring state
                                
                                void setup()
                                {
                                  gw.begin(incomingMessage, NODE_ID);
                                
                                  // Send the sketch version information to the gateway and Controller
                                  gw.sendSketchInfo("2 Doorbell Monitor", "1.0");
                                
                                  // Setup the button and activate internal pull-up
                                  pinMode(DOORBELL1_PIN, INPUT_PULLUP);
                                  pinMode(DOORBELL2_PIN, INPUT_PULLUP);
                                
                                  // After setting up the button, setup debouncer
                                  debouncer.attach(DOORBELL1_PIN);
                                  debouncer.attach(DOORBELL2_PIN);
                                  debouncer.interval(5);
                                
                                  // Register all sensors to gw (they will be created as child devices)
                                  gw.present(SWITCH1_CHILD_ID, S_LIGHT);
                                  gw.present(DOORBELL1_CHILD_ID, S_MOTION);
                                  gw.present(SWITCH2_CHILD_ID, S_LIGHT);
                                  gw.present(DOORBELL2_CHILD_ID, S_MOTION);
                                
                                  // Make sure relays are off when starting up
                                  digitalWrite(RELAY1_PIN, RELAY1_OFF);
                                  digitalWrite(RELAY2_PIN, RELAY2_OFF);
                                  // Then set relay pins in output mode
                                  pinMode(RELAY1_PIN, OUTPUT);
                                  pinMode(RELAY2_PIN, OUTPUT);
                                
                                  // Set doorbellSound to last known state (using eeprom storage)
                                  doorbell1Sound = gw.loadState(SWITCH1_CHILD_ID);
                                  doorbell2Sound = gw.loadState(SWITCH2_CHILD_ID);
                                }
                                
                                void loop()
                                {
                                  gw.process();
                                    unsigned long current1Millis = millis();
                                  //Check to see if front doorbell button was pushed.
                                  if (current1Millis - doorbell1Millis > doorbellDelay) //used to stop doorbell from being pressed too frequently
                                  {
                                    debouncer.update();
                                    // Read front doorbell button value
                                    byte doorbell1Detect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
                                
                                    if (doorbell1Detect != doorbell1PreviousVal)
                                    {
                                      //Serial.print("doorbell1Detect Value: ");
                                      //Serial.println(doorbell1Detect);
                                      if (doorbell1Detect == 1)
                                      {
                                        ringDoorbell1 = true;
                                        doorbell1Timer = current1Millis;
                                      }
                                      doorbell1Millis = current1Millis;
                                      doorbell1PreviousVal = doorbell1Detect;
                                    }
                                  }
                                
                                  if (ringDoorbell1)
                                  {
                                    if (doorbell1Sound)
                                    {
                                      if (doorbell1Off)
                                      {
                                        digitalWrite(RELAY1_PIN, RELAY1_ON);
                                        //Serial.println("Front Doorbell sounded.");
                                        doorbell1Off = false;
                                      }
                                      else
                                      {
                                        if (current1Millis - doorbell1Timer > ringTime)
                                        {
                                          ringDoorbell1 = false;
                                          digitalWrite(RELAY1_PIN, RELAY1_OFF);
                                          //Serial.println("Front Doorbell off.");
                                          doorbell1Off = true;
                                        }
                                      }
                                    }
                                  }
                                
                                //Check to see if back doorbell button was pushed.
                                unsigned long current2Millis = millis();
                                    if (current2Millis - doorbell2Millis > doorbellDelay) //used to stop doorbell from being pressed too frequently
                                  {
                                    debouncer.update();
                                    // Read back doorbell button value
                                    byte doorbell2Detect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
                                
                                    if (doorbell2Detect != doorbell2PreviousVal)
                                    {
                                      //Serial.print("doorbell2Detect Value: ");
                                      //Serial.println(doorbell2Detect);
                                      if (doorbell2Detect == 1)
                                      {
                                        ringDoorbell2 = true;
                                        doorbell2Timer = current2Millis;
                                      }
                                      doorbell2Millis = current2Millis;
                                      doorbell2PreviousVal = doorbell2Detect;
                                    }
                                  }
                                
                                  if (ringDoorbell2)
                                  {
                                    if (doorbell2Sound)
                                    {
                                      if (doorbell2Off)
                                      {
                                        digitalWrite(RELAY2_PIN, RELAY2_ON);
                                        //Serial.println("Back Doorbell sounded.");
                                        doorbell2Off = false;
                                      }
                                      else
                                      {
                                        if (current2Millis - doorbell2Timer > ringTime)
                                        {
                                          ringDoorbell2 = false;
                                          digitalWrite(RELAY2_PIN, RELAY2_OFF);
                                          //Serial.println("Back Doorbell off.");
                                          doorbell2Off = 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
                                      doorbell1Sound = message.getBool();
                                      // Store state in eeprom
                                      gw.saveState(SWITCH1_CHILD_ID, doorbell1Sound);
                                
                                      // Write some debug info
                                      Serial.print("Incoming change for sensor:");
                                      Serial.print(message.sensor);
                                      Serial.print(", New status: ");
                                      Serial.println(message.getBool());
                                    }
                                    
                                  }```

                                My Projects
                                2 Door Chime Sensor
                                Washing Machine Monitor

                                BulldogLowellB 1 Reply Last reply
                                0
                                • petewillP petewill

                                  @BulldogLowell Haha, I just took the easy way out and ran a 5V line :)

                                  @drock1985

                                  I built the project around the idea the wife would want something more elaborate than a simple ding sound, but I was wrong lol.

                                  Yeah, that's happened to me as well on other projects :)

                                  BulldogLowellB Offline
                                  BulldogLowellB Offline
                                  BulldogLowell
                                  Contest Winner
                                  wrote on last edited by
                                  #26

                                  Haha, I just took the easy way out and ran a 5V line

                                  @petewill

                                  that may be the easy way, but not as fun :(

                                  petewillP 1 Reply Last reply
                                  0
                                  • D drock1985

                                    Hi @petewill

                                    I finally got the parts in to do the project. I've been working on the code, but I seem to be running into an issue. I have the four devices show up in Domoticz, but I'm not getting any feedback from the sensor. Would you mind looking at the code for me please? This is the first program I have ever worked on, and not much of a programmer mentality yet.

                                    /*
                                     * 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
                                     * 
                                     * 2 Door Chime
                                     * Version 1.0 - ResentedPoet
                                     * DESCRIPTION
                                     * Original idea/concept by PeteWill. Modified code to add second actuator (relay)
                                     * door chimes with 2 doors. This will allow your home automation system to differentiate
                                     * between front and back door. As well, this allows current 2 door chimes to still have
                                     * their individual chimes. Pins 3 and 4 are used for door bell 1 and relay/chime 1 
                                     * respectively, and digital pins 5 and 6 for door bell 2 and relay/chime 2.
                                     */
                                    
                                    
                                    #include <MySensor.h>
                                    #include <SPI.h>
                                    #include <Bounce2.h>
                                    
                                    #define NODE_ID AUTO // or set a manual ID in place of AUTO
                                    
                                    #define DOORBELL1_PIN  3      // Arduino Digital I/O pin number for the doorbell button 
                                    #define RELAY1_PIN  4         // Arduino Digital I/O pin number for the relay 
                                    #define DOORBELL1_CHILD_ID 0  //ID of the front doorbell
                                    #define SWITCH1_CHILD_ID 1    // Id of the switch that will control front doorbell sound
                                    #define RELAY1_ON 1
                                    #define RELAY1_OFF 0
                                    #define DOORBELL2_PIN  5      // Arduino Digital I/O pin number for the doorbell button 
                                    #define RELAY2_PIN  6         // Arduino Digital I/O pin number for the relay 
                                    #define DOORBELL2_CHILD_ID 2  //ID of the back doorbell
                                    #define SWITCH2_CHILD_ID 3    // Id of the switch that will control back doorbell sound
                                    #define RELAY2_ON 1
                                    #define RELAY2_OFF 0
                                    
                                    Bounce debouncer = Bounce();
                                    
                                    MySensor gw;
                                    MyMessage switchMsg1(SWITCH1_CHILD_ID, V_LIGHT);
                                    MyMessage switchMsg2(SWITCH2_CHILD_ID, V_LIGHT);
                                    MyMessage doorbellMsg1(DOORBELL1_CHILD_ID, V_TRIPPED);
                                    MyMessage doorbellMsg2(DOORBELL2_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 doorbell1Millis;  //Used to keep track of the last front doorbell button press
                                    unsigned long doorbell1Timer;  //Used to keep track of front doorbell ring time
                                    unsigned long doorbell2Millis;  //Used to keep track of the last back doorbell button press
                                    unsigned long doorbell2Timer;  //Used to keep track of back doorbell ring time
                                    byte doorbell1PreviousVal;  //Used to keep track of front doorbell button pressed state
                                    byte doorbell2PreviousVal;  //Used to keep track of back doorbell button pressed state
                                    boolean ringDoorbell1;  //Used to initiate the ring front doorbell if statement
                                    boolean doorbell1Sound; //Used to keep track if the front doorbell should sound or be silent.  Value recieved from doorbell on/off switch
                                    boolean doorbell1Off = true;  //Used to keep track of front doorbell ring state
                                    boolean ringDoorbell2;  //Used to initiate the ring front doorbell if statement
                                    boolean doorbell2Sound; //Used to keep track if the front doorbell should sound or be silent.  Value recieved from doorbell on/off switch
                                    boolean doorbell2Off = true;  //Used to keep track of front doorbell ring state
                                    
                                    void setup()
                                    {
                                      gw.begin(incomingMessage, NODE_ID);
                                    
                                      // Send the sketch version information to the gateway and Controller
                                      gw.sendSketchInfo("2 Doorbell Monitor", "1.0");
                                    
                                      // Setup the button and activate internal pull-up
                                      pinMode(DOORBELL1_PIN, INPUT_PULLUP);
                                      pinMode(DOORBELL2_PIN, INPUT_PULLUP);
                                    
                                      // After setting up the button, setup debouncer
                                      debouncer.attach(DOORBELL1_PIN);
                                      debouncer.attach(DOORBELL2_PIN);
                                      debouncer.interval(5);
                                    
                                      // Register all sensors to gw (they will be created as child devices)
                                      gw.present(SWITCH1_CHILD_ID, S_LIGHT);
                                      gw.present(DOORBELL1_CHILD_ID, S_MOTION);
                                      gw.present(SWITCH2_CHILD_ID, S_LIGHT);
                                      gw.present(DOORBELL2_CHILD_ID, S_MOTION);
                                    
                                      // Make sure relays are off when starting up
                                      digitalWrite(RELAY1_PIN, RELAY1_OFF);
                                      digitalWrite(RELAY2_PIN, RELAY2_OFF);
                                      // Then set relay pins in output mode
                                      pinMode(RELAY1_PIN, OUTPUT);
                                      pinMode(RELAY2_PIN, OUTPUT);
                                    
                                      // Set doorbellSound to last known state (using eeprom storage)
                                      doorbell1Sound = gw.loadState(SWITCH1_CHILD_ID);
                                      doorbell2Sound = gw.loadState(SWITCH2_CHILD_ID);
                                    }
                                    
                                    void loop()
                                    {
                                      gw.process();
                                        unsigned long current1Millis = millis();
                                      //Check to see if front doorbell button was pushed.
                                      if (current1Millis - doorbell1Millis > doorbellDelay) //used to stop doorbell from being pressed too frequently
                                      {
                                        debouncer.update();
                                        // Read front doorbell button value
                                        byte doorbell1Detect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
                                    
                                        if (doorbell1Detect != doorbell1PreviousVal)
                                        {
                                          //Serial.print("doorbell1Detect Value: ");
                                          //Serial.println(doorbell1Detect);
                                          if (doorbell1Detect == 1)
                                          {
                                            ringDoorbell1 = true;
                                            doorbell1Timer = current1Millis;
                                          }
                                          doorbell1Millis = current1Millis;
                                          doorbell1PreviousVal = doorbell1Detect;
                                        }
                                      }
                                    
                                      if (ringDoorbell1)
                                      {
                                        if (doorbell1Sound)
                                        {
                                          if (doorbell1Off)
                                          {
                                            digitalWrite(RELAY1_PIN, RELAY1_ON);
                                            //Serial.println("Front Doorbell sounded.");
                                            doorbell1Off = false;
                                          }
                                          else
                                          {
                                            if (current1Millis - doorbell1Timer > ringTime)
                                            {
                                              ringDoorbell1 = false;
                                              digitalWrite(RELAY1_PIN, RELAY1_OFF);
                                              //Serial.println("Front Doorbell off.");
                                              doorbell1Off = true;
                                            }
                                          }
                                        }
                                      }
                                    
                                    //Check to see if back doorbell button was pushed.
                                    unsigned long current2Millis = millis();
                                        if (current2Millis - doorbell2Millis > doorbellDelay) //used to stop doorbell from being pressed too frequently
                                      {
                                        debouncer.update();
                                        // Read back doorbell button value
                                        byte doorbell2Detect = !debouncer.read();//read, then reverse the value so it will send correct trigger state to controller
                                    
                                        if (doorbell2Detect != doorbell2PreviousVal)
                                        {
                                          //Serial.print("doorbell2Detect Value: ");
                                          //Serial.println(doorbell2Detect);
                                          if (doorbell2Detect == 1)
                                          {
                                            ringDoorbell2 = true;
                                            doorbell2Timer = current2Millis;
                                          }
                                          doorbell2Millis = current2Millis;
                                          doorbell2PreviousVal = doorbell2Detect;
                                        }
                                      }
                                    
                                      if (ringDoorbell2)
                                      {
                                        if (doorbell2Sound)
                                        {
                                          if (doorbell2Off)
                                          {
                                            digitalWrite(RELAY2_PIN, RELAY2_ON);
                                            //Serial.println("Back Doorbell sounded.");
                                            doorbell2Off = false;
                                          }
                                          else
                                          {
                                            if (current2Millis - doorbell2Timer > ringTime)
                                            {
                                              ringDoorbell2 = false;
                                              digitalWrite(RELAY2_PIN, RELAY2_OFF);
                                              //Serial.println("Back Doorbell off.");
                                              doorbell2Off = 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
                                          doorbell1Sound = message.getBool();
                                          // Store state in eeprom
                                          gw.saveState(SWITCH1_CHILD_ID, doorbell1Sound);
                                    
                                          // Write some debug info
                                          Serial.print("Incoming change for sensor:");
                                          Serial.print(message.sensor);
                                          Serial.print(", New status: ");
                                          Serial.println(message.getBool());
                                        }
                                        
                                      }```
                                    BulldogLowellB Offline
                                    BulldogLowellB Offline
                                    BulldogLowell
                                    Contest Winner
                                    wrote on last edited by
                                    #27

                                    @drock1985

                                    I think your code is a little hard to get through, but you need two instances of the Bounce library if you want to manage two buttons:

                                      debouncer.attach(DOORBELL1_PIN);
                                      debouncer.attach(DOORBELL2_PIN);
                                    

                                    do this instead:

                                    //...
                                    Bounce debouncePin1 = Bounce();
                                    Bounce debouncePin2 = Bounce();
                                    //...
                                    void setup()
                                    {
                                      //...
                                      debouncePin1.attach(DOORBELL1_PIN);
                                      debouncePin1.interval(5);
                                      debouncePin2.attach(DOORBELL2_PIN);
                                      debouncePin2.interval(5);
                                      //...
                                    }
                                    

                                    and update the state with:

                                    debouncerPin1.update();
                                    

                                    get it?

                                    alternatively you could use an array:

                                    Bounce debouncer[2] = Bounce();
                                    

                                    it would make your code a lot easier, but you have to understand arrays and Classes or you will be a little lost.

                                    1 Reply Last reply
                                    0
                                    • BulldogLowellB BulldogLowell

                                      Haha, I just took the easy way out and ran a 5V line

                                      @petewill

                                      that may be the easy way, but not as fun :(

                                      petewillP Offline
                                      petewillP Offline
                                      petewill
                                      Admin
                                      wrote on last edited by
                                      #28

                                      @BulldogLowell

                                      that may be the easy way, but not as fun :(

                                      I know huh? It seems my opportunity for fun has been getting less and less these days :( I still need to finish the PhoneyTV project...

                                      My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        timropp
                                        wrote on last edited by
                                        #29

                                        My mini RBoard just arrived yesterday to do this... too bad I won't have any time to mess with it till probably next weekend. I'll definitely share some pics and results once I get it installed!

                                        VeraEdge UI7 with Mysensors ethernet gateway

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          timropp
                                          wrote on last edited by
                                          #30

                                          I did take a look at my doorbell last night. I have a transformer down in the basement that's outputting 16VAC. Then the doorbell upstairs, with no convenient place to get power from. The wires from both the doorbell button and the transformer come to the doorbell "box" on the wall.

                                          At first I was looking for a way to convert the 16VAC to 5VDC. Then as I was looking at the space in the doorbell to mount the board, I saw two more wires not connected to anything. They ran 4 conductor wire from the transformer to the bell! Sweet! So now I'll put a 5V source (probably phone charger to USB cable with the end cut off) in the basement, connect that to the other unused pair of wires, and have my power where I need it.

                                          Is there any issue with running the 5V DC power and the 16VAC power alongside each other? It's not like either is carrying data, so I don't think there would be...

                                          VeraEdge UI7 with Mysensors ethernet gateway

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          14

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular