[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

Good idea I’ll see what I can do

Ok, wiped all libraries on my LINUX laptop. Added only your libraries and sketches.

same problem as before.

error also reads candidate expects 1 argument, 8 provided

Yes ST doesn’t have a sensor capability to use distance as an attribute. Here is the current updated list of capabilities https://smartthings.developer.samsung.com/develop/api-ref/capabilities.html

Your recommendation of mounting a distance sensor on the ceiling to check if there is a parked car can be achieved, either you can modify the device handler to be a contact sensor like @ogiewon mentioned or you can modify it to be a presence sensor.

To make it a presence sensor change the DH to take the distance reading from the sensor and then trigger presence active if the distance measured is around height from floor to ceiling minus car height. Remember that the presence sensor is not tied to a car but a immovable spot. So all your automations and smart home monitor configurations will have to account for that.

Thanks for the input @Saif76. It is much appreciated.
I will mess up the DTH without a doubt if I try to do this, but Dan has kindly offered to look into the possibility of changing the DTH.

Would it not be easier to give the DTH a “range trigger” (which should be less than the distance between the sensor and the floor) and if the distance reported by the sensor is less than the pre-set range trigger, the presence sensor should report a positive result? E.g., if the distance between the sensor and floor is 8ft, one would set the range trigger to 7ft e.g. That way, regardless of the height of the vehicle, it will trigger the sensor to “present” if any vehicle/object higher than 1ft is parked below the sensor.

Why is that Dan? The reason I’m asking is that if we could expose the distance measurement to webCoRE, it could be used to set off an alarm if (when used as a water level sensor) the water level drops below a certain level. If used as a “Car in Garage” sensor, webCore could be set up to regard the Car as being in the Garage if the distance reported by the sensor, is less than the distance between the sensor and the floor. I don’t know how the distance will be reported to webCoRE if this is possible, but if e.g. it is reported in millimetres (or inches), would it not be a simple "IF the distance reported by Garage Sensor 1 is less than 400mm, then regard the garage as occupied."
The same DTH and sketch could then be used for multiple applications without making any changes to it e.g. our existing application of a Water level sensor; Car-in-Garage Sensor (If object is closer than x distance); Check if a Door or gate is open; Report of a closet door/electrical distribution box is opened; check if drapes are open/closed; Report if someone walks past the sensor; etc. (all depending on the free space allowed between the sensor and the obstacle it senses, i.e. the closest distance an object may get to the sensor, or the reverse, if the distance increases beyond a pre-set distance reported by the sensor and as set up in webCore)
Am I making sense?

Yes, you’re making sense, however it doesn’t really fit well into any of the existing, implemented, standard ST Capabilities. There is no 'Distance Measurement" Capability currently. The closest thing to it would probably the “Voltage Measurement” capability. That provides a raw floating point value, but when you look at the device in your ST App, you will see a voltage display, not a “Present” or “Away” status. Most people want to look at the device and know more than just a raw numeric value with no context as to what it means. We could expose both, the “Presence Sensor” and “Voltage Measurement” capabilities to a new Child Ultrasonic DH. In the Device Settings, you would configure the threshold for “Away” vs “Present”. I still think it would be much simpler to build a webCoRE rule off of the “Presence Sensor” capability vs the raw value. You always have to go into the webCoRE rule to change the threshold instead of just tweaking the device’s settings.

I’ve got a bit of a busy schedule for the next few days, so no promises on how quickly I can get to this.

I really don’t know what to tell you at this point. Have you tried using a Windows PC to run the Arduino IDE on? Perhaps the Linux OS’s case sensitive file naming is causing an issue? Just a guess. If so, let me know if any of the code needs to have any of the #include<> statements modified to account for a case-sensitive operating system.

My first setup was on a windows 10 pc and my second was on my Linux laptop. Both gave same error, very strange. I completely removed all Arduino from Linux laptop.
Oh well I’ll keep plugging away. Thanks for your help. Big fan of your work too.

1 Like

Beggers can’t be choosers! I’ve said it many times, but I seriously appreciate your assistance. Without that, I would have been nowhere.

So I was able to get the sensor working. Seems the LUX is very low especially if compared to another LUX sensor. I am showing readings of 0 and 5. When I shine a 800 lumen flashlight directly at the sensor it shoots up to 550. Curious if there is anything else I need to modify to get better readings. Suggestions?

Hi Dan, hope you are doing well.
I have now the lights of my entire house been controlled by 4 arduinos mega, with about 16 relay and 20 buttons for each arduino. (All wired up)
Everything works well most of the time… But time to time (probably every 10 to 30 minutes or so) the arduino stuck for a few seconds and than comes back again. So it becomes irresponsive during this time… And some times I have to reset the arduino to get it back.
I believe this may have something to do with the communication with the hub, or maybe with the Internet. It seams the loop is interrupt for some reason.
Do you have any idea how could I find the problem? Or have some suggestions?
Keep in mind you are talking to a “cave man” in therms of programming. so I don’t have any idea how most of your code works… Lol

Thank you very much Dan!

Every 5 mins, by default, ST_Anything refreshes all of the device statuses to ST. If you look in Constants.h (found in the ST_Anything library) you’ll find a couple of lines of code specifying how frequently this update is performed, and whether or not you want theses regular updates.

Try disabling this feature, as this keeps the Arduino busy for a while if you have a large number of devices defined. During this time, the system will be slow to respond.

The reason for this periodic refresh is to make sure ST always is kept up to date. It is not required, but you may end up with situations where ST and the Arduino could be out of sync.

Hi, I’m fairly new to smartthings but have had a little bit experience with raspberry pi arduino and esp8266. I have managed (reading and reading again) to get my nodemcu 12e flashed and working with the multiple flash. As I understand github doesn’t integrate in the UK so I copied the raw code in for child devices. I would like to use 4 DS18B20 temp sensors which are currently on a raspberry pi via speakthings mqtt. I take it I need to edit the sketch. On raspi I can bring all the data form 4 sensors into 1 pin. Do I need to use 4 pins and what about the 4k7 resistor do i use 4?. I would also like to use a couple of door contacts, do I set them to go high or low. If there is any documentation around about this I would love to read it. I would like to thank Daniel for the hours of work put into this project.
Regards Ray

I don’t currently have mine plugged in but I probably could test this weekend. I do remember indoor lighting being pretty low and when the Sun came out it shot up like it did with your flashlight. But 0 - 5 for ambient light seems really low.

I thought I put some debug lines into the code so if you are using serial monitor you’ll see the raw values being passed from the sensor. I’m not doing any kind of conversions or anything else on the data, literally making a call for the raw data and passing it to your hub. So if what shows up in serial monitor is what is showing in the device Handler then that is the data being passed from that sensor. Whether the sensor is correct or not I can’t tell you.


The DS18B20 support allows for multiple sensors on a single pin. The last argument in the constructor is the number of sensors that the software should expect to find. If this value is greater than 1, the first argument should be “temperature” as the numeric suffix will be added automatically by the software. If the last argument is equal to 1, the first argument should be “temperature1”. Wiring should be the same as for the raspberry pi, similar to the image below (ignore the 5V Vdd, as your ESP8266 will be 3.3V. do not connect the DS18B20 to a 5v supply if using a 3.3v board like the ESP8266!)


As for contact sensors (magnetic reed switches), those are easy. Just connect one wire to GND on the ESP8266, and the other to the corresponding PIN defined in the sketch for each sensor. In the example below, the internal pull-up resistor feature is enabled, which will supply 3.3v on each pin.

Here is a sketch that should meet your needs - I have not compiled or tested it, but it should be fine.

//  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_CONTACT_1             D1  //SmartThings Capabilty "Contact Sensor"
#define PIN_CONTACT_2             D2  //SmartThings Capabilty "Contact Sensor"
#define PIN_CONTACT_3             D5  //SmartThings Capabilty "Contact Sensor"
#define PIN_CONTACT_4             D6  //SmartThings Capabilty "Contact Sensor"
#define PIN_TEMPERATURE_1         D7  //SmartThings Capabilty "Temperature Measurement" (Dallas Semiconductor DS18B20)

//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
//			  st::PS_DS18B20_Temperature() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - if only 1 sensor, use "temperature1", if multiple use "temperature" as the number will be added automatically
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used for the One-Wire DS18B20 sensor conenction
//				- bool In_C - OPTIONAL - true = Report Celsius, false = Report Farenheit (Farentheit is the default)
//				- byte resolution - OPTIONAL - DS18B20 sensor resolution in bits.  9, 10, 11, or 12.  Defaults to 10 for decent accuracy and performance
//				- byte num_sensors - OPTIONAL - number of OneWire DS18B20 sensors attached to OneWire bus - Defaults to 1

  static st::PS_DS18B20_Temperature sensor1(F("temperature"), 15, 0, PIN_TEMPERATURE_1, false, 10, 4); 
  //Interrupt Sensors 
//			  st::IS_Contact() 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 input
//				- bool iState - REQUIRED - LOW or HIGH - determines which value indicates the interrupt is true
//				- bool internalPullup - OPTIONAL - true == INTERNAL_PULLUP
//				- long numReqCounts - OPTIONAL - number of counts before changing state of input (prevent false alarms)
  static st::IS_Contact             sensor2(F("contact1"), PIN_CONTACT_1, LOW, true);
  static st::IS_Contact             sensor3(F("contact2"), PIN_CONTACT_2, LOW, true);
  static st::IS_Contact             sensor4(F("contact3"), PIN_CONTACT_3, LOW, true);
  static st::IS_Contact             sensor5(F("contact4"), PIN_CONTACT_4, LOW, true);

  //Special sensors/executors (uses portions of both polling and executor classes)
  //  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"

Hi Dan
Thanks for the very prompt and detailed reply, I will try this asap. Within smartthings do i need to delete the existing parent and reset everything or can I just delete the children?
Regards Ray

Have you thought about using a sensor like this:

Depending on the layout of your garage and how comfortable you are with wiring this could be a lot more practical and dependable than a presence sensor. You might also look into a pressure pad that could go under your tire.

1 Like


Yes, if you’re using the exact same ESP8266, it is best to simply delete the parent device using the ST App on your phone. Doing so will delete the child devices. Then simply recreate the parent. It’s annoying, I know. Something changed on the ST Cloud Backend that has resulted in problems if you just delete a child. I tried for days to fix the issue, but no luck.


Hi Dan
Fantastic, all 4 contacts work and all 4 temps work off the same pins. I deleted the parent after the flash and they all came up. However I got an extra duplicate of temp 4 showing 0 degrees, so I deleted it, and as you wrote it broke the parent. (i’m getting quick at putting the parent back now!). Things are working very sweet just tried the simple logger smart app and it recording values to google sheets, neat! Question: I cant find any way to automate the temps, to say turn a switch on when a certain temperature is reached. Is this possible?
Thanks for all your time and support.
Regards Ray

I would recommend you look into webCoRE, as it is a very powerful Rules Engine for SmartThings. If it can be automated, webCoRE can do it.

1 Like