Creating a relay closure alarm from Arduino to ST shield for Arduino

Not knowing what I’m doing makes it difficult to know how to ask the right questions or search topics for the right answer. Sorry if I’m redundant.

I’m taking advantage of a feature of my furnace that it closes a relay when the furnace goes on the fritz. I currently have Adruino code that accurately detects HIGH/LOW on a digital pin. That part works OK. I can take action based on those digital pin cases.

The next step is to bridge the physical world to the virtual. I will have a ST shield for Arduino but they are currently out of stock. In the meantime, I’m trying to code this up.

I created a new Device and called it FurnaceAlarmDevice and gave it “button” capability.
Was the the right thing to do?
Should I create a new Device Type also/instead?
Can someone clarify what “should” be the next steps?

Thanks in advance,

You will need a device type for your thing shield. You can take a took at my arduino code and device type.

Once you have the shield you will need to import the relevant library and add some methods to your loop that send the events off to the cloud. You need a device type that can handle those incoming events and do whatever you wish them to do.

Thanks @jody.albritton. That’s what I needed to know.

I’ll go have a look at your repo and try to correlate the Device Type to the groovy code.
Hopefully I can wrap my mind around it enough to figure it out or at least ask more intelligent questions.


@ogiewon posted about a great library and device types he created with his son.

It’s EXACTLY what you are looking for!

Check it out.



Thanks @Todd_Whitehead.
I’ll have a poke at his code.

I’ve posted my code on github. The groovy code can’t be further tested yet as I don’t yet have the ST Shield for Arduino to really test things out. Anyone wanting to look/comment is welcome.
Thanks! @Todd_Whitehead and @jody.albritton for your posts. You helped me greatly.


I’ve finally received my ST Shield for Arduino as they were out of stock for a while.
Connecting the hardware world to the virtual is where I am lost.

The sketch I’m using with arduino is here: Arduino Sketch
I think the hardware layer is fine based on LED lights in my circuit.

I’m lost looking at the post by @ogiewon as recommended by @Todd_Whitehead (Thanks Todd). Despite this I’m still painfully lost.

What I did try to do, was to create a new ST Device Type of “Relay Switch”, then I assigned that type to the new ST Shield. The devicetype code is not seeming to catch any smartthing.send(alarmTriggeredMessage); commands as coming from the hardware. What I need to do is capture these messages and take appropriate action in a handler.
Does anybody have device type code that detects a relay closure then sends a push?

I’m hoping that @ogiewon will jump into this conversation.



I recommend starting with @ogiewon 's project and then removing what you don’t need.

Start here:

Follow these instructions and see if you can get the ST Anything project working in Smart Things. Once you do that, you can jumper the pins to ground to see if it is working. And then, depending on what you are trying to do, you can remove sections of code from the sketch and the device type to get just the functionality you need.

If you need help with that part, write back with more information on what you want to use the Arduino to do and we can help you with more specific instructions. But the first thing is to get the ST_Anything example working to make sure you have everything you need in place.

Good luck!

@Todd_Whitehead, Working on my new mac, I had to install a new Arduino IDE.
I get an error (RE: SmartThingsSerialType_t) compiling @ogiewon’s sketch. Note, that I have imported all 4 of his libraries into my IDE.
I made sure that I have the SmartThings library installed as well as that’s where (SmartThings.h) that ENUM is defined.
The error is:

In file included from ST_Anything.ino:48:0:
/Users/mlupo/Documents/Arduino/libraries/ST_Anything/Constants.h:113:18: error: ‘SmartThingsSerialType_t’ does not name a type
static const SmartThingsSerialType_t SERIAL_TYPE = HW_SERIAL; //UNO, Leonardo, MEGA - You MUST move ThingShield switch to D0/D1 position after loading program and then reset the Arduino
Error compiling.

Are you using an Arduino Mega?

If not, then I think you need to update constants.h around line 113 to comment out the mega line and uncomment the line for the Arduino board you are using.

