Announcing the "ST_Anything" Arduino/ThingShield Project


Ok, so I couldn’t stop once I started. I have created for you everything I think you’ll need for your project and it is all stored in my GitHub repository.

I have created the following new files for your project:

Arduino Sketch - ST_Anything_Doors_Windows.ino
ST DeviceType - ST_Anything_Doors_Windows.device.groovy
Multiplexer SmartApp - ST_Anything_Doors_Windows_Multiplexer.smartapp.groovy

And you’ll need to create 13 virtual Contact Sensors (one for every Door and Window you want to monitor) using the following Device Type also found in my GitHub repo.

Virtual Contact Sensor Device Type - VirtualContactSensor.device.groovy


  1. Load Arduino sketch on your Arduino
  2. Pair your Arduino to ST Hub (if you haven’t done this already)
  3. Add a custom device type using ST_Anything_Doors_Windows.device.groovy in the ST IDE
  4. Change the DeviceType of your Arduino to the new one you created in step 3.
  5. Add a custom device type using VirtualContactSensor.device.groovy in the ST IDE
  6. Manually create all 13 Doors and Windows devices using the IDE and the custom device type created in step 5
  7. Add a custom SmartApp in the IDE using ST_Anything_Doors_Windows_Multiplexer.smartapp.groovy
  8. On your phone, add the SmartApp created in step 7, and configure it to use the 13 virtual doors and windows you created in step 6. It will prompt your for each one of these. Also, configure it to use the Arduino Device you set up in step 4.

Note: I have not tested the new Multiplexer SmartApp yet (running out of time) but it should work. It is the glue between the 13 virtual devices you created and the one Arduino. This is necessary in order to use your new Door and Window devices in normal SmartApps like SmartHomeMonitor.

Have Fun!


Time to learn about those child devices! Your Multiplexer app could create the 13 virtual Contact Sensors for you, saving considerable effort.

It’s on Git. Go Git it! :grinning:

Totally agree. Just need to find the time to figure it out… :grinning:

Currently busy trying to “cut the cord” from Time Warner Cable TV… I just installed a nice antenna in my attic! Never thought I’d ever being doing that again!

@bravenel do you have any examples of code that dynamically create virtual devices? I have a few use cases for this and it will further simplify my setup. Thanks in advance.

@bravenel never mind changed my search and found this thread:
Spawn or Instantiate a Virtual Device in SmartApp?

You can look at my Lutron Gateway app at the link below. In that, I create many child devices, and subscribe to events from them. You can see the mechanism for creating names, and then finding the devices later to control them.

1 Like

@ogiewon - Wow, thank you! It probably would have taken me forever to figure all that out. I’m just getting in to this tonight and so far all of the 4-13 pins are working well. It seems that the analog pins are not working though (A0-A5). I’m just bench testing them by jumping the pin to ground and its not giving me any updates.

Was there something special I was supposed to do for the analog pins?

@mweston - Hmmmm, I tested the analog pins A1-A5 and all worked as expected for me just grounding each pin individually.

For all of the Pins, the code should be set to use the Internal Pullup resistor, which should keep the inputs Hi, until you ground them.

Please read the following article - - looks like to use an internal pullup resistor on an analog pin, you’ll need to add a few calls in the sketch’s setup() routine, after all of the ST_Anything initialization is completed.

Add these calls after “st::Everything::initDevices();” in setup() and see if that solves the issue.

digitalWrite(A1, HIGH); // set pullup on analog pin 1
digitalWrite(A2, HIGH); // set pullup on analog pin 2
digitalWrite(A3, HIGH); // set pullup on analog pin 3
digitalWrite(A4, HIGH); // set pullup on analog pin 4
digitalWrite(A5, HIGH); // set pullup on analog pin 5


You did remember to perform this step as well, correct? Otherwise the 4 doors will not be created within the Arduino. These are the ones that use the A1-A4 pins.

Also, I tested the fix I posted above and it does seem to work.

Yes, thanks that was it… Forgot to update constants.h

@ogiewon Looks like I’ve got everything up and running so far except motion. For some reason that one is not responding. I’ve seen it trigger active motion occasionally but it seems to be random when I’m not even touching the A5 pin.

Some other thoughts for future updates…

The activity log gets pretty messy now that there are a lot of devices and it looks like it checks every few seconds so you can’t really tell if a door actually closed at that time or if it was just checking and reporting the status in the “recently” and “activity feed” tabs.

I’m also getting a “catchall:” message in my activity log, not sure what that means or if it is my fault.

