Announcing the "ST_Anything" Arduino/ThingShield Project

@ogiewon,

First, I’ll chime in with everyone else and say thanks for this contribution!

I have a Honeywell/Ademco alarm integration project with SmartThings.

It uses a previous SmartThingsMega ThingShield library that requires bending out pins 0/1 which is not as elegant as your solution.

I would like to migrate the code over to the ST_Anything library and having a few issues getting the communications going between the Shield and the Mega. I am using Serial3 for hardware serial communication and have the jumpers set up to from 14->2, 15->3. And have the DIP set to D2/D3.

What are the constructors and the #define statements that I would need in my sketch?
To use Serial3, do I go into the SmartThings.cpp and modify the code to replace “hwSerialPort” with “HW_Serial3”? Or is this taken care of in the sketch with #define and a constructor?

If you know of or have an example code for a non-ST_Anything sketch that uses your SmartThings library for a Mega, I could work from there.

Thanks in advance!

@d8adrvn

Stan,

Turns out the change is super simple to make to your existing sketch. I just needed to take a look at how we added HW Serial support to remember… Our SmartThings library has two versions of the constructor, one for Software Serial and another for Hardware Serial. Here is a comparison of the two…

Software Serial (traditional method - identical to the original SmartThings library)

SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout);  // Software Serial Constructor

Hardware Serial (useful for the Arduino MEGA 2560)

SmartThings smartthing(HW_SERIAL3, messageCallout); //HW Serial Constructor

The HW_SERIAL3 is an enum value that was added to SmartThings.h. Other HW Serial ports are supported as well.

You do not need to modify any of the SmartThings library source files. Just modify your sketch to use the new HW Serial constructor as shown above.

Enjoy!

Dan

@ogiewon,
Your right! Super Simple! Worked like a charm.

I’ll be updating my project soon and will be sure to give you a shout out in the credits.

ST_Anything_Doors
I have a arduino working with a relay connect to a wireless garage door remote. I am also using PIR and a contact sensor for the regular door. I am using a z-wave tilt sensor for the main overhead garage door that tells me when it’s opened and closed. How do I get the tilt sensor working with the application?

@MikeDL

Mike - I am not exactly sure how you are using the ST_Anything library / ST_Anything_Doors sample code. Can you try to explain a little more your overall plan/design? The ST_Anything_Doors example is somewhat specific to my house, but could be modified to work for any house. The Garage Door portion currently expects a magnetic reed switch to be attached at each garage door and then wired to the Arduino to indicate whether the door is open or closed. To operate the garage door opener, a relay needs to be attached between the Arduino and the garage door opener’s “pushbutton” input (in parallel to permit existing functionality to still work).

I will try to help as best I can. Not sure how you have the “Tilt Sensor” integrated… It sound like you really just want to use the Arduino as a relay output device connected to the garage door pushbutton. Doing this may require you to use just a porttion of the complete ST_Anything_Doors sample code (Arduino and Groovy.) It definitely is possible. Perhaps a drawing of your overall design would be helpful?

Dan

The only difference is instead of using a contact sensor for the garage door I am using one of these. I guess the code is designed toggle the relay then wait for the garage door sensor to either be opened or closed. Where is that code located?

The code really doesn’t care about the open/closed sensor when it comes to opening/closing the garage door. In both cases, the Arduino simply energizes the relay for about 1 second, and the de-energizes the relay. It really simply replaces your finger pressing the button to open/close the garage door.