Since the ST_Anything project won’t compile, I’m back to poking at my own code.
Specifically, when the UNO detects the relay closure, I send a message back up to the cloud.
For example, smartthing.send("“Furnace is back to normal”);

As per @jody.albritton, I need to create a Device Type (DT) to capture those messages.
Not sure, but I think my problem starts in the “parse” method of my DT. I don’t know how to test for that message and then how to see to it that the correct handler is called. In the meantime, I’m going to look at Jody’s DT code again. I can’t seem to get the parse method to print any log statements so I don’t know when/if it’s getting invoked… the dots are not connecting.

in Detail: My device type is called, “FurnaceAlarmDeviceType”. My actual hardware, (ST Shield for Arduino) is assigned that device type so that it behaves like a “FurnaceAlarmDeviceType”.

This is the source:

 *  FurnaceAlarmDeviceType
 *  Copyright 2015 michael lupo
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
metadata {
	definition (name: "FurnaceAlarmDeviceType", namespace: "mlupo", author: "michael lupo") {
		capability "Switch"
        command: "sendAlarm"
        command: "sendBackToNormal"

	simulator {
		// status messages
		status "ping": "catchall: 0104 0000 01 01 0040 00 6A67 00 00 0000 0A 00 0A70696E67"
		status "hello": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A48656c6c6f20576f726c6421"

		tiles {
        standardTile("switch", "device.relayswitch", width: 2, height: 2, canChangeIcon: true) {
			state "on", label: 'FurnaceAlarm!', action: "", icon: "st.switches.switch.on", 
            	backgroundColor: "#79b821"
			state "off", label:'FurnaceNorm', action: "switch.on", icon:"", 
		main (["button"])

// parse events into attributes
def parse(String description) {
    log.debug "Parsing ${description}"
    def name = null
    def value = zigbee.parse(description)?.text
    log.debug "Value is ${value}"

    def result = [
            value: value,
            name: value != "ping" ? name : null
    log.debug result
    return result


// handle commands
def on() {
	log.debug "Executing 'on'"
	// TODO: handle 'on' command by sending the SMS/PUSH event from here.

def off() {
	log.debug "Executing 'off'"
	// TODO: handle 'off' command by sending the SMS/PUSH event from here.

I’m using an Arduino Uno. I had already done exactly what you stated.

@Todd_Whitehead did you get a chance to look at my Device Type code?

Thanks in advance,

Device types are not my strong point. I know how to make the ST Anything work, but am not going to be able to help you with another one.



Thanks @Todd_Whitehead for what you could contribute. I realize that my problem is a particularly frustrating one. I’ve written one other device type that works fine. I.e. a garage door opener.

I’ll get this. I’m darn persistent if anything.


Perhaps a new thread just discussing the issue you are having with parsing in a device type will get more answers?



Are you still having trouble getting this to work? I am curious as to why you want to emulate a “switch” capability? It seems that you are trying to know when the furnace is having an issue. This is more of a digital INPUT (i.e. a ST “Contact Sensor”) versus a Switch type of device which is a Digital OUTPUT.

If you are still looking for some assistance, I would be happy to create a stripped down, purpose built, version of the ST_Anything Project that implements a single Digital Input on the Arduino, as well as a custom Device Type for SmartThings. This would take me only about 20 minutes using the ST_Anything code as a starting point.

Please let me know if you are interested.


1 Like

Code written and tested on my Arduino UNO R3 as well as the custom groovy Device Type code. I have sent you a private message with more details on how to proceed.


Unless you really want/need to use the Arduino’s HardwareSerial library on an Arduino UNO, there is no reason to uncomment line 113 in Constants.h. In fact, for 99% of users, I would recommend leaving the serial comm settings as default in Constants.h. The library will AutoMagically detect if you’re using an UNO and select the SOFTWARE_SERIAL library on pins 2/3. This is the exact same behavior as the “regular” SmartThings library. My SmartThings library was modified to improve memory usage and to add support for the Arduino Mega’s additional HardwareSerial ports. If using a Mega, the library will AutoMagically configure the project to use the HARDWARE_SERIAL library.

If anyone really wants to use HARDWARE_SERIAL on an UNO R3, it is possible, but not exactly for the faint of heart. I can explain the process to anyone who really needs this capability. It requires a few more changes within Constants.h, and it requires you to give up all debug messages via the USB/COM port Serial Debug Console. UNO users should really just stick with the default behavior if possible as this allows you to debug your code using the Serial Debug Console.

Hmmmm… I believe your compiler error was because you uncommented line 113 in constants.h. No need to do that if you’re using the default SoftwareSerial library. Different sections of code are conditionally compiled based on whether SoftwareSerial or HardwareSerial is being used.