After experimenting with various scheduling SmartApps last night, the Smart Lighting app is working now. Perhaps removing and reinstalling it during testing did the trick, I’m not sure. In any case, as of now it’s all good. Thanks.
I strongly suggest not using ST as a home alarm, it is no where reliable enough for that. I miss state changes all the time and you will have periods of it just not giving you any status for an hour or two.
I’m aware of the limitations of ST. Right now, I get push notifications if a door opens. It works well enough. (Certainly better than no alarm at all.)
Thanks.
I’m getting the same compile errors. Did you find a solution?
Looks like you have a version of the SmartThings library in the Program Files folder. Remove that copy of the SmartThings library and follow my ReadMe in the Github Repository from the original post.
Also, please make sure you’re using a fairly recent version of the Arduino IDE. I personally use v1.6.5.
I am going to use this project for my garage doors as you already have most of the code necessary for that in place (very helpful!). Anyway, I was wondering if you can have multiple device types per arduino smartthings shield? That way, you can use a single shield as a sort of “hub” and have multiple arduinos communicate with the arduino with the shield. I ask this because the ST shield is a bit pricey.
Only one ST DeviceType is allowed per Arduino, however you can use Virtual Devices in conjunction with one of my Multiplexer SmartApps to allow multiple similar devices per Arduino. Check out my ST_Anything_Doors example. It has dual garage doors, 4 house doors, temperature/humidity, and motion.
I’ve contemplated adding local wireless sensor support using code from MySensors.org. If you decide to add local wireless sensor support, I’d be happy to add it into the main ST_Anything library.
This is great. Exactly what I was looking for.
However, I have a few questions…
The Thingshield is $30 from the Smarthings website and would represent 300% of the cost of a generic Arduino board plus the wires, capacitors, etc so i’m wondering if there is a more cost effective method to get an Arduino online my Smartthings Hub?
I’ve seen a Xbee board online and wondering if that’s an option?
If not, I’ll be buying these shields and doing all the above. Awesome work and many thanks to all that contributed.
I don’t recommend using an Uno. The hardware serial that the Mega supports, not to mention extra pins and memory make it a better choice.
Keep in mind, you can run many things on one Arduino, and most of those things would be at least $30 each, so it’s not hard to justify the cost.
My son and I have added two new capabilities to the ST_Anything library.
-
The library now supports the ability for the Arduino Sketch to subscribe to the data stream that is sent to the ST Cloud via the ThingShield. This allows your user created sketch to be aware of changes to your various sensors and perform some sort of local processing within the sketch.
-
The library now exposes to your sketch the function within the ST_Anything library that handles receiving a command from the ST Cloud. This will allow you to easily issue a command to one of your ST_Anything devices from within your sketch.
Combined, these two features now permit local processing of events within the Arduino, which is especially useful for time-critical actions that cannot tolerate the latency from the ThingShield-to-DeviceType-to-SmartApp-to-Devicetype-to-Thingshield round trip.
Please update your ST_Anything library’s Everything.h and Everything.cpp from the GitHub repository at https://github.com/DanielOgorchock/ST_Anything/tree/master/Arduino/libraries/ST_Anything
You will also find a new Arduino sketch that shows the proper usage of these new capabilities. The example sketch is named ST_Anything_wCallback.ino and can be found at https://github.com/DanielOgorchock/ST_Anything/tree/master/Arduino/Sketches/ST_Anything_wCallback
Here is an example of the local callback routine within your sketch that will need to be defined to use this feature. Please know that this is not required, but is an optional feature.
//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine. This is a sniffer to monitor
// data being sent to ST. This allows a user to act on data changes locally within the
// Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
Serial.print(F("ST_Anything_wCallback: Sniffed data = "));
Serial.println(msg);
//TODO: Add local logic here to take action when a device's value/state is changed
//Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud
st::receiveSmartString("Put your command here!"); //use same strings that the DeviceType would send
}
And here is the command to register the above callback function within your sketch’s setup() routine.
st::Everything::callOnMsgSend = callback;
These snippets are taken directly from the sample sketch, ST_Anything_wCallback.ino.
Hi Todd. Thank you for the suggestion. I will take a look at the Mega. This is my first foray into these hardware options.
Regarding the price of the SmartThings shield, I agree that we can do many things with it but I was thinking the low cost of the Arduino means I can do many small projects and the $30 cost of the SmartThings shield makes it prohibitively expensive. Maybe less projects would be “connected” as I doubt I’ll put 10 x $30 shields on the $5 projects.
Is there any other options? I looked at the Xbee shield but those didn’t cut it.
Hi @oglewon, thanks for this very nice work, you library is amazing. I’m trying to do a little project with your library but I am having trouble with the arduino mega. The shield works fine on the arduino uno. but on the on the arduino mega it sends information to the hub but does no receive anything. I did the jumper between the pins 14-2 and 15-3. I tested the serial port of the arduino mega and it seams to be working fine. Is there any other alteration that has to be done to use the shield on the arduino mega?
One more suggestion. Do you think you could incorporate MQTT on you library? With MQTT and the last update of the ST_Anything library we would have a very powerful platform. I have some working code here that I think wouldn’t be hard for you to include in your library.
```#include <Ethernet.h>
#include <MQTTClient.h> MQTT library by Joël Gähwiler (it can be obtained using Library Manager.
#include <SmartThings.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
char broker[] = "192.168.0.2";
EthernetClient net;
MQTTClient client;
unsigned long lastMillis = 0;
String str;
// Simulate a random change of state
char *water[]={"wet", "dry"};
char *motion[]={"inactive", "active"};
char *switch1[]={"on", "off"};
char *contact[]={"open", "close"};
char *alarm[]={"off", "strobe", "siren", "both"};
/************************* SmartThings Shield pins and variables *********************************/
#define PIN_THING_RX 15
#define PIN_THING_TX 14
SmartThingsCallout_t messageCallout; // call out function forward decalaration
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); // constructor
/************************* Sketch *********************************/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Smartthings MQTT Gateway");
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
client.begin(broker, net);
connect();
}
void connect() {
Serial.print("Connecting to MQTT Server...");
while (!client.connect("arduino", "try", "try")) {
Serial.print(".");
}
Serial.println("\nConnected!");
client.subscribe("house/command"); // Subscribe to a TOPIC
// client.unsubscribe("/example");
}
uint32_t x=0;
void loop() {
client.loop();
if(!client.connected()) {
connect();
}
smartthing.run(); // run smartthing logic
// update sensors after while
if(millis() - lastMillis > 100000) {
lastMillis = millis();
sensorsUpdate();
}
//can issue commands through serial monitor (just for test)
if(Serial.available() > 0) {
str = Serial.readStringUntil(’\n’);
Serial.println(str);
smartthing.send(str); // send message to cloud
}
}
void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
Serial.print("Broker: ");
Serial.print(topic);
Serial.print(" - ");
Serial.print(payload);
Serial.println();
smartthing.send(payload);
}
void messageCallout(String message) {
Serial.print("SmartThings: ");
Serial.println(message);
client.publish("house/smartthings", message);
smartthing.send(message);
}
// just for test
void sensorsUpdate() {
Serial.println(“Arduino: Updating sensors”);
smartthing.send("humidity " + String(random(100)));
delay(100);
smartthing.send("temperature " + String(random(100)));
delay(100);
smartthing.send("illuminance " + String(random(1000)));
delay(100);
smartthing.send("water " + String(water[random(2)]));
delay(100);
smartthing.send("motion " + String(motion[random(2)]));
delay(100);
smartthing.send("switch1 " + String(switch1[random(2)]));
delay(100);
smartthing.send("switch2 " + String(switch1[random(2)]));
delay(100);
smartthing.send("switch3 " + String(switch1[random(2)]));
delay(100);
smartthing.send("alarm " + String(alarm[random(4)]));
}```
Did you flip the switch on the thing shield? I forget what it needs to be, but on the ones I’ve bought, the default was wrong.
my switch is on 2-3. the shield works on the Uno. but on the Mega it send commands but do not receive any commands
Sounds like you may not be using my version of the SmartThings library… Or you have not properly selected the correct type of Arduino in the IDE. Please be sure to select MEGA 2560.
Wow. This kooks great. I’ve been swamped the past two days and haven’t had a chance to do anything with this. I’m hoping to get time this weekend.
For the call-back, do you have a sample smartapp we can use as a template? I’m thinking it would be kind of the reverse of your multiplexer that links a thing (or things) to an Arduino and when there is a state change, sends a message to the call-back.
Is that how you envision it working?
Thanks again.
Yes, please see the above section from my post. Should be a good starting point. This is all on the Arduino side, so no new SmartApp or DeviceType required.
This is the part I was asking about. In order to send a command from the cloud, I would assume we would need a smart app. I was thinking that an obvious example of this would be to send the state of a non-Arduino “thing” to the Arduino so the Arduino can take action on it.
So, similar to the multiplexer app, where the multiplexer app ties Arduino things to virtual sensors, this new smart app would tie Physical ST things to the Arduino, allowing Arduino code execution based on the thing and the state.
What other uses would you see for this?
Thank you.
Ahhh, I see the confusion. What the second part does, is allow your sketch to directly trigger the same Section of ST_Anything code which is executed whenever the ThingShield receives data from the cloud.
This allows your sketch to effectively emulate the ThingShield. What this enables is your sketch to directly affect the various sensors and devices that are usually only talked to via the ThingShield.
So, for example, you could use the new callback function to know immediately that a temperature has reached a certain value, and then using the second feature, you could trigger a local Arduino device to turn on or off.
This would give you true local control within the Arduino, when you have time critical processing to perform, while still fully integrated with SmartThings.
Recently, a user wanted a very unique timing sequence of two different relays, but wanted to still have them independently controllable via SmartThings. So when the first relay sent “switch1 off” to the ThingShield, indicating it was done, I could then immediately command “switch2 on”. By bypassing the SmartThings cloud, the correct timing of this relay sequence was maintained.
So, the intention of these new features is to allow one to develop their own “local rules processing” as needed.
Does that help clear it up?