ESP8266 NodeMCU WiFi IoT Garage Door Opener Relay with Cayenne

About This Project

I had previously completed a similar project using Blynk, so I thought it would be good to upgrade my project and try Cayenne.

In this project, we will use an ESP8266 with Cayenne to control a Garage Door Opener. I also use OpenHab Home Automation and included MQTT to be useful with that.

I haven’t been able to get the Fake “light” to indicate if the Garage Door is open just yet.

What’s Connected

ESP8266
Relay
DHT22/AM2303 Temperature & Humidity Sensor
GL5537 Light Sensor
Active Buzzer

Triggers & Alerts

I use a trigger to create the same functionality as a momentary switch would.

Scheduling

No scheduling setup set, but this could be useful to check if the Garage Door is still open after say 9pm and send a txt.

Dashboard Screenshots

Photos of the Project

Full write up on my blog: ESP8266 NodeMCU WiFi IoT Garage Door Opener Relay with Cayenne

6 Likes

Thanks for sharing this project with us. You’ll probably be excited to hear, if you hadn’t gathered it already from this community, that we’ll be launching an MQTT API in the next month or so, so you should soon be able to do even that part through Cayenne as well.

3 Likes

This is really cool, Rich!

1 Like

This looks great. I’m doing something similar but didn’t have somewhere to connect the relay, so have done something to record and replay RF codes (the focus is on replaying codes all the time). You can record your garage codes (to a file), then replay them as needed. Info is on the project here: GitHub - sillyfrog/RFreplayESP: Record and replay RF433Mhz signals on an ESP8266, using the Arduino IDE.
Maybe useful for others in the same situation looking to do something similar.
Cheers!

3 Likes

Great work, thanks for sharing with us. Just a question: how can you menage the 5V relay with the esp8266 NodeMCU that have only 3v3? I can’t see this connection from the photos you posted.

Most (if not all) development boards have a 5v output pin from the USB connection. If you are using a stand alone esp you’ll need to add one.

1 Like

