[RELEASE] ST_Anything - Arduino/ESP8266/ESP32

DAN, You are a lifesaver, like always! Thanks a lot!
Once I deleted the child devices, they recreated and seems to be working now.
The status is not updating right away, it takes 10-20 seconds, I guess it is the new app issue.
Do you think the "migration procedure should be documented in the post’s top?

1 Like

First off, I would like to thank Dan for developing this, and for spending so much of his time supporting it.

I was able to get it working on an ESP8266 (WeMos D1 R2), and am using it to read a contact, and control a 4 channel relay board. I ran into some obstacles along the way, mainly slow response and timeouts. I was able to overcome those by scanning through this thread, and the solution was to reboot my V2 hub, which I would not have thought to do.

My question is about the ultrasonic sensor capability. Looking at the code, it looks like it was meant to measure the volume of a liquid remaining in a cylindrical tank?

My intended use is to measure the amount of salt in my water softener, so it probably would not require me to modify much to get that functionality (the tank is rectangular rather than cylindrical). I have no experience with Groovy or the ST API, but it doesn’t look too difficult as long as I’m starting with something that already works as an example.

Thanks again!

1 Like

Correct, the Groover Driver code was actually written by a ST Community Member years ago. As with all of ST_Anything, please feel free to tweak it as you see fit for your specific use-case. As you mention, the math is pretty simple in that driver and should be fairly straightforward to change.

Thanks for the reply. It was fairly straightforward to get it working. It is now online and sending its current capacity % to SmartThings.

If I click on the child sensor in the app however, nothing shows up (no values, graphics, etc.). Digging around I get the feeling that the “Tile” functionality in those drivers is no longer applicable in the new app? I can see that it sending data across in the live log via some debug statements I added.

In any case, I can live with how it is working if need be. I can still use the capacity it sends across to trigger notifications when the salt gets low. It would just be nice to look at it and see a nice graphic displaying the % capacity.

Thanks again for your help!

1 Like

Yep, this makes sense as that DTH currently uses a custom capability. I have no plans to implement custom capabilities in the new ST App.

You could further modify your copy of the DTH to implement a standard capability, like Humidity. Since you’re sending a percentage anyway, using the Humidity Capability would at least match the correct units.

1 Like

Thanks! That is a good idea. I will probably give it a shot and see what happens.

I looked into the custom capability and it looks far more complicated than it needs to be. Maybe some day I’ll dig into it.

I am very impressed with this package. Kudos to the daniels! I hadn’t used my Arduinos in a while but working with this Instructable (https://www.instructables.com/ESP8266ESP-12-Arduino-Powered-SmartThings-DS18B20-/) I was able to get up and running easily. Now I need to make it do something that I want but that is the fun part.

Trying to configure a switch using st::EX_Switch executor2. Everything compiles and loads correctly. The device switch1 show up in SmartThings. as a switch but when I click on tthe on button to turn it on, I get a “Network or server error occurred. Try again later.” It is probably something easy but I can’t seem to figure it out. I can post the sketch if needed but it just the original sketch for a temperature sensor with the few changes for a switch

SO thinking that I might have mangled the editing of the original file to add the switch, I downloaded the sketch ST_Anything_Relays_ESP8266, editted the required lines. It complied and loaded correctly and the devices showed up in SmartThings. From SmartThings, if I press the button for the switch, I get a netowrk or server error. Perhaps this is related to using the new SmartThings App?

Have you filled in all of the Parent Device’s Settings correctly? For some users, it is simpler to edit those settings using the ST Web IDE. I just verified that everything is working fine for me still in the New ST App. I am using a ST v2 Hub and a NodeMCU ESP8266, running the ST_Anything_Multiples_ESP8266WiFi.ino example sketch.

Without seeing your sketch (please remove your WiFi credentials for privacy/security reasons) and a screenshot of your parent device in the ST Web IDE, it is very difficult to assist in troubleshooting.

One quick thing you can try is to pull the power on your ST Hub (and remove batteries if a v2 hub) to fully reboot your hub. This has helped other users to get data flowing properly.

Here is the sketch and the parent device setting from the ST IDE. For some reason, I couldn’t figur eout how to past the sketch as a block of code. This was the origianl sketch I was working with that has a single relay output. It show up correctly in SmartThings but if I try to toggle it on, I get a netowrk or server error. I am just going upstairs to power cycle the ST Hub. An earlier sketch (reading temperature) seemed to work as expected. I am also running a ST v2 Hub and a NodeMCU ESP8266.
I very much appreciate your help.

// 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
// 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 <EX_Switch.h> //Implements an Executor (EX) via a digital output to a relay

//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_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 D3 //SmartThings Capabilty “Temperature Measurement” (Dallas Semiconductor DS18B20)
//#define PIN_TIMEDRELAY_1 D8 //SmartThings Capability “Relay Switch”

//ESP8266 WiFi Information
IPAddress ip(192, 168, 1, 21); // 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, 226); // smartthings hub ip // <—You must edit this line!
const unsigned int hubPort = 39500; // smartthings 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_DS18B20_Temperature 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
// st::Everything::addSensor(&sensor1);
// st::Everything::addSensor(&sensor2);
// st::Everything::addSensor(&sensor3);
// st::Everything::addSensor(&sensor4);
// st::Everything::addSensor(&sensor5);
// st::Everything::addSensor(&sensor6);
// st::Everything::addSensor(&sensor7);
// st::Everything::addSensor(&sensor8);

//Add each executor to the “Everything” Class
// st::Everything::addExecutor(&executor1);

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

Please show the Parent Device datils page in the Web IDE. You’ve shown the EDIT page which does not show all of the details for the User Preferences (Arduino IP address, Arduino MAC Address, Arduino Port)

I could be wrong but seems like you’re missing this - Uncomment (//#define D1 5)

Not typically necessary if the correct board type is selected in the Arduino IDE when building the code. Also, that would throw a compiler error, not a runtime issue.

1 Like

I see the problem - you entered the IP address of your ST hub in the Parent Setting for the Arduino IP address. It should be, not .226.

Knew it had to be something simple since the instructions I was following were quite clear. Thank you for the help!!! And thank you and everyone involved again for ST_Anything! At this point, I am sort of committed to the SmartThings ecosystem so this seems to offers a great solution for expanding the system.

In reading through the discussion, there were some comments wrt “safety”. I think is was wrt a AC relay, Are there any concerns about using this device?

PS What is the correct way to post code. I can seem to get the <> to mark the pasted text as a block of code.

I guess the whole ST_Anything ecosystem will die sometime in 2021 once Samsung kills groovy and DTH integrations/customization.
Am I wrong?

That seems likely, but who knows what will happen in the future? :man_shrugging:

However, ST_Anything works great with Hubitat, where it is called HubDuino! ALways nioce to have options! :wink:

I have a small but annoying issue - after flashing new code to my device and updating DTHs, my motion sensor has a delay about 9-12 seconds before activation of the light. it was not like this before the update.
The logs show that the sensor sends and light receives an activation signal at the same time.
Is there something that was added to make IS_Motion library behave like this?