SmartThings Community

[RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi

(John Thrasher) #2915

I found that you can edit the preferences from IDE and put the info in on there its been working for me 100% of the time. There’s a weird glitch where you can still add the device when you search but it doesn’t add anything because its already in the list. Sorry if I’m explaining that poorly

(Dan) #2916

Yes, I do the same as well, but the ReadMe instructions are written for using the ST Classic App… So I try to be consistent. :slight_smile:

(Shaun Ellis) #2917

@ogiewon was a bad board along with a section of code Hub IP address was commented out, I didn’t catch that. New board flashed and all is up and running. Thanks

1 Like
(Shaun Ellis) #2918

@Synthesis - Hi i was reading your post concerning the car remote, while searching for a momentary relay control. So I’m actually looking to do the same thing, but I was actually going to take another remote, connect my relay outputs to that to control the functions, and leave the remote and ESP at home. My main goal is to add remote car start to my morning routine for cold and hot days. I’m curious how your project worked out?

(John Thrasher) #2919

Crazy coincidence I just ran into this exact issue last night. I had a board that just would not add to ST, I’m glad you mentioned bad board cause as soon as I swapped it out it added right away and created all the child devices

1 Like
(Shaun Ellis) #2920

@thrasher204 I’ve bought mine from Ali. This one programmed once and never again, and had a heck of a time getting the first program on it. I keep spares around for that reason and when I get an idea.


Thank you Ogiewon for all of your effort on this project! I got my LinkNodeR8 up and running based on the LinkNode R4 code you included in the package. I had a **** of a time getting the children to populate but after leaving the boot jumper off and/or rebooting the ST hub, she chooched!

Here’s the final LinkNode R8 code I used if anyone else wants to play along. Relays correspond to switch numbers 1 - 8, top to bottom, left to right. I used NodeMCU 1.0 (ESP-12E Module) as the board in the IDE.

//  File: ST_Anything_LinkNodeR8_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 LinkNodeR8 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 LinkNodeR8 ESP8266's WiFi.
//            ST_Anything_LinkNodeR8 implements the following Capabilities as a demo of what 
//            is possible with a single LinkSprite LinkNode R8 board
//              - 8 x Switch devices (used to turn on a digital output (e.g. LED, relay, etc...)
//  Board Programming details available at:
//  Change History:
//    Date        Who            What
//    ----        ---            ----
//    2019-03-26  Dan Ogorchock  Original Creation
//    2019-05-18  John Crusan    Modified LinkNode R4 Code to support LinkNode R8
// 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 <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//Define which Arduino Pins will be used for each device
#define PIN_S1              14  //LinkNode R8 Board Marking D8
#define PIN_S2              13  //LinkNode R8 Board Marking D7
#define PIN_S3               5  //LinkNode R8 Board Marking D10
#define PIN_S4              15  //LinkNode R8 Board Marking D11
#define PIN_S5              12  //LinkNode R8 Board Marking D6
#define PIN_S6              16  //LinkNode R8 Board Marking D9
#define PIN_S7               4  //LinkNode R8 Board Marking D17
#define PIN_S8              10  //LinkNode R8 Board Marking D12

//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, 127);       //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 Hub Information
IPAddress hubIp(192, 168, 1, 104);  // smartthings hub ip       //  <---You must edit this line!
const unsigned int hubPort = 39500; // smartthings hub port

// Hubitat Hub Information
//IPAddress hubIp(192, 168, 1, 143);    // hubitat hub ip         //  <---You must edit this line!
//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 = "));
  //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)
  static st::EX_Switch executor1(F("switch1"), PIN_S1, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor2(F("switch2"), PIN_S2, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor3(F("switch3"), PIN_S3, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor4(F("switch4"), PIN_S4, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor5(F("switch5"), PIN_S5, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor6(F("switch6"), PIN_S6, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor7(F("switch7"), PIN_S7, LOW, false);  //Non-Inverted logic for "Active High" Relay Board
  static st::EX_Switch executor8(F("switch8"), PIN_S8, LOW, false);  //Non-Inverted logic for "Active High" 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

  //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, "LinkNodeR8");
    //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
  //Add each sensor to the "Everything" Class
  //Add each executor to the "Everything" Class
  //Initialize each of the devices which were added to the Everything Class

//Arduino Loop() routine
void loop()
  //Execute the Everything run method which takes care of "Everything"
1 Like
(Shaun Ellis) #2922

@ogiewon am I reading correctly that I can use a distance sensor in place of the contact sensor for the garage door function? If so, is there a specific sensor that I must use? I got my DS18B20 temp sensor to read in the example sketch, but before I order I thought I’d ask. Thanks

(Dan) #2923

Some users have hacked together a solution like that. Personally, I use inexpensive wired contact sensors on my pair of doors. They would every time without fail. Pretty simple device, when you think about it - a reed switch and a magnet. Not much to fail.

I remember one user used an Ultrasonic sensor to know whether or not his cars were present in the garage. I think we treated this as a presence sensor. Looks like the code for that is still in the following child DTH. The reported value is compared against a threshold to determine present or away.


First of all thanks for this library and all the support you provide.

I am trying to get the LED_on/off demo working and I keep getting “post request timed out”

Here is the output from the serial monitor

Disabling ESP32 WiFi Access Point

[WiFi-event] event: 0
[WiFi-event] event: 2
ESP32 station start

Initializing ESP32 WiFi network.  Please be patient...
Attempting to connect to WPA SSID: BLAH
..[WiFi-event] event: 7
WiFi connected
IP address:
[WiFi-event] event: 7
WiFi connected
IP address:

Enter the following three lines of data into ST App on your phone!
localIP =
serverPort = 8090

hubIP =
hubPort = 39500
RSSI = -55

SmartThingsESP32WiFI: Intialized

Ready! Open http://esp32-webupdate.local in your browser
IP address:
MAC address: CC:50:E3:80:9B:D4
Post request timed out

Post request timed out

Received message: 'off' 
Post request timed out

Post request timed out

And here is the output from the live debug

8:22:32 PM: debug Using ip: and port: 8090 for device: DEVIC_ADDRESS
8:22:32 PM: debug Executing 'sendEthernet' off
8:22:32 PM: debug Sending 'off'
8:22:32 PM: debug Using ip: and port: 8090 for device: DEVICE_ADDRESS
8:22:32 PM: debug Executing 'sendEthernet' off
8:22:32 PM: debug Sending 'off'
(Dan) #2925

Hmmmm… I don’t have an ESP32 version of the very old “On/Off” demo sketch in my repository? Did you write your own?

What is your goal? Most users start with the ST_Anything_Multiples_ESP32WiFi.ino sketch as a starting point. This sketch is designed to work with the ST_Anything Groovy Device Type Handlers.

The On/Off Sketches, and their corresponding DTH, are simply a very basic example that emulates the old example sketch for now-obsolete SmartThings ThingShield. This can be a useful starting point for someone that wants to role their own sketch from scratch and not use the rest of ST_Anything.


I was planning on using it to trigger a stepper motor to run for about 10 seconds when “ON” then run 10 seconds in the other direction when “OFF”

I will take a look at the multiples example and see if I can get that working


(Dan) #2927

If a servo motor would work for your application, there is already support for those built into the library using the EX_Servo class.


i don’t think it will, i need multiple revolutions, and as I understand it the servo class is only 180 correct?

(Dan) #2929

That is correct. Are you an Arduino programmer? If so, you could possibly use the EX_Servo class files as an example for adding a stepper motor device class.