[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Thanks Dan for quick replying. One of the logic is as follows:

  1. Switch 2 will be turned ON only if Switch 1 is ON
  2. if Switch 1 is turned OFF, then Switch 2 is to be OFF

Thanks

That is a child contact sensor, and it appears to be working fine! :slight_smile: It has a status of Active and was LastUpdated today at 5:14pm. The fact that the child device exists tells me that the communications from the ESP8266 to ST is working. Otherwise it would not have been created.

Please post the Parent Device’s details.

Yes yes I have, but I need to regulate the regulation of gas boiler (2circuits temp senzors) + recuperating unit (CO2 senzor and humidity senzor) + automatic shades (light senzor) etc. Basically each regulation of the specific product works with resistance. So it’ll be good to have the possibility control everything like this. It’s not for ordinary users it’ll help a lot of people who knows what to do. you could use basically everything and control it remotely even old stuff etc etc … so it’s little disappointment I thought it can be done:(

Sorry, it is indeed a child sensor !
Here is a parent one. (was taken @ 8:20AM EDT)

Everything looks good to me. So, the ESP8266 is able to send data to ST as is evident by the creation of the two child devices (contact1 and switch1).

So, if you open the ST Classic App on your phone, and select the switch1 child device, and then click the On/Off section to toggle the switch device’s value… what is the output from the Parent and Child Live Logs? Also. what shows up on the Arduino IDE Serial Monitor?

Here are 2 sets of screenshots :

  1. Non-updated device (was flushed a year ago, or so - no OTA, and probably v2.2.0 )
  2. Newly flushed device (Arduino 1.8.8 & v2.5, ST_A v2.9.3)

Looks like it is working but with a HUGE delay (anything between 2 and 90 minutes), which mistakenly I have observed as non-functional at all.
Not sure what can cause this huge latency.

As you can see - the App tile state did not change once I pressed “turn on” , and it looks like it stacks on “turningOn” state.

First:
App

Parent

Child

SECOND

App

Parent

Child

I would like to control 12v solar lights an fan.

8 Channel Relay 12v Module Boards Optocoupler Arduino ARM AVR DSP PIC PLC.

how I setup it up in smartthings?

Hi Bob! It’s been a while. How are you doing?

So, you’d like to control some relays. That is fairly straightforward using ST_Anything. However, it would help if you shared the exact relay board you’re planning to use, as well as the micro-controller you want to run ST_Anything on.

Just an FYI - the ESP8266 boards have a hard time controlling too many relays depending on the relay design (i.e. active high versus active low relays.) If you want to use an ESP8266 as the controller, you may need at least two of them to handle all 8 relays.

In ST_Anything, you would just start with the ST_Anything_Multiples_ESP8266WiFi.ino sketch and modify it as shown below to try to handle 8 EX_Switch devices.

//******************************************************************************************
//  File: ST_Anything_Multiples_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
//              - 1 x Alarm device (using a simple digital output)
//              - 1 x Contact Sensor devices (used to monitor magnetic door sensors)
//              - 1 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//              - 1 x Motion devices (used to detect motion)
//              - 1 x Smoke Detector devices (using simple digital input)
//              - 1 x Temperature Measurement devices (Temperature from Dallas Semi 1-Wire DS18B20 device)
//              - 1 x Relay Switch devices (used to turn on a digital output for a set number of cycles And On/Off times (e.g.relay, etc...))
//              - 2 x Button devices (sends "pushed" if held for less than 1 second, else sends "held"
//              - 1 x Water Sensor devices (using the 1 analog input pin to measure voltage from a water detector board)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2015-01-03  Dan & Daniel   Original Creation
//    2017-02-12  Dan Ogorchock  Revised to use the new SMartThings v2.0 library
//    2017-04-17  Dan Ogorchock  New example showing use of Multiple device of same ST Capability
//                               used with new Parent/Child Device Handlers (i.e. Composite DH)
//    2017-05-25  Dan Ogorchock  Revised example sketch, taking into account limitations of NodeMCU GPIO pins
//    2018-02-09  Dan Ogorchock  Added support for Hubitat Elevation Hub
//
//******************************************************************************************
//******************************************************************************************
// 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
//******************************************************************************************

#define PIN_SWITCH_1              D0  //SmartThings Capability "Switch"
#define PIN_SWITCH_2              D1  //SmartThings Capability "Switch"
#define PIN_SWITCH_3              D2  //SmartThings Capability "Switch"
#define PIN_SWITCH_4              D3  //SmartThings Capability "Switch"
#define PIN_SWITCH_5              D4  //SmartThings Capability "Switch"
#define PIN_SWITCH_6              D5  //SmartThings Capability "Switch"
#define PIN_SWITCH_7              D6  //SmartThings Capability "Switch"
#define PIN_SWITCH_8              D7  //SmartThings Capability "Switch"


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                           //  <---You must edit this line!
String str_password = "yourWiFiPasswordhere";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 227);       //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, 149);    // 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 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  static st::EX_Switch executor1(F("switch1"), PIN_SWITCH_1, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor2(F("switch2"), PIN_SWITCH_2, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor3(F("switch3"), PIN_SWITCH_3, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor4(F("switch4"), PIN_SWITCH_4, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor5(F("switch5"), PIN_SWITCH_5, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor6(F("switch6"), PIN_SWITCH_6, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor7(F("switch7"), PIN_SWITCH_7, LOW, true);  //Inverted logic for "Active Low" Relay Board
  static st::EX_Switch executor8(F("switch8"), PIN_SWITCH_8, LOW, true);  //Inverted logic for "Active Low" Relay Board
  
  //*****************************************************************************
  //  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);
 
    //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
  //*****************************************************************************
 
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addExecutor(&executor1);
  st::Everything::addExecutor(&executor2);
  st::Everything::addExecutor(&executor3);
  st::Everything::addExecutor(&executor4);
  st::Everything::addExecutor(&executor5);
  st::Everything::addExecutor(&executor6);
  st::Everything::addExecutor(&executor7);
  st::Everything::addExecutor(&executor8);
    
  //*****************************************************************************
  //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();
}

