[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Sorry, there’s a tutorial at the top of the thread. I am not going to re-hash what is already posted. Try reading through some of the 2400 posts on this thread. You’ll find your answer, I promise.

#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 
//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 PIN_TEMPERATURE_1         13  //SmartThings Capabilty "Temperature Measurement" (Dallas Semiconductor DS18B20)
#include <Wire.h> //add cld
#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display

//ESP8266 WiFi Information
String str_ssid     = "";                           //  <---You must edit this line!
String str_password = "";                   //  <---You must edit this line!
IPAddress ip(192, 168, 1, 170);       //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, 127);    // 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()
  static st::PS_DS18B20_Temperature sensor2(F("temperature1"), 15, 0, PIN_TEMPERATURE_1, false, 10, 1);

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

  //Initialize each of the devices which were added to the Everything Class
  int error;
  Wire.beginTransmission(0x27); //Your LCD Address
  lcd.begin(16, 2);
  lcd.print("Netwrok ");
  lcd.setCursor(0, 1);
  lcd.print("IP ");
//  lcd.print(F("MAC "));
//  String strMAC(WiFi.macAddress());
//  strMAC.replace(":", "");
//  lcd.println(strMAC);
//  delay(5000);
  lcd.setCursor(0, 1);

ware do add Motion code?

Ahhhh, @bob5731 is back! :slight_smile:

Bob - literally EVERY one of my example 'ST_Anything_Multiples…" sketches includes an example of using a motion detector device. Just take a look at the ST_Anything_Multiples_ESP8266WiFi.ino sketch as a starting point. Your sketch does not #include some of the libraries needed to use the IS_Motion device. You’ll need to make sure you add those lines to your sketch as well. In fact, the more I look at it, the sketch you posted is actually missing quite a few required sections of code. Just start with the example sketch and modify from there. For LCD additions, I offer no support. Other users have successfully added LCD screens. You’ll need to search through the ST_Anything threads here in the community for examples of those.

Good Luck and Happy Holidays!

1 Like


Thanks for helping me to get my Arduino Mega working with ST_Anything a while back. I’m using it to monitor all the existing contact wires on my built-in alarm system. After I installed it, I tested that all the doors and windows were being reported to SmartThings.

Today, I opened a window and noticed that it wasn’t reported as open to SmartThings! After checking wiring and voltages were okay, I finally reset the Arduino and everything went back to normal and window reported as open.

My question is, how would you suggest monitoring that the Arduino is running ST_Anything correctly?

I would have never known my Arduino needed to be reset if I hadn’t opened a window and noticed it wasn’t being reported to ST.

Fortunately, we’re still using our built-in alarm system and we weren’t relying on the Smart Home Monitor.

Perhaps some sort of virtual watchdog device which sends a text or notification if it’s not updated by ST_Anything for an hour?

You should be able to create a webCoRE piston to monitor your devices and then send a text message if their values don’t change. I don’t use webCoRE, but there is a forum dedicated to its use. I’m sure someone could help you create a quick piston if you’re not a webCoRE user.

This is the app I use for that. Worked every time one of my ST_Anything boards got locked up for some reason.

1 Like


I’ll take a look at webCore and Device Monitor.


I have a project where most of the processing is done locally in the ESP. I just noticed that when the Smartthings hub goes offline everything stops working. As soon as the hub comes back online everything starts working again. Just as if it got paused.
Is it possible to make the local code work independently of Smartthings?

Seems like the loop didn’t stop, it just slowed down a lot. Can it be that there is a delay since the sketch is unable to send data to Smartthings?
Is there any way to know if the smartthings hub is out of reach?

Hmmmm… it kind of depends on how you’ve implemented local processing with the ESP’s sketch…and exactly how ST_Anything reacts when ST goes offline. Since ST_Anything only communicates with the ST hub, I wouldn’t think that communications would block when the ST Cloud is offline (but it may!)

There’s really nothing I can think of to do about problems with the ST infrastructure. I can tell you that I’ve been running for about 11 months on Hubitat with very good reliability and all local processing.

I just got the new Google hub. When I link my St devices, it must be the new software version. All my stanything devices are broken. They still work in the classic app. Is there anyway to get them working?


Just use the Classic SmartThings App. The new SmartThings app is only necessary to perform th einitial v3 Hub registration. Afterwards, you can just continue to use the Classic App like most users.

Samsung has not released any documentation on how to develop Device Handlers for the LAN connected devices using the new SmartThings App and Architecture. Therefore, users running custom code need to continue to use the Classic App.

Hi All,
Does anyone have a write-up or code for using the ST_Anything w/Node for reading Photo Sensors? I want to check the light levels in different areas and need a little help.

FYI, Im not sure how the structure of using and calling the library so thats what I need a little help with that.


When you say photo sensor do you mean lum sensors? Or like camera sensors?

Why do you need to use Node? Why not just read each of the lum sensors directly from your board into ST?

Hi Ryan,
When I say photosensor, I mean photoresistor. Its to measure light levels. I have a complex set of photoresistors to measure the location of a oil tank gauge float. I calculate the location using that array then output the location (right now to a serial monitor) as a string “FULL”, “3/4”, “1/2”, “1/4”, “EMPTY” I’m integrating this with NODE due to the calculations needed.

Thanks for responding!

As I read more, it may seem that ST_Anything only works with certain device types and cannot handle sending String statements? There may be a work around but I need to research more on how the integration works…

I’m sorry, I’m not following you. Sending string statements to ST or to your ESP8266?

No, what Im trying to do, ultimately, is to monitor (with my phone) the level of my oil tank. This done by sending a string or some kind of data that the ST App can translate or display

ST_Anything sends and receives strings, typically as name/value pairs, to the ST Hub.

Most people monitoring tank levels use an ultrasonic sensor to measure the distance from the top of the tank to the surface of the liquid.

If you’d like to use photoresistors, I would recommend connecting them in series (or possibly parallel) to a single analog input pin on an ESP8266 to see if you can discern the various tank levels.

Or, you can use an ESP32 which allows for many analog sensors to be connected independently to multiple pins.

You can then simply write some logic to perform the necessary math and send the data to ST. There is really no need for a NodeJS server, unless I am misunderstanding your requirements.

Let me know if you have any questions about my ST_Anything… or SmartThings… libraries.

Hi Dan,

I am using a NodeMCU to read a set of Parallel PhotoResistors. I have the sketch running great in Arduino however now it’s time to integrate the hardware into my smart home. The question is, how do I send my data, either the string or whatever is needed, to the ST system for ultimate display on my iPhone?

Is there a good way of displaying string data such as “FULL” or “EMPTY” to the ST App?


Ahhh… Now I understand a little better. Sounds like you might be somewhat new to custom Device Handlers in SmartThings? Correct?

SmartThings uses something known a CAPABILITIES to determine the behavior of a device. Msst users want to incorporate devices that follow these standard capabilties, like Temperature, Motion, Humidity, Presence, etc… This is why ST_Anything tries to implement these standard capabilities using low cost devices, like PIR sensors, DS18B20 sensors, DHT22 sensors, etc…

You really want a more custom solution… Please know that all Custom Device Handlers and SmartApps run in the cloud, not on the local hub. Also, you must use the ST Classic mobile phone app, not the newer one as it does not support custom devices like you are proposing.

In your case, I would simply recommend you take a look at my “SmartThings…” set of libraries. These perform all of the Arduino Sketch to SmartThings hub communications. They are also used by ST_Anything internally.

You’ll need to download ALL of the “SmartThings…” libraries and add them to your …\Arduino\libraries folder. Then take a look a the example sketches and the groovy device handlers in the \Smarthings\examples and \SmartThings\extras folders. This should get you started at adding ST connectivity to your existing sketch.

You can use a Value Tile in your ST custom Device Handler to display any text sent from the arduino sketch to the hub.

This is a link to the main SmartThings Arduino library. Be sure to grab the others as well. This one has the sample sketches and groovy code used by all of these communications libraries.

Hope this helps get you started on your journey! Have fun and feel free to reach out if you get stuck along the way.

1 Like