[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Hi Ryan,

Thanks for the pointer. Now I have a successful implementation of mclighting. I am now working on custom animations corresponding to the water level detected. When I finish, I will post the details. BTW I am planning to get this via RESTful API . Me no programmer but still trying to learn.

Thanks .

Thanks for the heads up on the corrosion. I guess that is to be expected to a certain extent, considering where it is being used.

Noob Question here:

I have a MEGA256 with a W5100Shield. I am usint the ST_Anything sketch for a W5100 as my base. In the setup for the 5100 it reserves pins 50 - 53 Even tho they are not physically used on the shield, Is it true that I cannot use them for other things, like an input from a sensor?

Thanks

Probably asked a thousand times


I rewrote my sketch and uploaded it to my Arduino. How do I update SmartThings to reflect all the changes, or does it do that automatically and it just takes awhile?

Thanks

Take a look at the following. You’ll see where those pins are reserved for use by the Arduino Ethernet library/shield.

The best way is to delete the Parent Device (not the groovy Device Handlers!) and then manually add it back in. Doing so, assuming the Arduino is online, all of the child devices will be recreated based on what you’ve defined in the sketch.

Unfortunately, manually deleting child devices seems to lock up all communications. It used to work, but something on the ST back end changed over a year ago.

You can add additional devices to you sketch, and new children will be created. But trying to delete child devices on the ST side is what triggers the issue.

Great, Thanks!

Looks like I leave those as they are then.

Thanks

Hi!
I’m stuck at the point where I’m supposed to press the little gear icon in SmartThings Classic. It says “Something’s wrong We can’t load your screen right now”

Any idea what I did wrong?
-Dave

Are you using the SmartThings Classic App? If yes, are you sure you have the current Parent Device Handler groovy code saved and published in your account? When you manually added the parent device via the WEB IDE, did you select the Location and Hub in their respective drop-down boxes?

Oh wow I’m sorry! I should have provided much more info off the bat!
I am using the classic app but I’m running it on an S8 so it’s got the newer app as well and I can’t remove it because it’s part of the interface.
The handler was not published but I published it and it still doesn’t work. (same error)
I did select location/hub. It wouldn’t let me add a device without both.

I waited a bit and restarted the app several times after publishing. Still nothing. Any ideas?

I don’t have any other ideas, except to remove the parent device (not the handler) and manually create it again. If necessary, you can fill in all of the required data on the parent device via the web ide. Just be sure to click refresh in the parent on your phone. The refresh command is then sent to the microcontroller, which will then cause the child devices to be created.

You should be able to remove the SmartThings (Samsung Connect) app from your S8. I have an S9 and removed the new app and installed the Classic app.

I have a number of DS18B20 sensors I want to hook up. I know the physical hookup. I have the library installed in my sketch. Do I need to declare a device for it(them) And did I see a modification to the groovy file for multiple devices?

Thanks

In order to use multiple DS18B20 sensors, you need only declare a single PS_DS18B20_Temperature device in your sketch (assuming you are using a single Arduino data pin for all DS18B20 sensors.) In the example below, 4 DS18B20 sensors will be polled (check out the last argument ‘4’ being passed in.) Also, pay attention to the name of the device being passed in as ‘temperature’ without a numeric suffix. This is because the PS_DS18B20_Temperature class automagically appends a 1, 2, 3, and 4 to the name ‘temperature’ based on which particular DS18B20 device it is sending data to ST for.

static st::PS_DS18B20_Temperature sensor2(F("temperature"), 20, 5, PIN_TEMPERATURE_1, false, 10, 4);

Here is the most up to date documentation from the top of the .cpp / .h files for this class.

//			  Create an instance of this class in your sketch's global variable section
//			  For Example:  st::PS_DS18B20_Temperature sensor1(F("temperature1"), 120, 0, PIN_TEMPERATURE, false); (for a single sensor)
//                          st::PS_DS18B20_Temperature sensor1(F("temperature"), 120, 0, PIN_TEMPERATURE, false, 10, 3); (for 3 sensors)
//
//			  st::PS_DS18B20_Temperature() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - either "temperature1" for a single sensor, or "temperature" for multiple sensors
//				- 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

Hi Dan thanks for the sample I have been fussing with this this evening and I copied your example. I do have the library installed. when I compile I get
expected primary-expression before ‘,’ token for the line

static st::PS_DS18B20_Temperature sensor1(F(“temperature”), 20, 5, PIN_TEMPERATURE_1, false, 10, 4);

//Polling Sensors 
static st::PS_DS18B20_Temperature sensor1(F("temperature"), 20, 5, 

PIN_TEMPERATURE_1, false, 10, 4);
//Interrupt Sensors
static st::IS_Contact sensor2(F(“contact1”), PIN_CONTACT_1, LOW,
true, 500);
static st::IS_Contact sensor3(F(“contact2”), PIN_CONTACT_2, LOW,
true, 500);
static st::IS_DoorControl sensor4(F(“doorControl1”),
PIN_DOORCONTROL_CONTACT_1, LOW, true,
PIN_DOORCONTROL_RELAY_1, LOW, true, 1000);
static st::IS_DoorControl sensor5(F(“doorControl2”),
PIN_DOORCONTROL_CONTACT_2, LOW, true,
PIN_DOORCONTROL_RELAY_2, LOW, true, 1000);

What am I missing?

Hmmm


I assume you have

#include <PS_DS18B20_Temperature.h> //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries

in your sketch?

You can post the whole sketch here (or in a PM if your prefer) so I can debug it. Make sure after youpaste it into your message, that you highlight all of the sketch and click the < / > menu option (preformatted text) to make the code readable and easy to copy and paste for me.

Yup I have the included library. I figured out that I didn’t declare the gpio pin 2 in the define portion. After doing that I got it compiled.

//******************************************************************************************
//  File: ST_Anything_Multiples_EthernetW5100.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Edited by Ed Lentz and used in the Lentz Home

//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one Arduino + Ethernet W5100 Shield 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 Ethernet W5100 Shield.
//

//******************************************************************************************
// SmartThings Library for Arduino Ethernet W5100 Shield
//******************************************************************************************
#include <SmartThingsEthernetW5100.h>    //Library to provide API to the SmartThings Ethernet W5100 Shield

//******************************************************************************************
// 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_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_AdafruitBME280_TempHumidPress.h> //Implements a Polling Sensor (PS) to measure Temperature, humidity, and Pressure using BME280 via I2C
//#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector) on an analog input pin 
#include <IS_Contact.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 <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing/cycle repeat capabilities

//**********************************************************************************************************
//Define which Arduino Pins will be used for each device
//  Notes: Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). 
//         This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. 
//         On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. 
//         These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, 
//         is not used to select either the W5100 or the SD card, but it must be kept as an output 
//         or the SPI interface won't work.
//         See https://www.arduino.cc/en/Main/ArduinoEthernetShieldV1 for details on the W5100 Sield
//**********************************************************************************************************
//"RESERVED" pins for W5100 Ethernet Shield - best to avoid
#define PIN_4_RESERVED            4   //reserved by W5100 Shield on both UNO and MEGA
#define PIN_1O_RESERVED           10  //reserved by W5100 Shield on both UNO and MEGA
#define PIN_11_RESERVED           11  //reserved by W5100 Shield on UNO
#define PIN_12_RESERVED           12  //reserved by W5100 Shield on UNO
#define PIN_13_RESERVED           13  //reserved by W5100 Shield on UNO
#define PIN_50_RESERVED           50  //reserved by W5100 Shield on MEGA
#define PIN_51_RESERVED           51  //reserved by W5100 Shield on MEGA
#define PIN_52_RESERVED           52  //reserved by W5100 Shield on MEGA
#define PIN_53_RESERVED           53  //reserved by W5100 Shield on MEGA


//Analog Pins
#define PIN_WATER_1               A0  //SmartThings Capability "Water Sensor"
#define PIN_WATER_2               A1  //SmartThings Capability "Water Sensor"

//Digital Pins
//#define PIN_TEMPERATUREHUMIDITY_1 22  //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"
//#define PIN_TEMPERATUREHUMIDITY_2 23  //SmartThings Capabilities "Temperature Measurement" and "Relative Humidity Measurement"
#define PIN_CONTACT_1             38  //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_2             39  //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_3             40  //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_4             41  //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_5             42  //SmartThings Capability "Contact Sensor"
#define PIN_CONTACT_6             43  //SmartThings Capability "Contact Sensor"


//Relay Outputs
#define PIN_SWITCH_1              22  //SmartThings Capability "Relay 1--Veg Lites"
#define PIN_SWITCH_2              23  //SmartThings Capability "Relay 2--Flower Lites"
#define PIN_SWITCH_3              24  //SmartThings Capability "Relay 3--Pool Pump"
#define PIN_SWITCH_4              25  //SmartThings Capability "Relay 4--Solar Valve"
#define PIN_SWITCH_5              26  //SmartThings Capability "Relay 5--Water Valve"
#define PIN_SWITCH_6              27  //SmartThings Capability "Relay 6"
#define PIN_SWITCH_7              28  //SmartThings Capability "Relay 7"
#define PIN_SWITCH_8              29  //SmartThings Capability "Relay 8"
#define PIN_SWITCH_9              30  //SmartThings Capability "Relay 9"
#define PIN_SWITCH_10             31  //SmartThings Capability "Relay 10"
#define PIN_SWITCH_11             32  //SmartThings Capability "Relay 11"
#define PIN_SWITCH_12             33  //SmartThings Capability "Relay 12"
#define PIN_SWITCH_13             34  //SmartThings Capability "Relay 13"
#define PIN_SWITCH_14             35  //SmartThings Capability "Relay 14"


//Garage Door Pins 
#define PIN_DOORCONTROL_CONTACT_1 44  //SmartThings Capability "Door Sensor North Door" 
#define PIN_DOORCONTROL_RELAY_1   36  //SmartThings Capability "Door Control North Door" 
#define PIN_DOORCONTROL_CONTACT_2 45  //SmartThings Capability "Door Sensor South Door"  
#define PIN_DOORCONTROL_RELAY_2   37  //SmartThings Capability "Door Control South Door" 
#define PIN_TEMPERATURE_1          2//SmartThings Capabilty “Temperature Measurement” (Dallas Semiconductor DS18B20)
//******************************************************************************************
//W5100 Ethernet Shield Information
//****************************************************************************************** 
byte mac[] = {0x06,0x02,0x03,0x04,0x05,0x06}; //MAC address, leave first octet 0x06, change others to be unique //  <---You must edit this line!
IPAddress ip(192, 168, 1, 50);               //Arduino 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, 6);    // 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

//******************************************************************************************
//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 withotu having to rely on the ST Cloud for time-critical tasks.
//******************************************************************************************
void callback(const String &msg)
{
  //Uncomment if it would be desirable to using this function
  //Serial.print(F("ST_Anything_Miltiples 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(s) as you see fit)
  //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_DS18B20_Temperature sensor1(F("temperature"), 20, 5, PIN_TEMPERATURE_1, false, 10, 4);
  //Interrupt Sensors 
  static st::IS_Contact             sensor2(F("contact1"), PIN_CONTACT_1, LOW, true, 500);
  static st::IS_Contact             sensor3(F("contact2"), PIN_CONTACT_2, LOW, true, 500);
  static st::IS_DoorControl         sensor4(F("doorControl1"), PIN_DOORCONTROL_CONTACT_1, LOW, true, PIN_DOORCONTROL_RELAY_1, LOW, true, 1000);
  static st::IS_DoorControl         sensor5(F("doorControl2"), PIN_DOORCONTROL_CONTACT_2, LOW, true, PIN_DOORCONTROL_RELAY_2, LOW, true, 1000);
  
  
  //Executors
  static st::EX_Switch              executor1(F("switch1"), PIN_SWITCH_1, LOW, true);
  static st::EX_Switch              executor2(F("switch2"), PIN_SWITCH_2, LOW, true);
  static st::EX_Switch              executor3(F("switch3"), PIN_SWITCH_3, LOW, true);
  static st::EX_Switch              executor4(F("switch4"), PIN_SWITCH_4, LOW, true);
  static st::EX_Switch              executor5(F("switch5"), PIN_SWITCH_5, LOW, true);
  static st::EX_Switch              executor6(F("switch6"), PIN_SWITCH_6, LOW, true);
  static st::EX_Switch              executor7(F("switch7"), PIN_SWITCH_7, LOW, true);
  static st::EX_Switch              executor8(F("switch8"), PIN_SWITCH_8, LOW, true);
  static st::EX_Switch              executor9(F("switch9"), PIN_SWITCH_9, LOW, true);
  static st::EX_Switch              executor10(F("switch10"), PIN_SWITCH_10, LOW, true);
  static st::EX_Switch              executor11(F("switch11"), PIN_SWITCH_11, LOW, true);
  static st::EX_Switch              executor12(F("switch12"), PIN_SWITCH_12, LOW, true);
  static st::EX_Switch              executor13(F("switch13"), PIN_SWITCH_13, LOW, true);
  static st::EX_Switch              executor14(F("switch14"), PIN_SWITCH_14, LOW, true);
 
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //*****************************************************************************
  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 EthernetW5100 Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsEthernetW5100(mac, 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::SmartThingsEthernetW5100(mac, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes Ethernet communications with the SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //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);
  
  
 


      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addExecutor(&executor1);
  st::Everything::addExecutor(&executor2);
  st::Everything::addExecutor(&executor3);
  st::Everything::addExecutor(&executor4);
  st::Everything::addExecutor(&executor5);
  st::Everything::addExecutor(&executor6);
  st::Everything::addExecutor(&executor7);
  st::Everything::addExecutor(&executor8);
  st::Everything::addExecutor(&executor9);
  st::Everything::addExecutor(&executor10);
  st::Everything::addExecutor(&executor11);
  st::Everything::addExecutor(&executor12);
  st::Everything::addExecutor(&executor13);
  st::Everything::addExecutor(&executor14);
 
  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}

Here it is I might still tonight get it all hooked up

Thanks alot!

1 Like

Looks good to me! I will tell you about one thing to be aware of. Since you have a pretty large number of devices attached to the Arduino, you may notice a slight delay about every 5 minutes when sending a command to the Arduino (like to change the state of a switch, or activate a doorControl).

The reason for this is that ST_Anything performs an automatic REFRESH once every 5 minutes, to make sure that ST is kept up to date on the current status of every device you define in the sketch. It doesn’t take too long, but it can be noticeable. To adjust or disable the auto-refresh feature, open “
Arduino\libraries\ST_Anything\constants.h” and look for the following lines:

To Disable, uncomment the following line:

//#define DISABLE_REFRESH		//If uncommented, will disable periodic refresh of the sensors and executors states to the ST Cloud - improves performance, but may reduce data integrity

To change the interval, adjust the ‘300’ below to a larger number of seconds:

//Interval on which Device's refresh methods are called (in seconds) - most useful for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above
static const int DEV_REFRESH_INTERVAL=300;				//seconds - Used to make sure the ST Cloud is kept current with device status (in case of missed updates to the ST Cloud) - primarily for Executors and InterruptSensors - only works if DISABLE_REFRESH is not defined above

Thanks for looking! I got one sensor connected and your sample showed 4 and I get one temp at 0 one that goes between the correct temp and 196.6 and the other two are steady at 196.6 I am assuming it is because I only have one sensor connected. I will probably comment out alot of the switches until I need them. I have a relay bank of 16 and currently use only 4.

One more question: If sometime I wanted the Arduino to operate independant of ST, is it possible to intermix ST commands and others that would work locally?

Thanks again

Have a great evening