Announcing the "ST_Anything" Arduino/ThingShield Project


(Dan) #1

1/16/16 - Updated to reflect recent ST IDE nomenclature changes and v2 SmartThings Phone App image.

Just a heads up - The current Arduino IDE 1.6.6 has a bug in it which throws a compiler error (invalid namespace) when trying to build ST_Anything. Please continue to use v1.6.5 until 1.6.7 is released. You can use the latest "Hourly Build" of the 1.6.7 IDE as well, since I have confirmed the bug has been fixed in that version, as of 11/28/15.

I am happy to share with the SmartThings Community a project that my son and I have been working on for the past two weeks - ST_Anything! Our goal was to make it as easy as possible for anyone with some Arduino hardware/software skills to be able to get a new "Device" up and running in a matter of minutes versus hours/days. We have implemented many of the typical Device Capabilities supported natively by SmartThings. ST_Anything can be used "as-is" if desired, but we believe that most of you will want to do something somewhat unique to solve a particular need. To that end, ST_Anything is more of a reusable framework that abstracts all of the SmartThings library away from the user, allowing you to focus on creating new "Devices" by inheriting from the ST_Anything C++ library's PollingSensor, InterruptSernsor, and Executor classes. Please refer to the sample devices like Illuminance, Temperature/Humidty, Motion, Contact, Switch, Alarm, an Water as examples of how to do this.

The entire project can be found at

Feedback is most welcome. I am also willing to help anyone who needs assistance getting this up and running. The initial contents of the GitHub repo's ReadMe are below, which explains most of how to get things up and running.

NOTE: You can also find a new and improved version of SmartThings' Arduino Library in the repository. We have made many improvements to the library which any existing Arduino/ThingShield project will most likely appreciate as well. Please see the ReadMe section below for specifics - also, the ReadMe at the GitHub link has more details of how to use the new library.


Turn your Arduino into an 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.

This package currently implements the following SmartThings Device Capabilities:
•Alarm (Siren only currently)
•Illuminance Measurement
•Motion Sensor
•Relative Humidity Measurement
•Temperature Measurement
•Water Sensor
•Contact Sensor

Note: Attempting to use all of these at once on an Arduino UNO is likely to result in running out of SRAM on the UNO (the UNO only has 2 kilobytes of RAM.) Using an Arduino MEGA 2560 with 8 kilobytes of SRAM is recommended if you want to run everything at once.

ST_Anything consists of four parts:
•The ST_Anything.ino Arduino sketch
•The ST_Anything Arduino library
•The SmartThings (ThingShield) library - A modified, more efficient version
•The ST_Anything.groovy DeviceType

ST_Anything Arduino Setup Instructions
•Download the ST_Anything repository.
•This folder structure should mirror that of your local Arduino directory. Copy all the files in the repo to the corresponding local directories (detailed instructions of this process are below if needed).
â—¦ Look inside the 'Arduino\Sketches' folder of the repo.
â—¦ Copy and paste the 'ST_Anything' sketch folder into your local 'Arduino\Sketches' directory.
â—¦ Look inside the 'Arduino\libraries' folder of the repo.
â—¦ Copy and paste both the 'ST_Anything' and 'SmartThings' folders into your local 'Arduino\libraries' directory. (Note: it may be wise to rename your existing 'SmartThings' library to prevent any overwriting if you have already downloaded the official release.)
•Download DHT library from and copy dht.h, dht.cpp, and ReadMe.txt to your 'Arduino\libraries\DHT' folder.
•Open the ST_Anything.ino and see if it successfully compiles.
•WARNING: If you are using an Arduino UNO, you will most likely need to comment out some of the devices in the sketch (both in the global variable declaration section as well as the setup() function) due to the UNO's limited 2 kilobytes of SRAM. Failing to do so will most likely result in unpredictable behavior. The Arduino MEGA 2560 has 8k of SRAM and has four Hardware Serial ports (UARTs). If you plan on using lots of devices, get the MEGA 2560.

