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.
  • T timropp

    Ok, finally worked this again today. Here's the status. I modified the sketch to update it to 2.0, giving me this:

    /*
     * 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
     * Version 2.0 - timropp, updating for MySensors 2.0
     *
     * 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
     */
    
    #define MY_RADIO_NRF24
    #define MY_REPEATER_FEATURE
    
    #include <MySensors.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you.
    
    #define DOORBELL_PIN A0      // 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();
    
    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 = 400; //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()
    {
      // 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);
    
      // 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 = loadState(SWITCH_CHILD_ID);
    }
    
    void loop()
    {
        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);
          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 receive(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
          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());
        }
      }
    
    void presentation()
      {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Doorbell Monitor", "1.0");
        // Register all sensors to gw (they will be created as child devices)
      present(SWITCH_CHILD_ID, S_LIGHT);
      present(DOORBELL_CHILD_ID, S_MOTION);
      }
    

    Sitting on my desk, it works fine. It appears in Home Assistant, clicks the relay when A0 is shorted to ground, and that appears in HASS as a motion event. Seems good, so I installed it in the doorbell. Doesn't work there. I get one ring when I hook up power, and then nothing. I checked again the leads from the physical doorbell button with a multimeter - I get a good continuity buzz when I press the button and silence when not pressed. Then I discovered something - if I physically unhook the wire going to A0 and reconnect it, the doorbell rings and I get that notification in Hass. If I unhook and reconnect the wire again, same thing. So that makes it appear that the A0 is being constantly grounded - is that possible? It acts like my physical doorbell button is stuck in the pressed position, but the multimeter indicates it's fine.

    Further testing - If I connect the board to the doorbell system but leave the physical doorbell button disconnected, then attach a spare piece of wire to A0 and ground it, the system works perfectly. So it's definitely something related to the physical button.

    On thing I've realized - I THINK the outdoor button is an illuminated one, which isn't illuminated with this system. Could that light be the cause? If so, why doesn't the continuity test show it as continuous? I think I'll go buy a basic non-illuminated button and install it and see if that works. Or just pull the button out of the wall, disconnect the wires, and then short them together. Duh, that'd be easier and cheaper. I'll try that this afternoon - have a wedding to get to first.

    dbemowskD Offline
    dbemowskD Offline
    dbemowsk
    wrote on last edited by dbemowsk
    #95

    @timropp said:

    I THINK the outdoor button is an illuminated one, which isn't illuminated with this system. Could that light be the cause?

    The button is probably illuminated with LEDs and a resistor (depending how old it is). This could complete the circuit to the digital input on the arduino making it look like the button is pressed. It is probably not seen on a continuity test when the button is not pressed because the resistance is enough where you don't have full continuity. See if reversing the wires into the arduino A0 and ground gets it working. If the doorbell is illuminated with an LED and a resistor that should reverse the current flow of the LED/resistor into A0 on the arduino in effect preventing that problem.

    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

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

      It's definitely the illuminated button. I pulled it out and connecting the wires rings the bell correctly. I hadn't thought about swapping the wires... It is pretty new but I wasn't considering the possibility of it being led. I'll give that a try. Worst case, replace it with a non lit button. Just glad to have finally figured it out!

      edit: actually, I'm betting it's not a LED. These buttons are typically on a 16VAC system, so a LED wouldn't work without more components. Whereas a simple incandescent bulb works fine on AC. So I think I probably just need a new button.

      VeraEdge UI7 with Mysensors ethernet gateway

      dbemowskD 1 Reply Last reply
      1
      • T timropp

        It's definitely the illuminated button. I pulled it out and connecting the wires rings the bell correctly. I hadn't thought about swapping the wires... It is pretty new but I wasn't considering the possibility of it being led. I'll give that a try. Worst case, replace it with a non lit button. Just glad to have finally figured it out!

        edit: actually, I'm betting it's not a LED. These buttons are typically on a 16VAC system, so a LED wouldn't work without more components. Whereas a simple incandescent bulb works fine on AC. So I think I probably just need a new button.

        dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by dbemowsk
        #97

        @timropp said:

        actually, I'm betting it's not a LED. These buttons are typically on a 16VAC system, so a LED wouldn't work without more components. Whereas a simple incandescent bulb works fine on AC. So I think I probably just need a new button.

        Actually an LED WILL work on AC. It will just flicker at 50/60 Hz (Depending on what country you are from) when connected with only a resistor which is only slightly noticeable to the naked eye. The flickering is because it is only lighting the LED on one half of the AC sine wave. An LED is a current controlled device, so all you need to make it work on AC is the correct size resistor to limit the current for whatever voltage you put on it. You can put more complex components in to stop the flickering such as a bridge rectifier, but for very basic operation it is not needed.

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

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

          Final update - no local stores carry a non-illuminated doorbell button. Argh. So I ended up taking the button apart on mine, yanking the incandescent bulb out, and putting it back together. Since it's held together with just some bent over tabs, they broke off and I had to glue it back together. Once I did, everything worked perfectly. The sketch I posted above is working great - doorbell rings and the ring appears in my Home Assistant like it should.

          VeraEdge UI7 with Mysensors ethernet gateway

          petewillP 1 Reply Last reply
          0
          • T timropp

            Final update - no local stores carry a non-illuminated doorbell button. Argh. So I ended up taking the button apart on mine, yanking the incandescent bulb out, and putting it back together. Since it's held together with just some bent over tabs, they broke off and I had to glue it back together. Once I did, everything worked perfectly. The sketch I posted above is working great - doorbell rings and the ring appears in my Home Assistant like it should.

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

            @timropp Glad you got it working!

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mitpol15
              wrote on last edited by
              #100

              Thanks, guys! You can't even imagine how much time I spent to find the solution. Currently works perfectly! Hope everything gonna be alright

              The market of doorbells and chimes is rich and diverse. Therefore, I would like to share the best door chimes and bells review with all homeowners.
              https://www.bestadvisor.com/door-chimes-and-bells

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mister_ik
                wrote on last edited by
                #101

                Thanks for this great project/hack.

                I built this project and it is working great, but i have a question about this. My controller is Domoticz and in Domoticz i have the two switches (DOORBELL_CHILD_ID, SWITCH_CHILD_ID). I though with this project i could also use the ringer of my doorbell as a sort of alarm in other combinations, but if a use the doorbell-switch in Domoticz the doorbell won't ring. But if i use the normal doorbell at my front door, it will ring.

                Is there something wrong in my sketch or am i missing something else?

                Thanks in advance for your help!

                petewillP 1 Reply Last reply
                0
                • M Mister_ik

                  Thanks for this great project/hack.

                  I built this project and it is working great, but i have a question about this. My controller is Domoticz and in Domoticz i have the two switches (DOORBELL_CHILD_ID, SWITCH_CHILD_ID). I though with this project i could also use the ringer of my doorbell as a sort of alarm in other combinations, but if a use the doorbell-switch in Domoticz the doorbell won't ring. But if i use the normal doorbell at my front door, it will ring.

                  Is there something wrong in my sketch or am i missing something else?

                  Thanks in advance for your help!

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

                  @Mister_ik You're not missing anything. It wasn't designed to do what you're describing. That is an interesting idea that I never thought of though! It shouldn't be too hard to implement if you wanted to try. I'm not sure which device types are available in Domoticz but I would think you would want to use some sort of momentary button press (rather than an on/off switch) in Domoticz. You could then send that to the sensor and when it receives the command it could trigger the relay. Have a look at the relay actuator code if you haven't done this before. https://github.com/mysensors/MySensors/blob/development/examples/RelayActuator/RelayActuator.ino#L82

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

                  M 1 Reply Last reply
                  0
                  • petewillP petewill

                    @Mister_ik You're not missing anything. It wasn't designed to do what you're describing. That is an interesting idea that I never thought of though! It shouldn't be too hard to implement if you wanted to try. I'm not sure which device types are available in Domoticz but I would think you would want to use some sort of momentary button press (rather than an on/off switch) in Domoticz. You could then send that to the sensor and when it receives the command it could trigger the relay. Have a look at the relay actuator code if you haven't done this before. https://github.com/mysensors/MySensors/blob/development/examples/RelayActuator/RelayActuator.ino#L82

                    M Offline
                    M Offline
                    Mister_ik
                    wrote on last edited by
                    #103

                    @petewill Thanks for pointing me in the right direction. I am not a programmer but i managed to get this working with your sketch and the example sketch of the relay

                    petewillP 1 Reply Last reply
                    0
                    • M Mister_ik

                      @petewill Thanks for pointing me in the right direction. I am not a programmer but i managed to get this working with your sketch and the example sketch of the relay

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

                      @Mister_ik Awesome! Good job.

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

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        flopp
                        wrote on last edited by flopp
                        #105

                        Very long time ago this was active.

                        I tried the code for MySensors 2.0 but it triggers my relay all the time.

                        When I press simulate a button-press the relay goes off, then on and then stays on.

                        I have the stuff on my desk so it is not connected to my button.

                        Only differene is that I am using a Arduino nano, so the signal from PIN 4 is 5 volt.

                        I think the micro is only giving 3.3 volt out on pins?

                        F 1 Reply Last reply
                        0
                        • F flopp

                          Very long time ago this was active.

                          I tried the code for MySensors 2.0 but it triggers my relay all the time.

                          When I press simulate a button-press the relay goes off, then on and then stays on.

                          I have the stuff on my desk so it is not connected to my button.

                          Only differene is that I am using a Arduino nano, so the signal from PIN 4 is 5 volt.

                          I think the micro is only giving 3.3 volt out on pins?

                          F Offline
                          F Offline
                          flopp
                          wrote on last edited by
                          #106

                          @flopp
                          Found one mistake. I wrote some Serial.print to see where in the code my problem was and I wrote in a wrong place, so the code was looping on a wrong way.

                          When that was corrected I found out that my relay needed to get 1 when it was off, so I just changed to below and now I don't get a green light as soon as I power on the arduino

                          #define RELAY_ON 0
                          #define RELAY_OFF 1
                          
                          1 Reply Last reply
                          1
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          17

                          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