SanthoshKumar
(Santhosh Kumar Rajendran)
January 5, 2018, 7:34am
1
Hi folks,
Context : I want to relay whether a room is occupied or not based on the motion sensor events.
So, this has two parts :
Implementing the SmartApp that maintains the state (based on motion sensor events) and exposes the APIs that provide this state. I believe I have completed this part here .
Make the REST API calls to this SmartApp to get the occupancy data.
I’m completely lost on Step-2 now !! I’m following this guide to make the REST request to the SmartApp. I’ve written the following python code so far :
import requests
payload = {'response_type': 'code',
'client_id': '2e5a6ffb-6bfa-4c47-bde4-7398bfb76196',
'scope': 'app',
'redirect_uri': 'http://getHuddleRoomsStatus.com'}
r = requests.get('https://graph.api.smartthings.com/oauth/authorize', params=payload)
print r.content
But I don’t see any “Authorization Code” present in the response (which is apparently needed for the next step).
Could someone please help me out here on what I’m missing.
For reference this is a continuation of this post : Access Device Methods inside runIn()
Cheers,
Santhosh
SanthoshKumar
(Santhosh Kumar Rajendran)
January 5, 2018, 7:35am
2
If there is a better way to do Step-2 (via python) please please let me know about that too !
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
January 5, 2018, 8:51am
3
Why not use the new API instead of the one on the way to being deprecated?
Fellow developers,
As many of you know, we recently made some announcements at SDC around the SmartThings Cloud. We’ll be providing more information about this soon, but one thing worth calling out is that the new API (it’s REST!) is already available!
While some of the APIs are specific to the new SmartApp model , the /devices and /locations APIs can be used just like any other REST API. All you need is a personal access token, which you can get here .
Example CLI Tool
[image]
To highlight some of the APIs, we wrote a simple CLI tool as an example. It allows you to get information about and control your devices, through a simple Command Line Interface. More importantly, it shows how you might use the API for your own projects. It’s open-sourced, and you can find the repository here .
W…
SanthoshKumar
(Santhosh Kumar Rajendran)
January 5, 2018, 4:19pm
4
Wait !!! Does this mean that I don’t even need the SmartApp running ? All I need to do is get the Access-Token and get the Devices’ Status via the API calls ?
Also, Thanks a lot @tgauchat !! You seem to come to my rescue everywhere
SanthoshKumar
(Santhosh Kumar Rajendran)
January 5, 2018, 4:40pm
5
As I understand, all we have to do is
Obtain the OAuth token from https://account.smartthings.com/tokens
Use the above to create GET/PUT/etc… (referring the ST-API Documentation )
And the above should give me the power to get status, turn on/off devices etc… ?
This sounds too good to be true !!! Please tell me that there’s no “But” here !
tgauchat
(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy)
January 5, 2018, 8:39pm
6
It’s definitely not going to be as easy or straightforward as it sounds; “but” it’s better than the old way.
SanthoshKumar
(Santhosh Kumar Rajendran)
January 5, 2018, 9:24pm
7
I’ll take what I get. Will update if I am successful in my attempt.
Thanks for all the help @tgauchat !