Using iRule to control SmartThings

Hi all,

I’ve never been a fan of the SmartThings mobile app, it’s not very customizable, it crashes occasionally, and the dashboard is just plain wrong most of the time. A few months ago I decided to try my luck at using iRule to control all of my ST devices. It’s working out pretty well so far, creating a REST API smart app was pretty easy and while getting everything loaded into iRule was a bit of a pain, it wasn’t particularly difficult. As a side benefit, using iRule gives you full control over TV and media devices that really isn’t possible using ST today. I made a quick video of my setup, let me know what you think.


Interesting… just a side note. you might edit your post and just enter the YouTube link only and not use the insert link feature. That way it will embed the video for you and we don’t have to jump out to another browser and lose the thread.

My question is can you show more details here on how you did the REST API etc. I am not familiair with iRule but am trying to see this compared to Logitech Harmony.

That’s pretty snazzy, thanks for the tip.

So the smartapp exposes simple endpoints that iRule can hit. iRule can more or less integrate with any IR (through a Global Cache device) or HTTP endpoint. Once you have the endpoints its just a matter of creating an ST device in iRule and adding the various commands/endpoints.

IE. Here’s my switch endpoint, you can do a GET to /switches and list all of them (useful for an iRule page that lists many switches) or a GET to a single switch (identified via device ID) or do a PUT to perform an action.

mappings { path("/switches") { action: [ GET: "listSwitches" ] }

path("/switches/:devid/:command") {
action: [
GET: “getSwitch”,
PUT: “setSwitch”

So as a test you should be able to CURL:
curl -H “Content-Type: application/json” -X PUT$INSTALLURL/switches/$UGLYDEVICEID/off

That’s all iRule is doing. Below is a screenshot of one of my commands for my ST device, I would have a matching command for off.

I haven’t used Logitech Harmony other than one of the older remotes, but I was in the same boat as you. I felt like going with the Harmony was going to be too limiting. Right now I can use iRule to completely control my TV, ST devices, receiver, Kodi, alarm system, etc. through one interface and it can be as simple or complex as I want to draw up in the builder.

I would suggest doing a trial of iRule and taking a look at the builder, it can be a little daunting at first with all the options but you can start with one of their templates, import a few devices, and just try out the functionality.

Just as a side note, if you want an easier iRule solution, you could use SmartTiles to control ST within iRule. iRule has a URL type object that loads a webpage within your iRule page (see my Kodi setup). You would then just need to setup multiple SmartTiles pages to split up your devices. I still use this setup on my tablet.

1 Like

Your reply was very helpful. Thanks!

Glad that tip helped :relaxed: FYI that tip applies in lots of areas; For example above I highlighted the text in your reply to me and a " quote reply pops up that you click on. It automatically embeds and formats it for you in the reply. Or if you just paste the whole URL link the system will automatically embed a snapshot version within your post. Or if you had say a product on Amazon that you wanted to help someone find just past the link and it embeds the details like this:

I’m trying to get control of my ecobee3 via irule. I understand basic irule integration, can you give me some specifics? Am I able to download your smartapp? What are the gateway settings you used in irule for the HTTP GET commands you’re using?

I have my ecobee’s added via the My Ecobee device by @yvesracine and I use his endpoints + the native ST thermostat device. I was originally using the community version but it kept losing connection every X many days so I switched to the My Ecobee and it works great. I’ve never had any issues with disconnecting.

In iRule my devices are as simple as:

name: Upstairs myEcobee - Away
data: thermostats/DEVICEID/away

name: Upstairs myEcobee - Heat level up
data: thermostats/DEVICEID/heatLevelUp

For my gateway endpoints I’m relaying everything through a web server so that I could quickly change my authorization header when I was playing with the setup. iRule has variables for the device code now so I would just add the auth header like this now:

name: Kitchen Dimmer 1 - Off
data: levels/DEVICEID/off?access_token=$VARIABLEWITHAUTHTOKEN

You should have 2 HTTP gateways (assuming you’re using a REST API like mine.) 1 setup as a GET and the other setup as a PUT. I use the GET to query state and the PUT to make some kind of a change. Both should point to on port 443.
In my case both of these point to my web server and I just forward them out to that same endpoint, I’m pretty sure I tested going direct to ST though and it worked fine.


Hope this helps!

Thank you so much!

I’m stuck on getting the access token. Do I need to add these get commands in the rest api smartapp?

I do remember jumping through those hoops, make sure OAUTH is enabled, do an install through the simulator, add a switch or 2, and run through those commands in CURL. You should get your auth token and then be able to test a device.

You should then be able to do:

curl -H “Authorization: Bearer THETOKENYOURECEIVED” “

And get a JSON response with the state of the switches you specified

Thank you so much, with your help I was able to get the curl commands to work to return status as well as do commands like change the temperature. I was also able to get the feedback to work in iRule and have it display values back from the thermostat. I am not able to have put commands work in iRule. I went back and forth with tech support and they determined it had to do with the access token and the header and that it wouldn’t work. You mentioned that you run it through a web server? Can you explain that process?

Glad you got it to work (partially anyway). I’m a little surprised the put commands aren’t working, I’ll have to try that out. Worst case you could probably modify the smartapp and make all the commands GET.
What I have right now is an IIS web server with two different sites listening on two different ports, one for GET and one for PUT. I have a rewrite rule set on each of those sites to take whatever query was sent to them and rewrite it to along with my authorization token as a header. You can do this with any web server that has some kind of a URL rewrite/proxy module, I just picked IIS because I know it the best. I went this route for a few different reasons, 1) At the time, I wasn’t aware that you could specify your authorization token as part of the query instead of the header 2) iRule doesn’t let you specify custom headers for HTTP gateways 3) If I need to change my token for whatever reason I can do it in IIS without having to make any changes to my device code in iRule.
I use split brain DNS to make this work both internally on my LAN as well as from the outside, ie. resolves to 192.168.x.x internally and the DDNS client on the server handles my dynamic external IP.


You mentioned that you’ve been able to get feedbacks working in ST - could you tell me how you did that?

Any luck getting the PUT commands to work also?

You could use actiontiles and do an http embed in iRule

1 Like

This is what I do, but when the page reloads I have to enter my credentials all over again. Do you have a way around that?

I installed your smartApp, but I’ve been reading and I can’t figure out how to connect to it so I can put and get data.

Any advice?

bump (10 characters)

Is this with iRule or something else?

Here are 3 examples (replace YOURINSTALLID, DEVICEID, and YOURTOKEN with the values that match your setup):

#List all switches and return some information about them

curl -H “Content-Type: application/json” -X GET

#Get generic state information about a specific level (dimmer)

curl -H “Content-Type: application/json” -X GET

#Issue a command to specific level device

curl -H “Content-Type: application/json” -X PUT

If you need to send a parameter with the command ie level value of 30 it should be /levels/DEVICEID/level=30?access_token=YOURTOKEN

As long as whatever program you’re using can do a PUT/GET similar to specified above it should work. You can also specify the access_token as a header.

This is for iRule. I can’t figure out how to get an access token or install ID. I’ve been reading the documentation, but I am still missing something.

Hi @JChand7751,

I’m getting the following error when trying to install you SmartApp from code:

startup failed: script1506651958239979987115.groovy: 190: expecting ‘)’, found ‘}’ @ line 190, column 14. } ^ 1 error

any advice? Thanks

Fixed! Please check the updated code.