ST_Anything SmartThings Device Handler Installation Instructions
•Join your Arduino/ThingShield to your hub using your phone's SmartThings App. It will show up as a generic "Arduino ThingShield"
•Create an account and/or log into the SmartThings Developers Web IDE.
•Click on "My Device Handlers" from the navigation menu.
•Click on "+ New Device Handler" button.
•Select the "From Code" Tab near the top of the page
•Paste the code from the ST_Anything.groovy file from this repo.
•If you commented out any of the devices in the sketch, be sure to comment out the corresponding tiles & preferences in the ST_Anything.groovy code as well.
•Click on Save in the IDE.
•Click on Publish -> For Me in the IDE.
•Click on My Devices from navigation menu
•Select your "Arduino ThingShield" device from the list
•Click the Edit button at the bottom of the screen
•Change the Type to "ST_Anything"
•Click the Update button at the bottom of the screen
•On your phone, log out of SmartThings in the app, and then log back into SmartThings to refresh its settings
•Your Arduino Device Tile should now look like the image above in this ReadMe
•Be sure to go into the Preferences section to set the polling rates for the sensors. These are sent to the Arduino if you press the Configure tile. (Note: Currently, these settings do not persist after an Arduino reboot. I am hoping to figure out a method to have SmartThings send the Configure() command each time the Arduino starts up. Gotta leave something for the future! :slight_smile: )

Updated SmarthThings ThingShield Library
While developing the ST_Anything library and Arduino sketch, it was discovered that the Arduino UNO R3's 2 kilobytes of SRAM was quickly limiting the number of devices that could be hosted simultaneously. Numerous optimizations were made to the ST_Anything library which resulted in significant savings. Focus was then turned to the SmartThings ThingShield library.

Improvements to the SmartThings ThingShield library include:
•100% backwards compatible for use with your existing Arduino code
•Performance improvements
•SRAM memory optimizations (~150 bytes saved)
•Elimination of unnecessary temporary dynamic memory allocations (255 bytes per send command)
•Elimination of unused variables and dead code paths
•The additon of a Hardware Serial communications constructor
•Support for the 3 additional hardware UARTS on the Arduino MEGA 2560

If you choose to use the complete ST_Anything package (i.e. ST_Anything.ino, ST_Anything library, and ST_Anything.groovy) the following choices are automatically made:
•If using an Arduino UNO - SoftwareSerial is used on pins 2/3
•If using an Arduino Leonardo - SoftwareSerial is used on pins 2/10 (add jumper from pin 10 to pin 2)
•If using an Arduino MEGA, Hardware Serial is used on pins 14/15 (add jumpers from Pin14 to Pin2 and another from Pin15 to Pin3)

