Homey Community Forum

HomeyDuino @V2.0 NodeMCU ESP8266 Smart doorbell succesfully working

#1

Hi, I just want to point out that contrary to what i read on the forum I have successfully tinkered with NodeMCU ESP8266 on Arduino code and completed to implement a traditional doorbell to become a smart doorbell using Homey V2.0x software. It has been running for almost two weeks without any issues and sends notifications to me through Homey when someone presses the doorbell. Needless to say that a ringer in the house notifies everyone there.
As the code is based on what i came across in Athom’s documentation of HomeyDuino I’m happy to share it hear (please note that I am not a developer and I’m not claiming to have perfect coding). Use it at your own risk, as is. I take no responsibility or liability.

/* Smart doorbell with NodeMCU ESP8266 V1 and HomeyDuino

  • The NodeMCU is powered with a 5V 700ma microusb power adapter
  • The doorbell is seperately powered with 9V 1A AC adapter and for safety the 5V active relais should be seperated with an optocoupler
  • In homey goto flows and create a new flow. Create a card Trigger [Boolean] with Tags Value is _onoff in the When section.
  • Create a notification Doorbell Rang with 0 seconds delay in the in the Then section. Don’t forget to save the flow as Doorbell.
    */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Homey.h>

//WiFi.mode(WIFI_STA); // prevents the softap FaryLink to become active and visible
int Status = 5; //connect the Int of the relay to D1 through the Base (3) of BD139 and 100K resistor from Collector to ground
int sensor = 4; //connect one end of the doorbell push button lead to D2,
//connect a 100K resistor from D2 to positive 3V3,
//connect the other end of the doorbell push button lead to ground.

void wifi() {
WiFi.mode(WIFI_STA); // Stop the FaryLink softAP from becoming active
if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(“YOUR SSID NETWORK NAME”, “YOUR WIFI PASSWORD”); // input the desired SSID and Key here
uint8_t timeout = 30;
while (WiFi.status() != WL_CONNECTED) {
delay(10);
Serial.print(".");
if (timeout<1) break;
}
if (WiFi.status() == WL_CONNECTED) {
/*Print IP address
Serial.println("")
Serial.print(“WiFi connected to: “);
Serial.print(WiFi.localIP());
delay(5000);
*/
Serial.println(””);
}
}
}

void setup() {
Serial.begin(115200);
Homey.begin(“Doorbell”); // this will be the name of your button in Homey
Homey.setClass(“socket”); // this is the classtype. The doorbell push button behaves like a socket with on/off functionality
Homey.addCapability(“onoff”, onoffCb); // adding capability _onoff to Trigger Boolean
pinMode(sensor, INPUT); // declare sensor as input (i.e. the doorbell push button)
pinMode(Status, OUTPUT); // declare the relay through BD139 as output
}

void onoffCb() { // this routine is called for _onoff
bool value = Homey.value.toInt();
setOutput(value);
}

void setOutput(bool value) {

                                                           // Do something with value, for example a digitalWrite(<pin>, value);
        digitalWrite (Status, HIGH);                       // sets the relay high 
        delay(10);                                         // prevents jittering relay
        Homey.setCapabilityValue("_onoff", (true));        // sets Homey capabiltiy to true
        Homey.trigger("_onoff", (true));                   // sends a trigger to Homey to start the Doorbell flow 
        Serial.println("SW Push detected!");             // activate this line if you need to check pressing the Doorbell button in Homey works
        delay(1200);                                       // this is the hold time for the relais or as long as the doorbell will ring   

/* done */
Homey.setCapabilityValue("_onoff", value); // sets Homey capability to the new value
}

void loop(){
wifi();
Homey.loop();
long state = digitalRead(sensor);
if(state == LOW){
digitalWrite (Status, HIGH); // sets the relais through D2 and BD139 active
delay(10); // prevents jittering relay
Homey.setCapabilityValue("_onoff", (true)); // sets Homey capabiltiy to true
Homey.trigger("_onoff", (true)); // sends a trigger to Homey to start the Doorbell flow
Serial.println(“HW Push detected!”); // activate this line if you need to check pressing the real Doorbell button works
Homey.returnResult(onoffCb); // returns the real Doorbell button push to Homey
delay(1200); // this is the hold time for the relais or as long as the doorbell will ring
}
else
digitalWrite (Status, LOW); // deactivates the relais
state == HIGH; // returns the Doorbell button to high (pullup) state
Homey.setCapabilityValue("_onoff", (false)); // sets Homey capabiltiy to false
Serial.println(“HW Push absent!”); // activate this line if you need to check not pressing the real Doorbell button works
}

1 Like
HomeyDuino Simple Switch
#2

Would you mind detailing the hardware too?

#3

Hi Konrad,

Good question and here you go:
1 ESP8266 NodeMCU V2
2 10K resistors
1 BD139 or BD140 Transistor
1 5V relais with opto-coupler
assuming you have an existing doorbell ring knob and ringer on 8V 1A