I have this one “tinxi® NodeMCU Lua WIFI Internet Development Board”(this is the uk amazon link, https://goo.gl/44m9lv ) that have Vin pin like yours (as I can see in the first photo of your project) but I supposed it can be used only as IN and not OUT. I was wrong?

It should be connected to the USB 5v. The easiest way to be sure is hook up a multi-meter and see if it reads 5vdc. I would say you should be fine to use it though.

yep, I’ll try.
Thanks again

Hey, thank you for putting this together. This was my first project of DIY programming. To keep things simple I left out MQTT, the buzzer, humidity sensors, etc… But I did add in a 3rd channel to trigger our gate open/close. Would like to improve it some and eventually work with Siri / Ok Google and/or bypass the web as a backup in case internet is down. I can check status with a camera, but that’s also not ideal.

1 Like

So how do you get this to work? I can’t figure it out.

1 Like

Welcome to Cayenne!

What are you having problems with?

1 Like

Where exactly are you getting stuck?

Did you read through the whole write-up here: https://www.wemustbegeeks.com/esp8266-nodemcu-wifi-iot-garage-door-opener-relay-with-cayenne/ ?

I originally did this in October 2016 so I’m sure Arduino versions and libraries have changed but it should still work.

Which ESP chip do you have?

I’ll list it out.

  1. I can’t find the libraries you used. so I can’t configure my NodeMCU v3. I thought I found them but it errors out.
  2. you are missing the extra item for the buzzer. the N thing
  3. This site doesn’t seem to support the nodemcu so you can’t setup your account easily.
  4. I found thread here on how to add the unsupported NodeMCU but when I added a relay it screwed up my NodeMCU so now it boots up, connects, and then crashes. Since it doesn’t stay connected I can’t seem to fix it. Says it is offline.
  5. There are a bunch of project on here but it seems odd I can’t configure my devices to use the “project”. Instead it seems like a manual process using directions on another site? I’d think I could clone your project and push it to my device.

thanks

Cayenne-garage-door-20170812-01:27: error: expected primary-expression before ‘;’ token
int lightPin = ; //define a pin for Photo resistor
^
Cayenne-garage-door-20170812-01:34: error: expected primary-expression before ‘;’ token
unsigned long previousMillis = ;
^
Cayenne-garage-door-20170812-01:35: error: expected primary-expression before ‘;’ token
unsigned long lastTempUpdate = ;
^
Cayenne-garage-door-20170812-01:45: error: expected primary-expression before ‘;’ token
int value = ;
^
Cayenne-garage-door-20170812-01:46: error: expected primary-expression before ‘;’ token
int gState = ;
^
/Users/kevin/Documents/Arduino/Cayenne-garage-door-20170812-01/Cayenne-garage-door-20170812-01.ino: In function ‘void loop()’:
Cayenne-garage-door-20170812-01:73: error: expected primary-expression before ‘(’ token
MyIp = "IP: " + String(WiFi.localIP()) + “.” + String(WiFi.localIP()[1]) + “.” + String(WiFi.localIP()[2]) + “.” + String(WiFi.localIP()[3]);
^
Cayenne-garage-door-20170812-01:73: error: expected primary-expression before ‘]’ token
MyIp = "IP: " + String(WiFi.localIP()) + “.” + String(WiFi.localIP()[1]) + “.” + String(WiFi.localIP()[2]) + “.” + String(WiFi.localIP()[3]);
^
Cayenne-garage-door-20170812-01:89: error: expected primary-expression before ‘)’ token
Cayenne.virtualWrite(V4, );
^
/Users/kevin/Documents/Arduino/Cayenne-garage-door-20170812-01/Cayenne-garage-door-20170812-01.ino: In function ‘void BlynkWidgetWrite3(BlynkReq&, const BlynkParam&)’:
Cayenne-garage-door-20170812-01:144: error: expected primary-expression before ‘)’ token
if (currentValue == ) {
^
/Users/kevin/Documents/Arduino/Cayenne-garage-door-20170812-01/Cayenne-garage-door-20170812-01.ino: In function ‘void CloseGarage()’:
Cayenne-garage-door-20170812-01:154: error: expected primary-expression before ‘;’ token
for (i = ; i <12; i++)
^
Cayenne-garage-door-20170812-01:161: error: expected primary-expression before ‘;’ token
for (i = ; i <15; i++)
^
exit status 1
expected primary-expression before ‘;’ token

The lightPin definition, it should read:

int lightPin = 0;  //define a pin for Photo resistor

(The ESP8266 only has one Analog pin 0)

Oddly, it looks like my website was stripping out “0” from some of the entries such as the lightPin. I’ve gone in and edited that. Which sketch are you using: MQTT or non-MQTT? I can get you a link to the actual sketch.

Which libraries do you have installed and which can’t you find, I will help you track them the missing libraries.

When I originally created this project, Cayenne required the Blynk library, but it looks like Cayenne now has their own.
I’ll see if I have an extra ESP8266 around so I can create a new version of the sketch using the Cayenne Arduino library.

It should still work with the Blynk Libraries, as my sketch is still running on that ESP8266 controlling the garage door.

Rich

I fixed the lightPin but there are a bunch of other lines with errors…

// Generally, you should use “unsigned long” for variables that hold time

You have that note and don’t have anything after the = so it errors out. I was just reading up on this.

I did go in and makes my own values and it works from the website/app but when you apply power it runs the garage door (CloseGarage)

I am using the non-MQTT

Can you post a closeup picture of how your relay is wired?

Some of the relays have options for Normally Open and Normally Closed.

Sounds like you are very close to getting this working!

// Generally, you should use "unsigned long" for variables that hold time
unsigned long previousMillis = 0;
unsigned long lastTempUpdate = 0;
const long interval = 5000;

If you can only wire your relay one way, you’ll need to flip all the values for digitalWrite(13, or whichever pin you are using for the relay.