This may be able to handle all 8 relays, although some may toggle (pins D3 and D4) during a reboot of the NodeMCU ESP8266 board.

My testing of the ESP8266 (found in the ReadMe) is shown below:

Wiring this 8 channel relay board up will be a little complicated, as you must power the relay board from an external power supply. You cannot power it from the ESP8266 as the ESP8266 cannot supply enough current for all 8 relays at one time.

This is a decent guide to how to safely wire things up. The examples are for Arduino 5v boards, instead of the ESP8266 3.3v boards. Do not fry your ESP8266!

http://arduinoinfo.mywikis.net/wiki/ArduinoPower#Optically-Isolated_Relays
and
http://arduinoinfo.mywikis.net/wiki/RelayIsolation

Good luck Bob! Please be safe!

p20Ph

The nodemcu v1.0
Keep in mind output is 12 volts from my solar panels.

The 12V would would be handled by the relay’s dry contacts, using the Normally Open (NO) and Common connectors on each relay’s screw terminal.

You’re going to have to read up on how to wire the relays to the ESP8266 yourself. I provided the link above.

smartthings is not turning on the relay.
but smartthings is send the commad

in1 = d2.

the code work for testing

int relay_pin = D2;
int led_pin = D7;

void setup (){
  pinMode(relay_pin, OUTPUT);
  pinMode(led_pin, OUTPUT);
  digitalWrite(led_pin, HIGH);
}

void loop(){
  digitalWrite (relay_pin, HIGH);
  delay (5000);
  digitalWrite (relay_pin, LOW);
  delay (5000);
 /* digitalWrite (relay_pin, LOW);
  delay (5000);
  digitalWrite (relay_pin, HIGH);
  delay (5000); */
}

smartthings code

#include <SmartThings.h>

//******************************************************************************************
// File: ST_Anything_Relays_ESP8266.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_Relays_ESP8266 implements the following ST Capabilities as a demo of what is possible with a single NodeMCU ESP8266
//            - 3 x Relay Switch devices
//
//
// Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2015-01-03  Dan & Daniel   Original Creation
//    2017-02-12  Dan Ogorchock  Revised to use the new SMartThings v2.0 library
//    2017-04-17  Dan Ogorchock  New example showing use of Multiple device of same ST Capability
//                               used with new Parent/Child Device Handlers (i.e. Composite DH)
//    2017-05-25  Dan Ogorchock  Revised example sketch, taking into account limitations of NodeMCU GPIO pins
//    2017-11-27  Kai Lenk       Modified to 3 relaySwitch
//    2017-11-29  Dan Ogorchock  Revisions to make sure works for Kai Lenk
//    2018-02-09  Dan Ogorchock  Added support for Hubitat Elevation Hub
//
//******************************************************************************************
//******************************************************************************************
// 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
//******************************************************************************************

