Announcing the "ST_Anything" Arduino/ThingShield Project

1 Like

Nice team-work everybody!

3 Likes

Hello ogiewon,

Just wondering if you ever implemented Mysensors? Being based in the UK. I don’t have access to The Smartthings shield.

Best wishes.

James

No, I never did get around to incorporating MySensors. However, it would not have helped you as my original thought was to still use the ST ThingShield to do so.

Thank you.

@foggy take a look at this thread which demonstrates using an Ethernet shield to communicate with ST through the HUB. No ThingShield required.

1 Like

@ogiewon - Have you seen this? It’s interesting, though I’d love to see what people can use this for without going through the cloud. The Beta IDE might prove to be something in the future…

http://makezine.com/2016/04/02/arduino-mkr1000-project-platform/

@Jason_Fay - This does look very intriguing. There has been some success by others in direct bi-directional Ethernet communications between an Arduino (with Ethernet Shield) and the ST Hub v2. I have even built a small proof of concept sketch based on that work and verified it for myself. I may spend some time adding Ethernet support to ST_Anything at some point in the future.

Check out this post by @Charles_Schwer

https://community.smartthings.com/t/how-to-send-data-from-my-lan-connected-device-to-hubv2/28825/2?u=ogiewon
1 Like

Great project, looks really nice. Impressed that an Arduino could accomplish that. It feels like a Raspberry could be a better alternative for the longer run, what do you think? I haven’t really looked through every comment in this thread, obviously, so I might have missed that discussion already!

Thanks for the feedback… The SmatThings ThingShield is designed specifically for an Arduino. Thus, an Arduino is the best, lowest cost platform to run it on. You can pick up an Arduino MEGA 2560 clone for about $15 on eBay. Raspberry Pi’s are typically $35+, especially the Pi 3’s. Also, the ThingShield is designed for 5V TTL logic, not 3.3V like a PI…

If I were to integrate a Pi, I would do a pure Ethernet solution, but still try to route all communications through the ST Hub.

I like the Arduino platform due to its very low cost, high performance I/O, and widespread adoption in the sensor/actuator space of embedded electronics. I also prefer not having an operating system to worry about, nor the heftier power requirements.

Both platforms have their uses, and have done an incredible job of opening up the small embedded controller market to the hobbyist.

1 Like

Ok, thanks for the answer!

Hi dan.
I really want to thank you for this. Ive veen playing withbyour project and is awesome. However, Ive a small issue with the motion sensor, im uaing a generic pir and the app is intermitently detecting the motion and I realised that if I try to turn on the switch when motion is detected it takes about 10 seconds. Is the any way to first hold the status of the sensor when it detects motion ? And second, is posible to reduce the time that the arduino takes to execute the switching?
Thanks gor your help!!

Raspberry Pi Zeros are $5. Of course you’ll need to drop another $5 or more for a microSD card (which is pretty funny when you think about it).

@DParker Yea, the Pi Zero is interesting, but not available for $5 anywhere in the US that I’ve found. Demand is just way too high. Also, the Zero has no Ethernet/Wifi built in. So you’re going to need to add that too, along with the micro sd card. It also is not voltage compatible with the ST ThingShield, and I haven’t seen anyone port the library yet. So, while Pi is interesting, it really is not an Arduino replacement, especially in terms of power consumption.

If want to try Arduino on the cheap, you can get Arduino Nano clones on eBay for about $4 shipped from China. This is the lowest cost entry point that I have seen. I’ve bought several and they work very well. I’ve just ordered an esp8266 to try. That looks like another low cost, very capable platform with built in WiFi.

The motion sensor class relies on the PIR motion sensor to adjust sensitivity and the delay between events. Usually there is also a jumper that changes whether the sensor sends a pulsing signal when motion is sensed versus a constant high or low for motion/no motion. You need to set it for a constant signal, not a pulse train.

As for any delay between sensing motion and turning on a switch, that is not typical whatsoever.

I have one that I got for $5 at MicroCenter. They’re still that price there. They’re frequently sold out, but you can order one at that price. Adafruit also sells them at that price (though also backordered). You just need to check sites frequently.

Ditto Arduinos.

No, but a compatible version of TS could be made…which is I suspect what was being contemplated above.

A replacement? No, of course not…nor is the Arduino a replacement for something like the Pi. I think the point was that there are applications where the Pi (or the functional equivalent thereof) would be a better choice.

True. Also irrelevant if your solution can be plugged in all the time…like an awful lot of other things that ST works with.

Yeah, I’ve got several of those (as well as some $6 Uno and $10 Mega 2560 clones), all available locally at MicroCenter.

