Interested in Tasker, Voice Control and NFC for Android?

@coryds, Danny posted the tutorial for setting up the Endpoint access and pulling back the URLs for switches and locks. I’ve been struggling with figuring out how to get the URLs for the various Thermostat controls and sending commands to SmartApps. Maybe you could take a look and see if anything clicks?

http://build.smartthings.com/blog/tutorial-creating-a-custom-rest-smartapp-endpoint/

@chrisb, @av8rdude, @m203 meant to CC you on this as well. Any thoughts?

@csader When creating the tasker (http get) task…what was your Server:Port? Is this something I have to setup on my local network to forward a port to my smartthings hub? Or does this point to the smartthings web server somehow?
Then I guess the Path is the path generated by the sample code?
Thanks!
Scott

@csader One of my goals with tasker is to make a Panic Button tasker widget that will turn on a long list of lights. I have the links for each individual switch but I’m lost on how to do this with tasker…
Cheers,
Scott

@av8rdude, check out the Developer Office hours if you want to see my setup, but here’s the gist. Follow Danny’s instructions to set everything up, including the Oauth process in Step 4 (you either have to host the PHP in Step 4 on your own server or just use the Example Oauth page he linked to on ST servers). Then when you go to the Oauth PHP URL in your browser, you will be asked to authenticate using your ST login, and choose the switches you want to expose endpoints for. Do this on your Android phone because it’s much easier to copy/paste on there than trying to type it all in manually.

Then, you should be taken to a page listing your switches/locks that you authenticated, along with buttons for ON/OFF/Toggle. On your Android phone, tap & hold the On or Off or Toggle button you want to use in Tasker and tap “Copy Link Address”.

Go into Tasker, create a task with an HTTP GET action, and paste the full URL in the “Path” box. Now you need to delete “http://graph.api.smartthings.com/” from the beginning of that URL, leaving only “api/smartapps/…” and everything after that. (Important Note: make sure you remove the “/” before “api”).

Now go to the “Server:Port” box and type in “graph.api.smartthings.com” (Important Note: don’t type http:// or the ending / after.com)

Now save your task and test it out. It should work great.

@av8rdude, since you said you have the links, I’m assuming you got through the Oauth part. So follow my steps above for filling in the Server:Port and Path boxes, and repeat this process for all of the lights you want to control. For your Panic Button, you’ll want to make sure you use the On button links.

Now create the Panic Button profile for your widget and add all of the appropriate tasks you created for turning on those lights.

When you trigger the profile, you’ll notice that the lights turn on in succession, not all at once. That’s because it’s going through the list of HTTP GET calls one by one. That’s the best we can do for now.

Hope this helps. Let me know if you need clarification.

@csader Thank you so much for the detailed help. I managed to build about 20 tasks for various lights and switches. Also I got the tasker widget to work. It’s a very labor intensive method and I look forward to SmartThings developing widgets for the android platform soon. I would assume lots of people would really like a widget to control specific items or execute an app like Big Turn On/Off.
For the less capable IOS platform they could just build a stripped down version of the app that has a single customizable purpose :slight_smile:
Scott

So finally got some time to start looking into this… can I just say: Wow, I never knew how much I didn’t know!

Well, actually I did. A lot of what was pretty far beyond my meager knowledge. But I’m going to work on installing that demo app and see what I can learn from just playing with it.

Thanks @csader for the info on tasker too. That’s primarily what I think I’d use this stuff for.

@csader,

Follow Danny’s instructions to set everything up, including the Oauth process in Step 4 (you either have to host the PHP in Step 4 on your own server or just use the Example Oauth page he linked to on ST servers).

When I try to go to the linked Example Oauth I’m getting a Webpage Not Available error. Don’t have my own server, so can’t host it myself right now.

Hmmm yeah @chrisb it seems like someone must have deleted the PHP file from their servers. I get the same result when trying to access it from labs.smartthings.com.

I think you should be able to host it through Dropbox if you wanted…simple put it in your “Public” folder, then right click it and “Copy Public Link” to get the URL. Don’t quote me on that, though.

@csader, @megapixel, is there any other way than the php code to grab the access token?

FYI, I’m working on tutorials for all of this on my Project page here: http://build.smartthings.com/projects/tasker/

@csader, thank you for the tutorial.

Great Work Chris @csader!

is there any other way than the php code to grab the access token?

Sure, the PHP code was really just done to automate the process.

The following are the steps to go through for the manually.
Hit these URLs in your browser to grab the code, the access token and the endpoint (the same process done in the other code):

Note the inclusion of scope=app in the first two URLs

Step 1:
https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=YOURCLIENTID&redirect_uri=https%3A%2F%2Flocalhost&scope=app
Authorize your endpoint to access your account.

Step 2:
Ignore the fact that the page comes back blank and grab the code at the end of the URL.
Add THECODE to the end of this URL. Add YOURSECRET to the url below.

https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=YOURCLIENTID&client_secret=YOURSECRET&redirect_uri=https%3A%2F%2Flocalhost&scope=app&code=THECODE

The access token will be returned in a JSON object.

Step 3:
As a third step, we probably want to find the app endpoint url by requesting it with our access token :

https://graph.api.smartthings.com/api/smartapps/endpoints/YOURCLIENTID?access_token=YOURACCESSTOKEN

The url to the endpoint will then be returned. We could use that to interact with the maps we created.

I think it would be worthwhile to write some additional ways to simplify this process. Sounds like a good future project.

-D

1 Like

@megapixel, Thank you! I did the same with little help from fiddler. Is the access token valid for 50 years? The json object came back with a large number ( i am assuming it’s number of seconds )

Okay, getting off topic a bit here, but I’m still trying to get this whole php thing working properly for me. If I’ve uploaded the file to a hosting service and when I point my browser there I just get the text of the file, am I right in assuming that this service can’t run php?

@chrisb, i think so. check if they listed php on what they support and if you have to enable via a control panel or something.

Well, I’m getting closer… I think.

I found a place to host the PHP, and I can go through most of the steps just fine. The problem I’m having is on the last step of the PHP process, I’m not seeing any of the on/off/toggle boxes. I just get a blank page with:

Save the above URL (access_token) for future reference. Right Click on buttons to copy link address.

at the top. Not sure we’re I’m going wrong. I copied the SmartApp directly from megapix’s page, as well as the exampleOauth. I put in my client and secret codes, verified that they are correct. Just not sure where to go now.

Well, I finally got this up an running! The hosted php file from the tutorial is apparently working again. Still don’t know why my php file isn’t showing the icons, but it’s working off the SmartThings file so I’m happy.

Haven’t had an abundance of time to play with it, but what I have done is setup tasker apps on my kids tablets so they can control their own devices in their rooms. Yeah, I know… boring and something that could easily be done with the mobile app… BUT, if I installed the mobile app they’d have control of everything. And everything means the devices in the other kid’s room. That would not be cool to have them turning on/off each other’s lights or radios. No thanks.

Next up I’m gonna play with some of @csader’s tutorials with autovoice. Now if they’d just hurry up on start shipping the pressy I’d be happy!

Great use case, @chirsb. I’m curious what did the trick for you with the php setup.
Also, what icons did you add (the example definitely needed a better looking design)?

Thoughts that might help others:

Many hosts have error handling turned off by default.
When debugging, I would recommend turning on error handling at the start of the script (after <?php ):

error_reporting(E_ALL);
ini_set('display_errors', '1');

Also, the code also depends on using PHP CURL.
That extension is often installed by default, but not always.