Will look into the motion issue tomorrow and see if I can find what went wrong there.

Did you add the following lines to your sketch’ setup() routine? This will solve the motion detector input from false transitions.

As for the routine updates, the system is designed to update everything every 5 minutes, even if nothing has changed. This is to make sure ST is kept in synch with the Arduino. It will not cause false triggers within the SmartThings world, as ST needs to see a true change before it will take action.

If you do not want this behavior, you can disable it in constants.h.

The catchall is normal as well. You can safely ignore it it. It is done by the ThingShield automatically.

I know this has been around for a while now, but just wanted to say thanks. Was working on something similar and you just saved me days. Really awesome stuff!


Glad you found it useful!


Dan @ogiewon,

As you know, I am a huge fan of what you’ve done here.

I have an enhancement request that I think would be fairly straight forward. I could do this in Arduino code, but I know how accommodating you have been in the past, so I thought I’d ask if you thought this was something you’d be interested in looking at for your libraries.

I have a friend who has an alarm system that still works. He wants to add ST integration, but he wants the alarm to still work.

I was thinking that if when I define a contact sensor, I could pass an optional second pin and a flag. If this is passed, the software could pass through any changes on the original pin to the optional second pin (using the flag to determine whether to pass it asis or flip it (high on input, high on output or high on input, low on output)). This would allow people to insert the arduino in the middle of a working alarm and still have that alarm work the way it did before.

So, I hook the front door sensor to pin8 on the Arduino and then hook pin 9 to the place where the front door sensor was hooked on the alarm (I might need a relay in there, not sure, but I could do that if needed) and ST could monitor status and the alarm system would not know it was there.



So I’ve been mulling over an idea lately that has my curiosity piqued…

I have a remote start system in each of my vehicles and have a lot of experience with 12v Automotive Electrical systems.
In fact, I performed all of the remote start/security installations in all of the cars.

I’ve been thinking about the ThingShield/Arduino combination and how it would be useful in my particular case for integrating my vehicles with ST.

All of my modules have two fun little features on them.
One is a wire, that when momentarily brought low (ground is applied), will start the vehicle. Reapplying ground momentarily will shut the vehicle off.
The other is a second wire that outputs 12v+ when the module has started the vehicle and confirmed it is running.

I am also able to integrate the door locks and windows via the remote start module with input leads, so that I could lock/unlock the doors, as well as roll the windows up/down on one or two of the cars that I have installed this feature on.

My weakness comes in with the arduino and any programming needed to make it work.

Would anyone be willing to help me tackle something like this?

The signaling wires are all very low current at the module. The module does the majority of the heavy lifting with the exception of window roll up or down. That is a separate window control unit.

My long term goal is to have a status button on the wall display that shows grey when the car is not running, but green when active. Tapping the icon will speak via the ST system to the ThingShield/Arduino, and the car will start.
Tapping it again will shut the car off. A separate button will allow my wife to unlock the doors on the car in the driveway if I have the keys with me and am gone at the neighbor’s/gym/work with one of the other cars…

The same function would work for window rollup/down, etc.


Todd @Todd_Whitehead,

Yes, this could be done fairly easily with an optional parameter in the constructor for the contact sensor. Of course, the question I have to ask is, “Why not just wire the existing alarm system in parallel with the Arduino, such that no new outputs are needed?” This would require that the existing alarm system use 5V TTL signals ideally, but could also be accomplished with a simple circuit to level shift the existing alarm system’s voltage.

The advantage this would have is that the existing alarm would still work, regardless of the Arduino’s hardware and software. It would also be very simple.


Would this work? If I understand what you are saying, I would hook the Arduino pin and ground to the pin and ground for the loop the is the sensor so that the arduino is essentially wired as if it was a sensor?

Alarm Sensor 1 + o----------------------------------------------o /
Alarm Sensor 1 - o----------------------------------------------o/

Alarm Sensor 1 + o--------o-------------------------------------o /
Alarm Sensor 1 - o--------|---o---------------------------------o/
Arduino Pin 8    o--------+   |
Arduino Ground   o------------+

Would that actually work? Would both devices detect the switch state changing?



Yes, that is exactly what I’d be tempted to try, assuming both systems a running at 5 VDC. If they are not both 5VDC , you could build a simple circuit (possibly even using a relay if necessary) to trigger the Arduino input based on the existing alarm system’s wiring. This would protect the Arduino from improper voltages. (Note: in your original design, this same issue would be present as well, as the Arduino’s output voltage would have to be adjusted to match the alarm system’s voltage requirements.)