Yep. You can also use it directly with any Pi.

Hi Dan
I have another question, Why with ST_Anything_Alarm_Panel is not necessary to have a Multiplexer.smartapp if you are including many devices of the same type. From the ST_Anything_Relays project I understood that you need 1) the app 2) Multiplexer.smartapp and 3) the virtual device. But in this case, you just have the 1) App Could you please give us a small explanation of how it is work I’m a bit confuse now.
Thanks

ST_Anything_Alarm_Panel Was just a sample I created for a specific user’s need. The Arduino sketch plus the Device Handler are a matched pair that allows one to view all of the sensors from within the ST App on your phone. However, without a multiplexer and virtual devices, none of the sensors can be individually selected from other SmartApps.

Continuing the discussion from Announcing the "ST_Anything" Arduino/ThingShield Project:

Hello Dan
Thanks for that, I have another question, I 've been trying to modify your project to have just 4 relays, so far everything is working well, I have control of each relay and the push buttons work perfectly even if the hub is down. Nevertheless, I tried to create an app to turn on the relays when motion my sensor detects that the door is open and the app doesn’t work any idea what could be the problem. I am wondering if I’m able to use other devices to trigger the relays


this the groovy smart app
/**

  • ST_Anything_Relays Multiplexer - ST_Anything_Relays_Multiplexer.smartapp.groovy
  • Copyright 2015 Daniel 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-03-27 Dan Ogorchock Original Creation

*/
definition(
name: “ST_Anything_Relays Multiplexer”,
namespace: “ogiewon”,
author: “Daniel Ogorchock”,
description: “Virtual Switches to Arduino Relays Multiplexer/Demultiplexer”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)

preferences {
section(“Select the Relays (Virtual Switch devices)”) {
input “virtual_switch_1”, title: “Virtual Switch for Relay 1”, “capability.switch”, required: true
input “virtual_switch_2”, title: “Virtual Switch for Relay 2”, “capability.switch”, required: false
input “virtual_switch_3”, title: “Virtual Switch for Relay 3”, “capability.switch”, required: false
input “virtual_switch_4”, title: “Virtual Switch for Relay 4”, “capability.switch”, required: false

}

section("Select the Arduino ST_Anything_Relays device") {
	input "arduino", "capability.switch", required: true
}    

}

def installed() {
log.debug “Installed with settings: ${settings}”
subscribe()
}

def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
subscribe()
}