#define PIN_TIMEDRELAY_1 D2 //SmartThings Capability "Relay Switch"
//#define PIN_TIMEDRELAY_2 D6 //SmartThings Capability "Relay Switch"
//#define PIN_TIMEDRELAY_3 D7 //SmartThings Capability "Relay Switch"

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "";                           //  <---You must edit this line!
String str_password = "";                   //  <---You must edit this line!
IPAddress ip(10, 0, 0, 35);     //Device IP Address       //  <---You must edit this line!
IPAddress gateway(10, 0, 0, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 254, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(10, 0, 0, 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(10, 0, 0, 18);    // 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

  //Special sensors/executors (uses portions of both polling and executor classes)
  static st::S_TimedRelay sensor1(F("relaySwitch1"), PIN_TIMEDRELAY_1, LOW, true, 3000, 0, 1);
  //static st::S_TimedRelay sensor2(F("relaySwitch2"), PIN_TIMEDRELAY_2, LOW, true, 3000, 0, 1);
  //static st::S_TimedRelay sensor3(F("relaySwitch3"), PIN_TIMEDRELAY_3, LOW, true, 3000, 0, 1);

  //*****************************************************************************
  //  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);

  //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);
  //st::Everything::addSensor(&sensor3);

  //*****************************************************************************
  //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();
}

Bob,

Please read the documentation for the EX_Switch class and adjust the parameters are necessary for your type of relay module.

//******************************************************************************************
//  File: EX_Switch.h
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  EX_Switch is a class which implements the SmartThings "Switch" device capability.
//			  It inherits from the st::Executor class.
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example:  st::EX_Switch executor1(F("switch1"), PIN_SWITCH, LOW, true);
//
//			  st::EX_Switch() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- byte pin - REQUIRED - the Arduino Pin to be used as a digital output
//				- bool startingState - OPTIONAL - the value desired for the initial state of the switch.  LOW = "off", HIGH = "on"
//				- bool invertLogic - OPTIONAL - determines whether the Arduino Digital Output should use inverted logic

Ok Bob - This is the last bit that I think you need… Those are ‘Active Low’ relays so the sketch I sent should just “work” without any changes, I believe.

Here is the wiring diagram.

If you posted a sketch I cannot see it.

C’mon BOB!!! The sketch was in the first reply to you just 1 hour ago! I have now done your entire project for you!!! And not a single THANK YOU!!! :angry:

3 Likes

It can be done with the addition of interface circuitry. The two methods that come to mind are:

  1. Digital potentiometer IC. See this link for an Arduino library that was developed for such a chip that uses a SPI interface. It would be fairly easy to adapt ST_Anything to work with this IC.
  1. Arduino PWM driving transistor/resistor circuit. This would also be fairly easy to drive with a modified ST_Anything child device.

Still not working will not turn on and off from SmartThings. Maybe I’m missing something here what smart app am I supposed to be using along with what device handler? I appreciate your guys’s help so far.

In the demonstration video you linked above, there is no SmartApp being used. Just the SmartThings Classic mobile phone app. After you get it working via the ST mobile app, you can use whatever SmartApps (e.g. Smart Lighting, Routines, webCoRE, etc…) you want to control these ‘switches’ just just any other switch device in SmartThings.

Simply follow the ST_Anything ReadMe found in my GitHub repository to set up everything (all of the ST_Anything Parent and Child Device Handlers are configured as part of the ReadMe setup process.)

UPDATE: I just tested the code and the wiring and it works fin for me (although I do not have a 8 channel relay board. I used a 2-channel board.

Note: I tried my 4-channel board, but it requires 5v for both the relay power as well as the Input signals. The relay board LEDs would illuminate correctly, but the relays would not actually physically change state. Obviously, some older relay boards are not compatible with the 3.3v digital outputs of the ESP8266 and would work better using an Arduino MEGA which uses 5v.

I’ve tried all your relay smart handlers the none of them seem to be turning on. My Arduino says that it is in an off State when it gets the command.

That is the log from the Arduino IDE.
I’ve also tried your relay apps and none of them work either. Did you throw out pain that I am using is d0 5 volt and ground.

However when I test with the example code outside of SmartThings my whole entire setup works just fine over Wi-Fi. the problem lies when I add the SmartThings code. like I said I am no programmer to this stretch of the imagination so maybe I’m missing something. Again I appreciate your guys’s help in this matter. My wife has been asking me to automate these lights and pan for months so you guys’s help would be appreciated once again.