Git Product home page Git Product logo

smartthings-rest-api's Introduction

SmartThings REST API

Setup

Installation

  1. Login at https://graph.api.smartthings.com/
  2. Navigate: My SmartApps > New SmartApp > From Code (tab)
  3. Paste contents of rest-api.groovy
  4. Click: Create, Publish > For Me
  5. Navigate: App Settings > OAuth
  6. Click: Enable OAuth in Smart App
  7. Note the Client ID (i.e. abc123) and Client Secret (i.e. def321)

Get Access Token via OAuth

  1. Replace the client_id value and open this URL in a browser: https://graph.api.smartthings.com/oauth/confirm_access?response_type=code&scope=app&redirect_uri=http%3A%2F%2Flocalhost&client_id=abc123
  2. Login and Click "Authorize".
  3. You will be redirected to http://localhost; note the code query value (i.e. aD4kF5 in http://localhost/?code=aD4kF5)
  4. Run curl -v -H "Content-Type: application/x-www-form-urlencoded" -X POST --data 'grant_type=authorization_code&code=aD4kF5&client_id=abc123&client_secret=def321&redirect_uri=http%3A%2F%2Flocalhost' https://graph.api.smartthings.com/oauth/token
  5. Note access_token in response (i.e. xyz123). This will be the access token used to authenticate to the REST API.
  6. Run curl -v -H "Authorization: Bearer xyz123" https://graph.api.smartthings.com/api/smartapps/endpoints
  7. Note the uri value (i.e. https://graph1.smartthings.com/api/smartapps/installations/123987). This will be the Endpoint URL used to access the REST API.

Usage

(Assumming Access Token: xyz123 and Endpoint URL: https://graph1.smartthings.com/api/smartapps/installations/123987)

List Devices

curl -v -H "Authorization: Bearer xyz123" \
  https://graph1.smartthings.com/api/smartapps/installations/123987/devices

Get Device Attribute (i.e. on/off for a switch)

curl -v -H "Authorization: Bearer xyz123" \
  https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/attribute/switch

Turn Device On

curl -H "Authorization: Bearer xyz123" -X POST \
  https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/on

Turn Device Off

curl -H "Authorization: Bearer xyz123" -X POST \
  https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/off

Adjust Brightness to 50%

curl -H "Authorization: Bearer xyz123" -X POST \
  https://graph1.smartthings.com/api/smartapps/installations/123987/device/123/command/setLevel?arg=50

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.