Multiple Devices on One Shield
Arduino SmartShield Garage Controller
Arduino Shield Suggestions?
Arduino Doorbell with smart shield help
Creating a relay closure alarm from Arduino to ST shield for Arduino
ST_Anything: 433Mhz RF Devices + Arduino + ThingShield
Automating my home on the cheap, wired automation
Integrating with Home Alarm
Smartthings shield UK
Arduino Mega and Smartthings Library issues
Arduino open/close sensor setup
Arduino + ST to control multiple Relays
Best Garage door solution with v2
SmartThings and Air Conditioners?
RF Motorized Shades
Need help troubleshooting ThingShield
Monitor a contact?
Wireless Communication Between Arduino Uno and ST Hub Options
[SOLVED] Pairing, discovery and device type for a custom Arduino recliner project?
Scoping advice for a few Arduino-based HW integration projects
How to send data from my LAN connected device to HubV2?
Neopixel projects
Can I develop an app that will work with Phidget devices?
Arduino SmartThing Shield Schematic?
Running ST locally, DIY control panel, and feasibility
Home made door lock sensor
Pet door project
Use existing in-home sensors with smartthings
Smart things Arduino shield issues
Any pointers to luminance only sensors
Arduino Mega and Smartthings Library issues
Roller shutter,no neutral wires,,,alternatives? Arduino tutorial?
Lutron RadioRA Integration
Home Automation Options for People who are quadriplegic/quadriparetic
Options for Arduino > Smarthings
ADT Alarm with ST Hub Integration - Help Please!
Xbee con arduino
Would this work to integrate into an existing wired security system?
Ardunio Shield not receiving events
How can I bring in a wired 0 - 10v signal?
Wired system with smart Things? (Existing wires, no devices--what now?)
Help with ST_Anything scripts anyone, please?
Arduino + Smartthings
Trying to control older lighting system over RS-232 with simple ASCII commands?
When is smartThings hub going to integrate Lutron?
Multi Input Dry Contact Sesor?
Smart Sprinkler System
Toilet tank leaked through ceiling
Standard Temperature Msg Format--need help parsing messages
ThingShield Arduino Library Invalid Name?
New Smartthings Hub - Whats the best I/O Solution?
Device Handler with 2 contact sensors and motion sensor?
Lutron RadioRA (version 1) and SmartThings saga. (Prologue)
Hardwired sensors
Zigbee/ZWave control for any battery powered device?
Updating / Replacing a 1970's Home Automation System
Automate Blinds by hacking 433 mhz Remote?
What projects are you currently working on?
(Edward Pope) #2

Excellent work, I will have to try this out when I get the shield. This will make many projects much easier to accomplish. I really do appreciate your work!

(Dan) #3

Thanks for the kind words. Please let me know if you need any help to get it up and running.

(Geko) #4

BTW, what's up with the Shield? AFAIK, they've been sold out. @steriana solicited suggestions from the community last September, but never revealed what the actual plans are with regards to the shield. Are there any plans to manufacture more or to build a new one?

(Todd Whitehead) #5

Wow! I have been playing with this for weeks and tonight I got one contact sensor working. I haven't even read this whole thing, but I can say this is REALLY what the community needed.

I sent an e-mail to ST support asking about thing shield availability. They said they had more coming. I sure hope so, because this is powerful stuff.

Thank you for sharing!

(Todd Whitehead) #6

I am getting an error trying to compile the arduino sketch. The distribution does not have dht.h and dht.cpp.

Where can I get those?

Thank you.

(Todd Whitehead) #7

I found a library that at least compiles here:

(Dan) #8


Sorry about the missing DHT library. I should have included a link to it in my ReadMe. I'll update it shortly.


(Todd Whitehead) #9

Okay. I have it installed.

I don't have all of these sensors, so I'm trying to play with the open/close to verify if it is working. Looking at the sketch, it says contact is pin 8. When I jumper pin 8 to ground, nothing happens.

I am using the Arduino Mega. Do I have to jumper any pins for it to work?


(Todd Whitehead) #10

Sorry, I'm posting a lot.

One of the things I really want to do is have multiple contact sensors that could each trigger different "stuff" in Smartthings. I was able to get one contact sensor to trigger a light on/off. But, I cannot figure out how to make the thing shield look like more than one contact sensor in the Smart Things app.

You guys have done more with this than anyone. Have you thought about that and if it can be solved?

Thanks, again.

(David Creed) #11


Congrats, this is awesome. I was playing with it tonight and had most of my generic Arduino hardware working with it in short order. I'm looking forward to building a few of these projects and integrating them into my home.


(Dan) #12


I have updated the ReadMe at the GitHub to include the DHT library instructions, as well as the first post in this topic. Thank you for the feedback and for giving ST_Anything a test run!

As for the Contact Sensor question, I think you already figured out how to get one to work, but just in case...

Per the sketch...

"#define PIN_SWITCH 8"
"#define PIN_ALARM 9 "
"#define PIN_CONTACT 11"