Please setup your hardware parts on breadbord first to test and note that I take no responsibility or liability.

A rough layout of how it is connected is here:

#4

maybe we should start a new “collecting thread” for successful created Homeyduino projects?

2 Likes
#5

Hi Pino,

which part of the code I need for only using the switch function?
I want to trigger a switch on homey by pressing the bell connected on the nodemcu so I dont need the relais etc.

Regards, Marius

#6

Hi Markus,

Depending on the load. The BD139 transistor can handle loads as much as one or two leds. The relais is used both to physically seperate the circuits through the optocoupler and keep the higher voltage and amperge that could destroy the nodemcu away. Anyhow you don‘t need to skip any part of the code but just leave the relay out to achieve that.

#7

I don’t need any load, as far as I know, the only thing I want is when the doorbell push button is used a trigger is send to homey. I want to place some wmos inside my light socket so a push switch activate my hue lights.

Regards Marius

#8

Hi Marius,

For that purpose you can leave out the relay and use a simpler version of the code (untested).
Mind you that you don’t even need to change the code to this simpler version, just removing all the hardware to drive the relay should also work. I urge you to test everything on a breadboard first to see if it runs and works error-less before soldering and implementing. Again this code is as is and to be used at your own risk. I take no responsibility or liability.

The schematics:
Simple%20doorbell%20notification%20only

The code:
/* Simple Smart doorbell with NodeMCU ESP8266 V1 and HomeyDuino

The NodeMCU is powered with a 5V 700ma microusb power adapter

In homey goto flows and create a new flow. Create a card Trigger [Boolean] with Tags Value is _onoff in the When section.

Create a notification Doorbell Rang with 0 seconds delay in the in the Then section. Don’t forget to save the flow as Doorbell.

*/

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#include <Homey.h>

//WiFi.mode(WIFI_STA); // prevents the softap FaryLink to become active and visible

int sensor = 4; //connect one end of the doorbell push button lead to D2,

//connect a 100K resistor from D2 to positive 3V3,

//connect the other end of the doorbell push button lead to ground.

void wifi() {

WiFi.mode(WIFI_STA); // Stop the FaryLink softAP from becoming active

if (WiFi.status() != WL_CONNECTED) {

WiFi.begin(“YOUR SSID NETWORK NAME”, “YOUR WIFI PASSWORD”); // input the desired SSID and Key here

uint8_t timeout = 30;

while (WiFi.status() != WL_CONNECTED) {

delay(10);

Serial.print(".");

if (timeout<1) break;

}

if (WiFi.status() == WL_CONNECTED) {

/*Print IP address

Serial.println("")

Serial.print(“WiFi connected to: “);

Serial.print(WiFi.localIP());

delay(5000);

*/

Serial.println(””);

}

}

}

void setup() {

Serial.begin(115200);

Homey.begin(“Doorbell”); // this will be the name of your button in Homey

Homey.setClass(“socket”); // this is the classtype. The doorbell push button behaves like a socket with on/off functionality

Homey.addCapability(“onoff”, onoffCb); // adding capability _onoff to Trigger Boolean

pinMode(sensor, INPUT); // declare sensor as input (i.e. the doorbell push button)

}

void onoffCb() { // this routine is called for _onoff

bool value = Homey.value.toInt();

setOutput(value);

}

void setOutput(bool value) {

// Do something with value, for example a digitalWrite(<pin>, value);

Homey.setCapabilityValue("_onoff", (true)); // sets Homey capabiltiy to true

Homey.trigger("_onoff", (true)); // sends a trigger to Homey to start the Doorbell flow

Serial.println("SW Push detected!"); // activate this line if you need to check pressing the Doorbell button in Homey works

/* done */

Homey.setCapabilityValue("_onoff", value); // sets Homey capability to the new value

}

/*

void loop(){

wifi();

Homey.loop();

Homey.setCapabilityValue("_onoff", (true)); // sets Homey capabiltiy to true

Homey.trigger("_onoff", (true)); // sends a trigger to Homey to start the Doorbell flow

//Serial.println(“HW Push detected!”); // activate this line if you need to check pressing the real Doorbell button works

Homey.returnResult(onoffCb); // returns the real Doorbell button push to Homey

}

else

state == HIGH; // returns the Doorbell button to high (pullup) state

Homey.setCapabilityValue("_onoff", (false)); // sets Homey capabiltiy to false

Serial.println(“HW Push absent!”); // activate this line if you need to check not pressing the real Doorbell button works */

}

#9

Hi, I used the original code and it works, I can trigger a flow, now the next part :slight_smile:
When I push the button the lights turn on, but how do I achieve putting the lights off? Because when I push the button, homey starts the Doorbell Flow again switching the lights on again :smiley:

Regards, Marius

#10

Never mind I fixed in the flow Thanks for your help regards, Marius

#11

Hi Marius,

Good to hear that it’s working now. For future users; would you mind sharing what hardware you used and what you did in the flow to make it work?

Much appreciated!