def subscribe() {

    subscribe(arduino, "switch1.on", switch1on)
    subscribe(arduino, "switch1.off", switch1off)
    subscribe(virtual_switch_1, "switch.on", relay1on)
    subscribe(virtual_switch_1, "switch.off", relay1off)

if (virtual_switch_2) {
    subscribe(arduino, "switch2.on", switch2on)
    subscribe(arduino, "switch2.off", switch2off)
    subscribe(virtual_switch_2, "switch.on", relay2on)
    subscribe(virtual_switch_2, "switch.off", relay2off)
}

if (virtual_switch_3) {
    subscribe(arduino, "switch3.on", switch3on)
    subscribe(arduino, "switch3.off", switch3off)
    subscribe(virtual_switch_3, "switch.on", relay3on)
    subscribe(virtual_switch_3, "switch.off", relay3off)
}

if (virtual_switch_4) {
    subscribe(arduino, "switch4.on", switch4on)
    subscribe(arduino, "switch4.off", switch4off)
    subscribe(virtual_switch_4, "switch.on", relay4on)
    subscribe(virtual_switch_4, "switch.off", relay4off)
}

if (virtual_switch_5) {
    subscribe(arduino, "switch5.on", switch5on)
    subscribe(arduino, "switch5.off", switch5off)
    subscribe(virtual_switch_5, "switch.on", relay5on)
    subscribe(virtual_switch_5, "switch.off", relay5off)
}

if (virtual_switch_6) {
    subscribe(arduino, "switch6.on", switch6on)
    subscribe(arduino, "switch6.off", switch6off)
    subscribe(virtual_switch_6, "switch.on", relay6on)
    subscribe(virtual_switch_6, "switch.off", relay6off)
}

if (virtual_switch_7) {
    subscribe(arduino, "switch7.on", switch7on)
    subscribe(arduino, "switch7.off", switch7off)
    subscribe(virtual_switch_7, "switch.on", relay7on)
    subscribe(virtual_switch_7, "switch.off", relay7off)
}

if (virtual_switch_8) {
    subscribe(arduino, "switch8.on", switch8on)
    subscribe(arduino, "switch8.off", switch8off)
    subscribe(virtual_switch_8, "switch.on", relay8on)
    subscribe(virtual_switch_8, "switch.off", relay8off)
}

if (virtual_switch_9) {
    subscribe(arduino, "switch9.on", switch9on)
    subscribe(arduino, "switch9.off", switch9off)
    subscribe(virtual_switch_9, "switch.on", relay9on)
    subscribe(virtual_switch_9, "switch.off", relay9off)
}

if (virtual_switch_10) {
    subscribe(arduino, "switch10.on", switch10on)
    subscribe(arduino, "switch10.off", switch10off)
    subscribe(virtual_switch_10, "switch.on", relay10on)
    subscribe(virtual_switch_10, "switch.off", relay10off)
}

if (virtual_switch_11) {
    subscribe(arduino, "switch11.on", switch11on)
    subscribe(arduino, "switch11.off", switch11off)
    subscribe(virtual_switch_11, "switch.on", relay11on)
    subscribe(virtual_switch_11, "switch.off", relay11off)
}

if (virtual_switch_12) {
    subscribe(arduino, "switch12.on", switch12on)
    subscribe(arduino, "switch12.off", switch2off)
    subscribe(virtual_switch_12, "switch.on", relay12on)
    subscribe(virtual_switch_12, "switch.off", relay12off)
}

if (virtual_switch_13) {
    subscribe(arduino, "switch13.on", switch13on)
    subscribe(arduino, "switch13.off", switch13off)
    subscribe(virtual_switch_13, "switch.on", relay13on)
    subscribe(virtual_switch_13, "switch.off", relay13off)
}

if (virtual_switch_14) {
    subscribe(arduino, "switch14.on", switch14on)
    subscribe(arduino, "switch14.off", switch14off)
    subscribe(virtual_switch_14, "switch.on", relay14on)
    subscribe(virtual_switch_14, "switch.off", relay14off)
}

if (virtual_switch_15) {
    subscribe(arduino, "switch15.on", switch15on)
    subscribe(arduino, "switch15.off", switch15off)
    subscribe(virtual_switch_15, "switch.on", relay15on)
    subscribe(virtual_switch_15, "switch.off", relay15off)
}

if (virtual_switch_16) {
    subscribe(arduino, "switch16.on", switch16on)
    subscribe(arduino, "switch16.off", switch16off)
    subscribe(virtual_switch_16, "switch.on", relay16on)
    subscribe(virtual_switch_16, "switch.off", relay16off)
}

}

//--------------- Relay 1 handlers ---------------
def switch1on(evt)
{
if (virtual_switch_1.currentValue(“switch”) != “on”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping On Virtual Switch to match Arduino”
virtual_switch_1.on()
}
}
def switch1off(evt)
{
if (virtual_switch_1.currentValue(“switch”) != “off”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping Off Virtual Switch to match Arduino”
virtual_switch_1.off()
}
}
def relay1on(evt)
{
if (arduino.currentValue(“switch1”) != “on”) {
log.debug “relay1event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning On Arduino Relay to match Virtual Switch”
arduino.switch1on()
}
}
def relay1off(evt)
{
if (arduino.currentValue(“switch1”) != “off”) {
log.debug “relay1event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning Off Arduino Relay to match Virtual Switch”
arduino.switch1off()
}
}

//--------------- Relay 2 handlers ---------------
def switch2on(evt)
{
if (virtual_switch_2.currentValue(“switch”) != “on”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping On Virtual Switch to match Arduino”
virtual_switch_2.on()
}
}
def switch2off(evt)
{
if (virtual_switch_2.currentValue(“switch”) != “off”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping Off Virtual Switch to match Arduino”
virtual_switch_2.off()
}
}
def relay2on(evt)
{
if (arduino.currentValue(“switch2”) != “on”) {
log.debug “relay2event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning On Arduino Relay to match Virtual Switch”
arduino.switch2on()
}
}
def relay2off(evt)
{
if (arduino.currentValue(“switch2”) != “off”) {
log.debug “relay2event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning Off Arduino Relay to match Virtual Switch”
arduino.switch2off()
}
}

//--------------- Relay 3 handlers ---------------
def switch3on(evt)
{
if (virtual_switch_3.currentValue(“switch”) != “on”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping On Virtual Switch to match Arduino”
virtual_switch_3.on()
}
}
def switch3off(evt)
{
if (virtual_switch_3.currentValue(“switch”) != “off”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping Off Virtual Switch to match Arduino”
virtual_switch_3.off()
}
}
def relay3on(evt)
{
if (arduino.currentValue(“switch3”) != “on”) {
log.debug “relay3event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning On Arduino Relay to match Virtual Switch”
arduino.switch3on()
}
}
def relay3off(evt)
{
if (arduino.currentValue(“switch3”) != “off”) {
log.debug “relay3event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning Off Arduino Relay to match Virtual Switch”
arduino.switch3off()
}
}

