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
}