• Stars
    star
    113
  • Rank 308,130 (Top 7 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Demonstration of how to write APIs that communicate with SmartThings

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

Important Notes

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.

Shards

If you are having trouble connecting to SmartThings, you may have to change your shard. Add to smartthings.json

"api_location": "<shard-url>"

You can find out your shard following the instructions here: https://community.smartthings.com/t/faq-how-to-find-out-what-shard-cloud-slice-ide-url-your-account-location-is-on/53923

Installation

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

Clone this project into a local directory

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

Log into SmartThings

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

If necessary, do what it takes to become a Developer

Create New App

Go to:

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

Click on "+ New SmartApp"

Fill in the App Details

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.

Add the code

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

Authorize

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.

API Access

Python

List all the motion detectors

$ 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"
    }
  }
]

Turn off a switch

$ python smartthings.py --type switch --id "My Z-Wave Switch" --request switch=0

Toggle a switch

$ python smartthings.py --type switch --id "My Z-Wave Switch" --request switch=-1

Node

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

More Repositories

1

node-iotdb

Easily control the Internet of Things using Semantics
JavaScript
47
star
2

iotdb-homestar

IOTDB / Home☆Star is an Open Source IoT Platform / API in Node.JS
JavaScript
35
star
3

iotdb-iotql

IoTQL - an SQL-like language for the IoT
JavaScript
16
star
4

iotdb-vocabulary

Semantic Vocab for the Internet of Things
Python
13
star
5

iotdb-arp

Scan the network for MAC addresses
JavaScript
6
star
6

iotdb-examples

Getting started with IOTDB - examples
JavaScript
5
star
7

iotdb-phant-client

Node Client for Phant
JavaScript
5
star
8

dart-x509csr

Create X.509 Certificate Signing Requests
Dart
5
star
9

homestar-alexa

IOTDB / HomeStar Module for talking to Alexa / Amazon Echo
JavaScript
4
star
10

alexa-opendata

Voice interface for Open Data
JavaScript
4
star
11

iotdb-crypto-example

Demonstrate Node's Crypto library
JavaScript
3
star
12

iotdb-commands

Apply Human-Like commands to Things
JavaScript
3
star
13

homestar-lifx

HomeStar / IOTDB Controller for LIFX Lights
JavaScript
3
star
14

iotdb-aws-cognito-digits-example

An Example of using AWS Cognito with Twitter / Fabric / Digits SMS Login
JavaScript
2
star
15

homestar-lg-smart-tv

HomeStar / IOTDB Controller for LG Smart TV
JavaScript
2
star
16

iotdb-recipes

IOTDB Recipes - JavaScript actions that look like Things
JavaScript
2
star
17

iotdb-models

Things - semantically described
JavaScript
2
star
18

iotdb-fs

Pipeline Oriented FS functions
JavaScript
1
star
19

iotdb-awslib

IOTDB AWS Library Functions
JavaScript
1
star
20

iotdb-transport

IOTDB Transporter - move IoT data around
JavaScript
1
star
21

iotdb-nlp

NLP functions
JavaScript
1
star
22

homestar-johnny-five

IOTDB / HomeStar Controller for Arduino / Firmata devices
JavaScript
1
star
23

homestar-smartthings

HomeStar / IOTDB Controller for SmartThings
JavaScript
1
star
24

homestar-wink

IOTDB / HomeStar Controller for Quirky / Wink Devices
JavaScript
1
star
25

homestar-denon-avr

HomeStar / IOTDB Controller for Denon AVR
JavaScript
1
star
26

iotdb-postgres

POP Postgres Module
JavaScript
1
star
27

homestar-ble

IOTDB / HomeStar Controller for Bluetooth Low Energy Devices
JavaScript
1
star
28

iotdb-thing

A new model for Things - experimental
JavaScript
1
star
29

homestar-coap

IOTDB / HomeStar Controller for CoAP Devices
JavaScript
1
star
30

iotdb-transport-iotdb

IOTDB / HomeStar Transport for IOTDB Things (!)
JavaScript
1
star
31

homestar-cookbook

Recipes for Home☆Star Runners
JavaScript
1
star
32

iotdb-aws-toolkit

Shell
1
star
33

iotdb-mqtt

HomeStar / IOTDB MQTT wrapper
JavaScript
1
star