//--------------- Relay 4 handlers ---------------
def switch4on(evt)
{
if (virtual_switch_4.currentValue(“switch”) != “on”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping On Virtual Switch to match Arduino”
virtual_switch_4.on()
}
}
def switch4off(evt)
{
if (virtual_switch_4.currentValue(“switch”) != “off”) {
log.debug “arduinoevent($evt.name: $evt.value: $evt.deviceId)”
log.debug “Flipping Off Virtual Switch to match Arduino”
virtual_switch_4.off()
}
}
def relay4on(evt)
{
if (arduino.currentValue(“switch4”) != “on”) {
log.debug “relay4event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning On Arduino Relay to match Virtual Switch”
arduino.switch4on()
}
}
def relay4off(evt)
{
if (arduino.currentValue(“switch4”) != “off”) {
log.debug “relay4event($evt.name: $evt.value: $evt.deviceId)”
log.debug “Turning Off Arduino Relay to match Virtual Switch”
arduino.switch4off()
}
}

AND THIS IS THE DEVICE HANDLER
/**

  • ST_Anything_Relays - ST_Anything_Relays.device.groovy
  • Copyright 2015 Daniel 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-03-27 Dan Ogorchock Original Creation

*/

metadata {
definition (name: “ST_Anything_Relays”, namespace: “ogiewon”, author: “Daniel Ogorchock”) {
capability “Actuator”
capability “Switch”

	attribute "switch1", "string"
	attribute "switch2", "string"
	attribute "switch3", "string"
	attribute "switch4", "string"
    
	
	command "switch1on"
	command "switch1off"
	command "switch2on"
	command "switch2off"
	command "switch3on"
	command "switch3off"
	command "switch4on"
	command "switch4off"

}

simulator {
}


// tile definitions
tiles {

    standardTile("switch1", "device.switch1", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch1on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch1off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}

    standardTile("switch2", "device.switch2", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch2on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch2off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}
    
    standardTile("switch3", "device.switch3", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch3on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch3off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}
    
    standardTile("switch4", "device.switch4", width: 1, height: 1, canChangeIcon: true) {
		state "off", label: '${name}', action: "switch4on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		state "on", label: '${name}', action: "switch4off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
	}

           main (["switch1"])
    details (["switch1","switch2","switch3","switch4"])
}

}

//Map parse(String description) {
def parse(String description) {
def msg = zigbee.parse(description)?.text
log.debug “Parse got ‘${msg}’”

def parts = msg.split(" ")
def name  = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null

name = value != "ping" ? name : null

def result = createEvent(name: name, value: value, isStateChange: true)

log.debug result

return result

}

def switch1on() {
log.debug “Executing ‘switch1on’ = ‘switch1 on’”
zigbee.smartShield(text: “switch1 on”).format()
}

def switch1off() {
log.debug “Executing ‘switch1off’ = ‘switch1 off’”
zigbee.smartShield(text: “switch1 off”).format()
}

def switch2on() {
log.debug “Executing ‘switch2on’ = ‘switch2 on’”
zigbee.smartShield(text: “switch2 on”).format()
}

def switch2off() {
log.debug “Executing ‘switch2off’ = ‘switch2 off’”
zigbee.smartShield(text: “switch2 off”).format()
}

def switch3on() {
log.debug “Executing ‘switch3on’ = ‘switch3 on’”
zigbee.smartShield(text: “switch3 on”).format()
}

def switch3off() {
log.debug “Executing ‘switch3off’ = ‘switch3 off’”
zigbee.smartShield(text: “switch3 off”).format()
}

def switch4on() {
log.debug “Executing ‘switch4on’ = ‘switch4 on’”
zigbee.smartShield(text: “switch4 on”).format()
}

def switch4off() {
log.debug “Executing ‘switch4off’ = ‘switch4 off’”
zigbee.smartShield(text: “switch4 off”).format()
}

THANKS

Did you manually create 4 virtual switches using the code in my github? Then link those 4 virtual switches to the Arduino via the Multiplexer SmartApp.

Then, when’re asked for a switch by another SmartApp, such as SmartLighting, be sure to use one of the virtual switches, not the Arduino.