[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

The bench testing seems to work great - the only hiccup is when I press the tile in ST - the first on pulse seems to last a few seconds before it begins the timed pulses at 0.5 secs. Seems like it is the connection/transmit time between ST and the ESP8266 - once the connection is made it works as expected, for subsequent tile pushes. Thanks for the advice!!

1 Like

I created an additional variable (flow) in my sketch that I used to be able to see in the history of the parent device. Its an irrigation control with 8 relays and a flow meter counting pulses from a hall sensor. In logs, I can see the variable show up as “Parsing: flow 191”. Is there a way to view this in the SmartThings app or create a child device that shows the value?

Sure… What you’ll need to do is change the text that you’re sending from the sketch to ST from “flow 191” to one of the supported names, like “voltage1 191” (the numeric “1” as a name suffix is required!) This will cause the parent device to create a Child Voltage device and update its value to “191”. Another suitable option would be to use the Child Power device, which means you would have the sketch send “power1 191”.

Play around with the various numeric child devices to see what works best for your needs. Unfortunately, using custom attributes is much more difficult then it used to be back in the ST Classic App days.

1 Like

Hi @ogiewon , thanks for all your work for St_anything

Im pretty sure this platform is the best for me to do what im looking for. Ive seen few post up there that are very close from what i want to know but i dont have big skills into this !

Im using some Lolin Node MCU v3 Esp8266 with a esp-12e chip , my goal is to monitor battery voltage using A0 analog port 0-3.3v that i can scale to 12vdc .

I want to monitor a 12v deep cycle battery in my trailer that is solar charged into smartthings

I have looked to the Multiples_esp8266 WIFI into the library but it doesn’t seems to include any analog input support for voltage monitoring,

is there a way to do it ?

Thanks for your support !!

1 Like

I dunno how I did that , because I’m a very beginner at all this , but ive been able to modify the code by doing some copy paste from other device handlers that you made , and doing some tweaks… but ive been able to have a voltage child app created and working with my Node Mcu V3.0. Now i need to buy some resistors and scale this thing out .

1 Like

@dsrq - Great work! Glad you were able to figure out how to add the PS_Voltage device to a sketch and get it working.

Can you share your code examples? Was looking for something very similar.

@EdHayes3 - If you explain your requirements, I’d be happy to help guide you through the process of configuring an ST_Anything Arduino sketch.

Is it possible to use this library to read the status of other devices in smartthings (i.e. a light switch)

Not really directly possible, without some workarounds.

Can you please explain exactly why you’d like to do this?

I would like to make some motorized blinds but don’t have easy access to power for the window so I was hoping to make it battery/solar powered, but that would require using the sleep function of the ESP8266. So I was thinking if I could create a virtual switch to be a place holder for the state of the blinds, then when the ESP8266 would wake up and check the status of that virtual switch and either open or close the blinds based on the status of the virtual switch.

Interesting idea… :thinking: Unfortunately, ST_Anything is not designed where the microcontroller can request a data update from SmartThings. It is definitely something that you could add if you wanted to, though.

Upon wake-up, have the microcontroller send a command to the Parent device. It would need to be unique, something like “request Refresh”. Then, have the Parent device intercept this message and somehow request the child devices issue their last command again. Make sure the microcontroller stays awake long enough to receive the command.

The parent/child devices you mention are these ST_Anything devices, I want to get the states from other devices in my smartthings hub.

I am thinking I may need to create a smartapp to allow access to the devices in my smartthings hub?

Ideally I would have the 8266 send a POST/GET request to a URL and it would return the state of a specified device

Yes, I was referring to ST_Anything parent/child devices.

Based on what you’re trying to accomplish, you might want to skip ST_Anything and instead, look at using one of the newer ST API’s to directly communicate with the ST Cloud.

1 Like

turned out to be easier than i thought.

just had to create a token at SmartThings. Add a little smartness to your things.

then sent this GET request to the below address with bearer token authentication to get list of device ids

once you have a device id you want then you GET request to the following to get status

thanks for the help!


Not sure if anyone else has this issue, but I’m controlling an RGB strip for Christmas lights and everything works great - as long as I’m controlling it from the Device Handler simulator on the SmartthingsIDE. For some reason on my mobile device the parent and child both say they are connected, but the controls themselves are replaced by clouds with a slash through them. When I refresh (by pull down) I can see the controls, but they’re a bit different than the rgbSwitch device handler on the simulator. And they immediately disappear and are replaced by clouds quickly after that. Any thoughts?

Hi, Could someone please help as I’m not good with Arduino…
So I’m trying to set Wemos D1 Mini with DHT22 pin D1 and HC-SR501 pin D5.
Below is my code but i keep getting errors and not sure how to proceed

// 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 <PS_TemperatureHumidity.h>
//#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 <IS_Motion.h>
//#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_WATER_1 A0 //NodeMCU ESP8266 only has one Analog Input Pin ‘A0’

//#define PIN_ALARM_1 D0 //SmartThings Capabilty “Alarm”
//#define PIN_SWITCH_1 D1 //SmartThings Capability “Switch”
//#define PIN_CONTACT_1 D2 //SmartThings Capabilty “Contact Sensor”
//#define PIN_BUTTON_1 D3 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_BUTTON_2 D4 //SmartThings Capabilty Button / Holdable Button (Normally Open!)
//#define PIN_MOTION_1 D5 //SmartThings Capabilty “Motion Sensor” (HC-SR501 PIR Sensor)
//#define PIN_SMOKE_1 D6 //SmartThings Capabilty “Smoke Detector”
//#define PIN_TEMPERATURE_1 D7 //SmartThings Capabilty “Temperature Measurement” (Dallas Semiconductor DS18B20)
//#define PIN_TIMEDRELAY_1 D8 //SmartThings Capability “Relay Switch”

//ESP8266 WiFi Information
String str_ssid = “GTL5G”; // <—You must edit this line!
String str_password = “Internet1”; // <—You must edit this line!
IPAddress ip(192, 168, 1, 154); //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

// Smarthings Hub Information
IPAddress hubIp(192, 168, 1, 105); // 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 = "));
// 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
// static st::PS_Water sensor1(F(“water1”), 60, 20, PIN_WATER_1, 200);
static st::PS_TemperatureHumidity.h sensor2(F(“temperature1”), 15, 0, PIN_TEMPERATURE_1, false, 10, 1);

//Interrupt Sensors
static st::IS_Contact sensor3(F(“contact1”), PIN_CONTACT_1, LOW, true);
static st::IS_Button sensor4(F(“button1”), PIN_BUTTON_1, 1000, LOW, true, 500);
static st::IS_Button sensor5(F(“button2”), PIN_BUTTON_2, 1000, LOW, true, 500);
static st::IS_Motion sensor6(F(“motion1”), PIN_MOTION_1, HIGH, false);
static st::IS_Smoke sensor7(F(“smoke1”), PIN_SMOKE_1, HIGH, true, 500);

//Special sensors/executors (uses portions of both polling and executor classes)
static st::S_TimedRelay sensor8(F(“relaySwitch1”), PIN_TIMEDRELAY_1, LOW, false, 3000, 0, 1);

static st::EX_Alarm executor1(F(“alarm1”), PIN_ALARM_1, LOW, true);
static st::EX_Switch executor2(F(“switch1”), PIN_SWITCH_1, 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

//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

//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”

I previously had ST_Anything working correctly on an ESP32 Dev Board.
After switching to a new WiFi SSID, I tried to do everything again from scratch (as I no longer had the IDE or Sketch) but now am only getting errors on compile:

Arduino: 1.8.15 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None"

C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\ST_Anything\Everything.cpp: In static member function 'static bool st::Everything::sendSmartStringNow(const String&)':

C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\ST_Anything\Everything.cpp:269:2: warning: no return statement in function returning non-void [-Wreturn-type]



In file included from C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\OneWire.cpp:144:

C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h: In function 'void directModeInput(uint32_t)':

C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:141:26: error: 'rtc_gpio_desc' was not declared in this scope

         uint32_t rtc_reg(rtc_gpio_desc[pin].reg);


C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:141:26: note: suggested alternative: 'rtc_io_desc'

         uint32_t rtc_reg(rtc_gpio_desc[pin].reg);



C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h: In function 'void directModeOutput(uint32_t)':

C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:169:26: error: 'rtc_gpio_desc' was not declared in this scope

         uint32_t rtc_reg(rtc_gpio_desc[pin].reg);


C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\OneWire\util/OneWire_direct_gpio.h:169:26: note: suggested alternative: 'rtc_io_desc'

         uint32_t rtc_reg(rtc_gpio_desc[pin].reg);



Multiple libraries were found for "WiFi.h"

 Used: C:\Users\rcarm\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi

 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi

 Not used: C:\Users\rcarm\OneDrive\Documents\Arduino\libraries\WiFiNINA

exit status 1

Error compiling for board ESP32 Dev Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any ideas on how I can get this up and running again?
Sincere regards,

Probably a little late for this but are you still having this issue? And are you sure your device handler is up to date (IDE → Device Handlers)

Did you also install Arduino fresh? Make sure it’s up to date and that you downloaded a fresh copy of the ST_anything libraries and extracted them to the correct place. It seems to be having a issue finding stuff.

It doesn’t look like you edited the default file other then for your internet info. You’ll have to put the sensors in that you are using and remove the stuff you are not. Probably want to start with the readme: GitHub - DanielOgorchock/ST_Anything: ST_Anything is an Arduino library, sketch, and Device Type that works with your SmartThings ThingShield to create an all-in-one SmartThings device.

1 Like

Thanks for your reply vseven,
I just tried on a completely different computer with a fresh install of the Arduino IDE, ESP32, and ST_Anything drivers but the result is the exact same. Any ideas?

On another note, if I am running 2 “SmartThings Wifi” units ( & .3), connected to my Modem (.1), what Gateway, DNS, & HUB Address do i use?