Raspberry Pi Zero and Relay for Garage Door Opener

That is the contact sensor portion of the doorControl. Are you activating and deactivating the magnetic reed switch?

Can you please post a copy of your sketch here? Remove your WiFi credentials first, of course.

Below is my sketch. The only changes I made from the reference is to add the line quoted below and commented out the 2nd door devices. FYI, I have the reed switch to Com and NC.

//******************************************************************************************
//  File: ST_Anything_GarageDoors_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_Multiples implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
//              - 2 x Door Control devices (used typically for Garage Doors - input pin (contact sensor) and output pin (relay switch)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-01-24  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************

//Garage Door Pins 
#define PIN_DOORCONTROL_CONTACT_1 D2  //SmartThings Capabilty "Door Control"
#define PIN_DOORCONTROL_RELAY_1   D1  //SmartThings Capabilty "Door Control" 
//#define PIN_DOORCONTROL_CONTACT_2 D5  //SmartThings Capabilty "Door Control"
//#define PIN_DOORCONTROL_RELAY_2   D6  //SmartThings Capabilty "Door Control" 

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "DEFAULT";                           //  <---You must edit this line!
String str_password = "BLANK";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 221);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 1, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings / Hubitat Hub TCP/IP Address
IPAddress hubIp(192, 168, 1, 188);    // smartthings/hubitat hub ip //  <---You must edit this line!

// SmartThings / Hubitat Hub TCP/IP Address: UNCOMMENT line that corresponds to your hub, COMMENT the other
//const unsigned int hubPort = 39500;   // smartthings hub port
const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
  
  //Interrupt Sensors 
  static st::IS_DoorControl sensor1(F("doorControl1"), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, HIGH, true, 1000, 1000);
  //static st::IS_DoorControl sensor2(F("doorControl2"), PIN_DOORCONTROL_CONTACT_2, LOW, true, PIN_DOORCONTROL_RELAY_2, LOW, true, 1000, 1000);
 
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString, "OfficeESP");
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
  //st::Everything::addSensor(&sensor2);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
    
  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}

Soldered new header on a new board and uploaded the sketch above to it with different IP. I now get clicking sounds when I move the reed switch around. I don't see the status of the device get updated as often as I see messages in the logs..

dev:3872019-08-18 03:59:48.708 pm debug[name:rssi, value:-66, displayed:false]

dev:3872019-08-18 03:59:48.706 pm debugIn parse: RSSI name = rssi, value = -66

dev:3872019-08-18 03:59:48.702 pm debugmsg= rssi -66

dev:3872019-08-18 03:59:48.698 pm debugdescription= 'mac:2462AB094D8B, ip:c0a801de, port:d857, headers:UE9TVCAvIEhUVFAvMS4xDQpDb250ZW50LUxlbmd0aDogOA0KSG9zdDogMTkyLjE2OC4xLjE4ODozOTUwMQ0KQ29udGVudC1UeXBlOiB0ZXh0DQo=, body:cnNzaSAtNjY='

dev:3872019-08-18 03:58:54.669 pm debug[name:rssi, value:-67, displayed:false]

dev:3872019-08-18 03:58:54.665 pm debugIn parse: RSSI name = rssi, value = -67

dev:3872019-08-18 03:58:54.662 pm debugmsg= rssi -67

dev:3872019-08-18 03:58:54.657 pm debugdescription= 'mac:2462AB094D8B, ip:c0a801de, port:d4c6, headers:UE9TVCAvIEhUVFAvMS4xDQpDb250ZW50LUxlbmd0aDogOA0KSG9zdDogMTkyLjE2OC4xLjE4ODozOTUwMQ0KQ29udGVudC1UeXBlOiB0ZXh0DQo=, body:cnNzaSAtNjc='

dev:3872019-08-18 03:58:01.710 pm debug[name:rssi, value:-70, displayed:false]

dev:3872019-08-18 03:58:01.706 pm debugIn parse: RSSI name = rssi, value = -70

dev:3872019-08-18 03:58:01.702 pm debugmsg= rssi -70

dev:3872019-08-18 03:58:01.698 pm debugdescription= 'mac:2462AB094D8B, ip:c0a801de, port:c927, headers:UE9TVCAvIEhUVFAvMS4xDQpDb250ZW50LUxlbmd0aDogOA0KSG9zdDogMTkyLjE2OC4xLjE4ODozOTUwMQ0KQ29udGVudC1UeXBlOiB0ZXh0DQo=, body:cnNzaSAtNzA='

dev:3872019-08-18 03:57:09.662 pm debug[name:rssi, value:-68, displayed:false]

dev:3872019-08-18 03:57:09.659 pm debugIn parse: RSSI name = rssi, value = -68

dev:3872019-08-18 03:57:09.656 pm debugmsg= rssi -68

dev:3872019-08-18 03:57:09.653 pm debugdescription= 'mac:2462AB094D8B, ip:c0a801de, port:c19b, headers:UE9TVCAvIEhUVFAvMS4xDQpDb250ZW50LUxlbmd0aDogOA0KSG9zdDogMTkyLjE2OC4xLjE4ODozOTUwMQ0KQ29udGVudC1UeXBlOiB0ZXh0DQo=, body:cnNzaSAtNjg='

dev:3872019-08-18 03:56:18.667 pm debug[name:rssi, value:-70, displayed:false]

dev:3872019-08-18 03:56:18.663 pm debugIn parse: RSSI name = rssi, value = -70

dev:3872019-08-18 03:56:18.660 pm debugmsg= rssi -70

dev:3872019-08-18 03:56:18.656 pm debugdescription= 'mac:2462AB094D8B, ip:c0a801de, port:d7ee, headers:UE9TVCAvIEhUVFAvMS4xDQpDb250ZW50LUxlbmd0aDogOA0KSG9zdDogMTkyLjE2OC4xLjE4ODozOTUwMQ0KQ29udGVudC1UeXBlOiB0ZXh0DQo=, body:cnNzaSAtNzA='

What pins did you solder the reed switch to?

D1 is connected to Com and NC is tied to Ground

Hang on... let’s figure out your wiring. The relay should be simply plugged into the Wemos board. At this time, do NOT wire anything to it whatsoever.

The magnetic reed switch should have two wires. Attach one to the Wemos board’s GND pin, and the other to the Wemos board’s D2 pin.

The magnetic reed switch (I.e. contact sensor) has nothing to do with the relay. It simply indicates whether the door is open or closed.

Eventually, the relay’s COM and NO connections will be wired in parallel to your garage door opener’s “doorbell button” to simulate someone pressing that button.

2 Likes

Everything seems to work now, I think I misinterpreted some of the directions above. I will mount it up and see how it works.

1 Like