Pin 8 is a digital output for a relay, which is essential what a SmartThings Switch device is, like a SmartPower Outlet or a GE Z-Wave wall switch. Pin 9 is another digital output for another relay to turn on a siren. Of course, feel free to tweak the pins however you want...that's the purpose of the library! Just don't inadvertently assign the same pin to two different devices. I lost about 30 minutes trying to figure out that silly mistake during my copy and pasting of new sensors... smile

Pin 11 in the sketch is a digital input, which is set to use "INPUT_PULLUP" per the constructor (see IS_Contact.h and IS_Contact.cpp for details of the C++ constructor arguments.) By connecting Pin 11 to ground, you should see the Contact Sensor change from Closed to Open in the Arduino IDE Serial Monitor window, as well as in the SmartThings App on your phone.

On the MEGA, make sure you follow the detailed directions in the full ReadMe from the ST_Anything GitHub. By default, I have configured the MEGA to use Hardware Serial communications on pins 14 and 15. Pin 14 needs to be jumpered to pin 2 while pin 15 needs to be jumpered to pin 3. Using the hardware UART on the MEGA really improves the performance and reliability based on our testing.

As for your question about multiple Contact Sensors, or actually multiples of any device type... Yes, this is possible, but requires some custom Attributes in the Groovy Device Type code, along with a SmartApp to link these custom attributes to a set of Virtual Contact Sensor Devices. I have successfully done this as part of my original GarageDoor Arduino application which can be found below.

I am planning on converting my GarageDoor controller over to the ST_Anything library shortly and will happily share that example with the community as well. It implements 4 x Contact Sensors (1 digital input each), 2 x GarageDoors (1 digital input & 1 digital ouput each), and 1 x Temperature sensor. All of these devices show up in the SmartThings App's "Things" section as individual tiles, which can then be used within any existing SmartApps as if they were independent devices. I just need to find some time to work on it...

Continuing the discussion from Arduino SmartShield Garage Controller:

(Dan) #13

David (@DavidCreed),

Thanks for the feedback. Glad to hear it is working for you as well. If you have any suggestions, I'd love to hear them. There is a surprising amount of code behind the scenes, but it is amazing how simple the Arduino sketch is now.


(Dan) #14


As promised, I have rewritten my old Garage Door Arduino Application (now called ST_Anything_Doors) using my new ST_Anythings and SmartThings libraries. ST_Anything_Doors utilizes a DHT22 temperature/humidity sensor instead of the Dallas Semiconductor DS18B20 sensor. I have also added a Motion sensor to keep an eye on the interior of the garage.

ST_Anythings_Doors includes a new standard SmartThings Device Capability in the form of a "Door Control" device. I have written a new C++ class called IS_DoorControl for the Arduino to implement the Door Control capability which is typically used for a garage door. This class includes a digital input for a magnetic contact sensor as well as a self-timed relay output for "pressing the button" to open/close the garage door. Please read the comments in IS_DoorControl.h for specifics on how to use the constructor of this new class. The new ST_Anything_Doors.ino sketch should provide a nice example of how to use the new Door Control capability on an Arduino.

