API / OAuth Examples in Python, Node

Just a heads up that I’ve written a (fairly) well documented example of how to access the SmartThings API from Python & Node. This includes:

  • Groovy source code, demonstrating sending and receiving JSON payloads
  • an MQTT bridge, demonstrating listening to events
  • Python source, for getting and setting device state
  • Node-JS source, for the same (not quite complete)
  • an OAuth tool, for taking the pain away from getting tokens

The source and documentation for all this is here
https://iotdb.org/playground/oauthorize/smartthings

The MQTT bridge is here:
https://iotdb.org/playground/mqtt

The OAuthorize tool is here:
https://iotdb.org/playground/mqtt

2 Likes

Intriguing… Couldn’t find the source and documentation though.

There’s related open-source project utilizing MQTT and MQTT-SN (wireless) for Home Automation – http://x13home.github.io/index_en.html. Check it out.

Sorry, suffering from cheering for Denver

2 Likes

@dpjanes: Awesome! I’ve been working on a similar project to feed events from non-ST devices into SmartThings and ended up using Xively.com as a bridge because of ST’s cumbersome authentication process (http://build.smartthings.com/forums/topic/temperature-sensor-with-embedded-chart/).
BTW, Xively also exposes its data streams via MQTT. That’s why I prefer it to ThingSpeak, since MQTT is more embedded-friendy than HTTP.

Oh nice. I’ve been playing with MQTT a bit (if you look on the Playground of IOTDB, there’s a connected home thing there that messages via MQTT also). I’ve stayed away from Xively only because I’m not sure if I have a $1000 / year budget to play with stuff!

In terms of your ST implementation, did you have to do the same thing I did - everyone has to install their own copy of the app source code in order to get a safe API key?

D.

Oh I see - they have a free developer option. Cool.

I just hope Xively will keep it free for developers :slight_smile:

My solution does not use an app. It’s a device type that relies on ‘polling’ property to update itself periodically. This worked quite well until last Saturday when SmartThings suddenly stopped polling. I don’t know if it’s a bug or a “feature”. If it does not resume, I could write my own polling app, I guess. With regards to installing the app, yes, copy-paste is the only way right now.

I saw your demo. Very nice! I think MQTT is an ideal messaging backbone for Home Automation – it’s lightweight, low footprint, low latency. This is perfect for all kind of connected WiFi devices. The MQTT broker can run either on a WiFi router or on a wall-mounted touch panel (essentially an iPad or an Android tablet). This would completely erase the dreaded ‘hub’ from the picture.

1 Like

It’s a shame that SmartThings doesn’t provide a MQTT (or CoAP) hub.

I really like what I see in the IOTDB.bridge groovy file you’ve created. I’m a little unsure if I am supposed to setup my own MQTT server to implement this in my own smartapps or if I am supposed to work with the bridge smart app some other way.

I was using HiveMQ MQTT server - it’s kinda flaky though (I do like HiveMQ’s MQTT implementation). Eclipse also has a public MQTT server. IOTDB might offer production-level MQTT services for some small amount of money in the future (10¢/month) but it’s not high on my priority list at this point.

I’m really struggling to write to an MQTT test server from within the smartthings web IDE. I can read and write to to http://test.mosquitto.org/ using local python scripts but not from the web IDE. Does your code successfully write to HiveMQ’s servers?

Sorry, I just saw this message. I bridge my messages through a HTTP server on iotdb.org

Hello David, I’ve been trying to implement the bridge but have not been able to get oauth work. When I execute the pythn code I get an error: switchd[‘url’] = “%s/%s” % ( devices_url, switchd[‘id’], ) TypeError: string indices must be integers
Tracing this error led me to check the request which brings nothing back with an error “Access denied” for the specified access token. I tried erasing the smartapp and creating a new one with a new token but had the same error. Am I missing something? I appreciate your help.

You’re responding to an archived message that’s almost 3 years old.

I suggest instead you ask in the current developers section of the forum:

https://community.smartthings.com/c/developers

Someone there should be able to help you.