Standalone Application capable of listing and controlling devices


(kapil) #1

Dear all,

I am a newbie , started working on web app to list and control devices in one location.
i could write REST calls for logging and getting location and devices details.
for example below function sends get request for fetching devices for a location:
sendGetRequest(endpoint + “/api/locations/” + locationId + “/devices?” + “access_token=” + token, callback);

How to change status for one device from a web app?


#2

I think @mager can help you!


(Alex) #3

@kapil1211, welcome to the game.

Check out my project and look at the source to find more than you ever wanted to know about REST calls:
http://action-dashboard.github.io/


(kapil) #4

thanks alex, i have a quick view on your work.
And followed mentioned steps, but after opening url in browser i just get one grey box with “Refresh button”.
Am i missing something here ?

FYI: I dont have smart hub or actual devices yet, so is there any depenency for those?


(Alex) #5

If you have no devices what do you expect to see on a dashboard?


(kapil) #6

1.i have added virtual device in my Home Location, will not this be shown ?
2.Where can i find complete list for API like :
https://graph.api.smartthings.com/api/locations?access_token=***** (to fetch the location using access token)
like this way if there any post/get request to change state of a particular devide_id ?

Please correct me if i misunderstood something, meanwhile i am going through docs and learning more :slight_smile:


(kapil) #7

I could ad Virtual device in your dashbroad through ST Android App, and now it reflects in dashboard :slight_smile:

And here is my understanding:
But for changing the state of a device- lets say switch on/off a Bulb,
i need to write a web all from my html web app, which will be interpreted by groovy code.
And there i can change the state. (thats i could understand your code)

Is this correct ?

And good news is i just received my Smart Hub Kit with basic sensors , so now i can start practically :wink:


(Alex) #8

You create your own API, it doesn’t have to be a web app.

Refer to this document to get started:

http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/index.html


(kapil) #9

Thanks for your reply, but my actual requirements is to control devices through my Webapp (not through from SmartThing Android APK or other applications like you have developed)

Altough its doing the same thing, basically i want to mimic the same in my WebApp.
(But i am new to HTML/REST etc, so kind of asking basic doubts)

As mentioned i want to change the device state through my HTML page,
would be happy to hear your inputs.


(Andrew Mager) #10

Here’s an example of how to control a switch with a REST API: https://github.com/SmartThingsCommunity/Code/blob/master/smartapps/hackathon-demo/restful-switch.groovy

It more or less uses the tutorial Alex posted.


(kapil) #11

thanks @mager, i am looking for same.
Is there any public JS code also for this project ?
TIA.