Also included in the ST_Anything_Doors package are three groovy Device Types (ST_Anything_Doors (for the Arduino ThingShield), VirtualContactSensor (for 4 house doors), and VirtualDoorControl (for the 2 garage doors.) You will also find one SmartApp called ST_Anything_Doors_Multiplexer which takes care of mapping the 6 virtual devices into the 1 Arduino Device. This allows standard SmartApps to see each of the 4 contact sensor devices and 2 DoorControl devices as if they were 6 standalone devices.

These changes are all available at Please be sure to download all of release v1.1 and replace any copies of the v1.0 ST_Anything library as changes were needed to some of the standard files in order to support the new DoorControl device properly.

As always, please let me know if anyone has any questions or suggestions for improvements.


@Todd_Whitehead, @johnwest80, @DavidCreed

Arduino SmartShield Garage Controller
Arduino Shield Suggestions?
(Todd Whitehead) #15


In the multiplexer smart app, is there a way to set a sensor in preferences as optional? I'd like to make a more generic version that I can add and remove contact sensors in different times of the year, but the preference pane will not let me move on if all of the sensors are not assigned to something.



(Dan) #16


I am sure there is probably a much cleaner and more generic way to write the Multiplexer SmartApp. Unfortunately, I am much more of an Arduino C++ programmer than I am a Groovy guy. One simple method would be to run multiple instances of the Multiplexer app, each one mapping a single virtual device to the Arduino (but I am not sure how you'd handle the different custom attributes that the app has to subscribe to.) Or, you could just tweak the SmartApp's groovy code based on your specific needs as they change.

To make it truly generic, you have to allow the user to select the virtual device tile, the Arduino, and the events it would subscribe to (in both directions) and the custom actions to call. I am not sure how to make that happen. Perhaps someone with a lot more groovy experience will chime in?

Thanks for taking a look. Hope it helps with your project!



(Todd Whitehead) #17


I am only using this for contact sensors, so it doesn't have to be THAT generic.

The work-around I am using right now is I just select the Arduino itself for the contact sensors that are not used. It has the potential to cause some error messages in the web interface log, but I almost never look at that.

I'll go see if I can RTTFM and find the solution.



(Todd Whitehead) #18

Okay, that wasn't hard to figure out. You use required: false

preferences {
section("Connect these virtual contact sensor to the Arduino's sensors") {
		input "pin4", title: "Virtual Contact for Pin 4", "capability.contactSensor", required: false
        input "pin5", title: "Virtual Contact for Pin 5", "capability.contactSensor", required: false
        input "pin7", title: "Virtual Contact for Pin 7", "capability.contactSensor", required: false
        input "pin8", title: "Virtual Contact for Pin 8", "capability.contactSensor", required: false
        input "pin9", title: "Virtual Contact for Pin 9", "capability.contactSensor", required: false
        input "pin10", title: "Virtual Contact for Pin 10", "capability.contactSensor", required: false
        input "pin11", title: "Virtual Contact for Pin 11", "capability.contactSensor", required: false
        input "pin12", title: "Virtual Contact for Pin 12", "capability.contactSensor", required: false


    section("Which Arduino board to control?") {
		input "arduino", "capability.contactSensor"


(Todd Whitehead) #19

Hi Dan (@ogiewon),

I am expanding my custom setup using your ST_Anything library. I started with the door sensors in my house and now I am adding moisture and temp humidity sensors. I have a problem and a question.

Problem: When I run the ST_Anything code, I get an error on the DHT call. I am using a DHT11 instead of a DHT22 (Does that matter?), but even if I point to a pin where the sensor isn't present, I still get this error:
PS_TemperatureHumidity: DHT Unknown Error

Question: Can I have more than one Temp Humidity sensor? For the other "things", the name in the declaration is the name we use in the device driver. But for temp humid, it seems to have hard-coded names. Is there a way to force some sort of suffix to the name so I can define more than one?

Thank you

(Dan) #20

Todd (@Todd_Whitehead),

If you're using a DHT11, simply change the call in the sketch to refer to a DHT11 instead of the DHT22. That should sort out that issue.

As for multiple Temp/Humid sensors, I can modify the PS_TemperatureHumidity class to allow you to pass in two optional string arguments which will be used when transferring data to the ST Cloud. This will allow you to have multiple temperature and humidity sensors, assuming you name the tiles in the Device Type code that same as the new names you pass into the new optional arguments.

The reason I used "temphumid" as the Arduino device name was to allow the polling interval to be sent from the Cloud to the Arduino when you press Configure (be sure to set the polling rates in the Preferences first). This is really optional, and does not currently persist after an Arduino reboot. I still want to use the Arduino EEPROM to persist those values.

I'll make the code change shortly and update GitHub. I'll let you know when it's ready. Shouldn't take long.