smartthings

Interface with the SmartThings API

iotdb-smartthings

Well-documented code to:

  • Demo how to write using the SmartThings API
  • Control / Monitor SmartThings from Python
  • Control / Monitor SmartThings from Node-JS
  • Broadcast SmartThings events to MQTT

Courtesy of IOTDB. Follow us on Twitter:

  • @iotdb
  • @dpjanes

The SmartThings code broadcasts everything you do to MQTT. It's anonymous enough but you may find it creepy and it's easily turned off by editing smartthings.groovy.

This is somewhat developer-y. At some point we'll make a more general user friendly version of this.

git clone https://github.com/dpjanes/iotdb-smartthings.git

https://graph.api.smartthings.com/

If necessary, do what it takes to become a Developer

Go to:

https://graph.api.smartthings.com/ide/apps

Click on "+ New SmartApp"

Make sure to "Enable OAuth" and to copy the two values produced. You'll need them them later. Press the Create (or Update maybe) button. Authorize access to as much as your comfortable with, you can always change this later from your iPhone or Android app.

  • Press the Code button
  • Copy the code from smartthings.groovy and paste
  • Press Save
  • Press Publish

To access the API key, you need an access_token. Normally this is a real pain in the arse to generate, but we've done the hard work.

You'll need the OAuth Client ID and OAuth Client Secret, which you copied from the last major step. If you didn't, you can go back and get them now.

  • Go to this page: https://iotdb.org/playground/oauthorize/smartthings
  • Fill in the form
  • Press Submit
  • You'll be brought to the SmartThings website, where you'll allow access to your stuff
  • When that's done, you'll be brought back to IOTDB OAuthorize
  • copy the JSON data displayed and save it in a file called smartthings.json in the same directory

Keep that file to yourself. If you need to turn off access to your things, you can just go generate new OAuth keys in SmartThings.

If you add new devices to your SmartThings setup, you can give the API access using your SmartThings phone app.

$ python smartthings.py --type motion
[
  {
    "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 
    "label": "Motion LivingRoom", 
    "type": "motion", 
    "url": "http://graph.api.smartthings.com/api/smartapps/installations/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/motion/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 
    "value": {
      "motion": false, 
      "timestamp": "2014-02-03T13:30:31.361Z"
    }
  }
]
$ python smartthings.py --type switch --id "My Z-Wave Switch" --request switch=0
$ python smartthings.py --type switch --id "My Z-Wave Switch" --request switch=-1

A work in progress. The code is solid, but there's no command line argument parsing