Sorry Smartthings code newb. How does the following code know to either post opening or closing?

	standardTile("leftDoor", "device.leftDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
		state "closed", label: 'Closed', action: "pushLeft", icon: "st.doors.garage.garage-closed", backgroundColor: "#79b821", nextState: "closed"
        state "open", label: 'Open', action: "pushLeft", icon: "st.doors.garage.garage-open", backgroundColor: "#ffa81e", nextState: "open"
        state "opening", label: 'Opening', action: "pushLeft", icon: "st.doors.garage.garage-opening", backgroundColor: "89C2E8", nextState: "opening"
        state "closing", label: 'Closing', action: "pushLeft", icon: "st.doors.garage.garage-closing", backgroundColor: "89C2E8", nextState: "closing"

I think I figured it out. All control for the garage door relay is done in IS_DoorControl library.

Correct! The IS_DoorControl is a very special class that handles the door status as well as the relay output. It is not designed to be integrated with another wave/zigbee sensor.

However, you could easily modify it to suit your needs as you see fit. That is exactly what my son and I hoped users would do with the ST_Anything library.

Have fun! :blush:

1 Like

Thanks so much for creating this. I have 6 magnetic reed sensors hooked up to an Arduino Mega. I was able to create more sub tiles using the code that was created. Can anyone tell me how to write the code to allow the sub tiles in the ST Anything Tile to send notifications for each individual sub tile? I am not very familiar with programming. As of right now I am only able to include ST Anything as a whole to send a push notification using a smart app. Here is the code.

/**

  • ST_AnyThing.groovy
  • Copyright 2014 Dan G Ogorchock & Daniel J Ogorchock
  • 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:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • 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.
  • Change History:
  • Date Who What

  • 2015-01-03 Dan & Daniel Original Creation

*/

metadata {
definition (name: “ST_AnyThing”, namespace: “ogiewon”, author: “Daniel Ogorchock”) {
capability "Configuration"
capability "Illuminance Measurement"
capability "Temperature Measurement"
capability "Relative Humidity Measurement"
capability "Water Sensor"
capability "Motion Sensor"
capability "Switch"
capability "Sensor"
capability "Alarm"
capability "Contact Sensor"
capability “Polling”

	command "test"
	command "alarmoff"

}

simulator {

}

// Tile Definitions
tiles {
	
    standardTile("water", "device.water", width: 1, height: 1) {
		state "dry", icon:"st.alarm.water.dry", backgroundColor:"#ffffff"
		state "wet", icon:"st.alarm.water.wet", backgroundColor:"#53a7c0"
	}

	standardTile("motion1", "device.motion1", width: 1, height: 1) {
		state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0")
		state("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#ffffff")
	}
    
    standardTile("motion2", "device.motion2", width: 1, height: 1) {
		state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0")
		state("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#ffffff")
	}
    
    standardTile("switch", "device.switch", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}

	standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
		state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
	}

	standardTile("contact", "device.contact", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
    standardTile("contact1", "device.contact1", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
    standardTile("contact2", "device.contact2", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
    standardTile("contact3", "device.contact3", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
    standardTile("contact4", "device.contact4", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
    standardTile("contact5", "device.contact5", width: 1, height: 1) {
		state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
	}
    
	standardTile("alarm", "device.alarm", width: 1, height: 1) {
		state "off", label:'off', action:'alarm.siren', icon:"st.alarm.alarm.alarm", backgroundColor:"#ffffff"
        state "strobe", label:'', action:'alarmoff', icon:"st.secondary.strobe", backgroundColor:"#cccccc"
        state "siren", label:'siren!', action:'alarmoff', icon:"st.alarm.beep.beep", backgroundColor:"#e86d13"
		state "both", label:'alarm!', action:'alarmoff', icon:"st.alarm.alarm.alarm", backgroundColor:"#e86d13"
	}

	standardTile("test", "device.alarm", inactiveLabel: false, decoration: "flat") {
		state "default", label:'', action:"test", icon:"st.secondary.test"
	}
    
	standardTile("off", "device.alarm", , width: 1, height: 1) {
		state "default", label:'Alarm', action:"alarmoff", icon:"st.secondary.off"
	}
	//standardTile("off", "device.alarm", inactiveLabel: false, decoration: "flat") {
	//	state "default", label:'', action:"alarmoff", icon:"st.secondary.off"
	//}

    main(["contact","contact1","contact2","contact3","contact4","contact5","motion1","motion2","alarm","water"])
    details(["contact","contact1","contact2","contact3","contact4","contact5","motion1","motion2","alarm","test","off","water","configure"])
}

}

// parse events into attributes
def parse(String description) {
log.debug “Parsing ‘${description}’”
// TODO: handle ‘contact’ attribute

}

def openme() {
log.debug "Virtual Contact Open"
sendEvent(name: “contact”, value: “open”)
}

def closeme() {
log.debug "Virtual Contact Closed"
sendEvent(name: “contact”, value: “closed”)
}

// handle commands

def on() {
log.debug "Executing ‘switch on’"
zigbee.smartShield(text: “switch on”).format()
}

def off() {
log.debug "Executing ‘switch off’"
zigbee.smartShield(text: “switch off”).format()
}

def alarmoff() {
log.debug "Executing ‘alarm off’"
zigbee.smartShield(text: “alarm off”).format()
}

def strobe() {
log.debug "Executing ‘alarm strobe’"
zigbee.smartShield(text: “alarm strobe”).format()
}

def siren() {
log.debug "Executing ‘alarm siren’"
zigbee.smartShield(text: “alarm siren”).format()
}

def both() {
log.debug "Executing ‘alarm both’"
zigbee.smartShield(text: “alarm both”).format()
}

def test() {
log.debug “Executing ‘alarm test’”
[
zigbee.smartShield(text: “alarm both”).format(),
“delay 3000”,
zigbee.smartShield(text: “alarm off”).format()
]
}

def poll() {
//temporarily implement poll() to issue a configure() command to send the polling interval settings to the arduino
configure()
}

I know the ST Shields are in short supply and I am selling mine. I wanted to use it for the smart sprinkler project, but my sprinkler system runs on high voltage which would necessarily destroy any low voltage things connected to it.

Anyway, I paid $35.00 for it and that’s what it is going for. If you want to buy it let me know and we can make paypal arrangements.

Ryan,

You may want to look at the ST_Anything_Doors example in the Github Repository as it shows how to use multiple contact sensors using one Arduino. It includes the Arduino sketch, the Groovy Device Type for the Arduino, a Multiplexer SmartApp, and Virtual Contact Sensor Device Type.

The only way to use the individual contact sensors in the Arduino is to map them to corresponding virtual contact sensors. The virtual contact sensors can then be used in normal SmartApps.

Hope this helps!

Justin,

You do realize that the relays you choose to use with the Arduino can easily handle 120/240 VAC? No need to abandon the project.

Here is an example relay board that should suit your needs - http://www.amazon.com/JBtek-Channel-Relay-Arduino-Raspberry/dp/B00KTELP3I/ref=sr_1_1?ie=UTF8&qid=1436486992&sr=8-1&keywords=Arduino+relay

The relay receives a low voltage DC signal from the Arduino to turn on, the relay then switches AC or DC voltage to your sprinkler valve, one relay per valve.

Does this make sense? If you’re not comfortable working with high voltage systems, you might want to enlist the help of a competent friend or a licensed electrician.

Dan

Thanks Dan!
I am going to go back and start over with the things that you mentioned. I originally had the code working from the ST Anything sketch. I will load everything with the ST Doors project and change the pin numbers to match what I have on the Arduino. I really appreciate your help!

Thanks,
Ryan

Hey Dan,

Thanks for building this, i read through most of it last night and some of the example codes and have ordered kit to have a play. One thing I haven’t been able to locate is a IR option, so I can replace remote controls around the house, so I can turn the AC on or off etc.

I found something like https://www.youtube.com/watch?v=2xFrO-VBLOI but wondered if you had created something similar for ST_Anything ?

Many thanks in advance
cheers
barry

Barry,

I haven’t tackled IR yet using the ST_Anything library, but I have done 433MHz RF remote controlled devices. Take a look at the following as a starting point. You would just need to create your own class, probably called EX_IRSwitch.cpp and .h using the EX_RCSwitch files as a starting point. Replace all of the RC-Switch calls/libraries with whatever IR libraries and code you need to control your devices.

Hope this helps!

Dan

I’m interested, check your private inbox

Hey Dan,
This is probably a stupid question but I still can’t get the Virtual Contact working the way that it should. I have the Anything Doors code loaded on the Arduino Mega and the Groovy code loaded on the IDE. That all works fine. The sensors on the doors are talking to each other and show open and closed on the app on my phone. So here is my question, how do I make everything work together assuming that I leave all of the code the same that you have created. Do I need to create a “New SmartDevice” then add the VirtualContactSensor code to that? If so, how do I then point the Virtual Contact to the sub tiles on the Arduino? If you have any examples or can tell me how to make it work, that would be great. I am just really confused and banging my head against the wall trying to figure this out. I went to school for Electronics Engineering but haven’t had much experience with programming. Any help that you can give would be appreciated. I can’t find any examples of how to link Virtual Devices anywhere.

Thanks,
Ryan

Ryan,

Not a stupid question… It took me quite some time to get my head in the SmartThings game…

Here are the basic steps to using ST_Anything_Doors:

  1. Load ST_Anything_Dooor.ino on your Arduino (requires all of the associated library files to have also been installed in your Arduino Libraries folder.) Sounds like you’ve done this already.
  2. Create a new “ST_Anything_Doors” DeviceType in the ST IDE (under Device Handlers) and paste in the ST_Anything_Doors.device.groovy code. Save and Publish. Sounds like you’ve done this already.
  3. In the ST IDE (under Devices), change the Device Type of your Arduino to your new “ST_Anything_Doors” DeviceType from step 2. Sounds like you’ve done this already.
  4. Create a new “Virtual Contact Sensor” DeviceType in the ST IDE (under Device Handlers) and paste in the VirtualContactSensor.device.groovy code. Save and Publish.
  5. In the ST IDE (under Devices), create a new device (call it whatever you want) and assign it to use the “Virtual Contact Sensor” DeviceType from step 4.
  6. Repeat step 5 until you have created a virtual “contact sensor” device for each of the Arduino’s real contact sensor inputs.
  7. In the ST IDE (under Smart Apps), create a new Smart App called “ST_Anything_Doors_Multiplexer” and paste in the groovy code from ST_Anything_Doors_Multiplexer.smartapp.groovy. Save and Publish.
  8. Using your phone/tablet, start the SmartThings app and “Add a new SmartApp” - select the “ST_Anything_Doors_Multiplexer” app that you created in step 7.
  9. Configure the new smart app to use the Virtual Contact Sensor devices you created in steps 5/6. Configure the smart app to use the Arduino device you revised in step 3. Save the settings.

I have skipped the virtual garage “Door Control” devices, but you can repeat steps 4/5/6 to create the two virtual garage door devices if desired using the corresponding groovy code. Then you can add them to the SmartApp as well. These virtual devices are a little more complicated as they are two-way devices.

Basically, what is happening here is the following:
-Arduino reads real world data and sends to ST
-Events are raised in the ST_Anything_Dooors device
-The ST_Anything_Dooors_Multiplexer smart app sees these events, and in turn, updates the virtual contact sensor devices with the current state of the Arduino’s inputs.
-Any other smart apps that are looking at the virtual contact sensor devices will then receive an update and act accordingly.

Hopefully this helps to clear things up!

Dan

1 Like