SmartThings Rest API using Tasker

So recently the SharpTools Android app that allowed you to access SmartThings via Tasker was announced that it will be reaching out end of life cycle with the shutdown of groovy.

So I decided to work on figuring out how to access the API directly using tasker. I have included a link to the TaskerNet so you can get the tasks I have created and I am still currently working on.

IMPORTANT : You need to be using the Tasker Beta. You can join the beta program for Tasker here. Tasker Beta Program
You will also need this plugin for Tasker.
Autotools

SmartThings Rest API tasks.

Base Tasks from TaskerNet
Tasker SmartThings Rest API
More tasks and code snippets are available below on post #3. Those tasks are dependent on you having the base Tasks imported into Tasker.

If you don’t want to use that link and or sign up for the beta you can import the project using this XML .

Once you download it it will run a setup task asking for the bearer Token( PAT(Personal Access Token) your token will be saved in the %Bearer variable.

You can go here to obtain your token. SmartThings Personal Access Token .
Please keep this safe it is used to access your devices.

Next you will need to run the Build Database task. This will pull all device names and IDs and store them in a variable to be used by the other tasks.

Then you can use the tasks.

Get Device Info (Returns info about the device Device name, make,capabilitys, ect)
Get Device Status (Returns the status. on, off, open ,closed, ect)
These should be self explanatory. When you run them it will give you a list dialog to choose which device to use the an option for what command to send.

Device Tasks:

Turn Device On or Off
Turn Dimmer On And Set Level
Turn Dimmer On And Set Color
Open Or Close Garage Door

I still have some work to do on the create lock code and delete lock codes.

Locations Tasks :

Get Location IDs (returns the id of the location you want to use when working with scenes and rules.)

Get Location Mode(Returns the current location mode the hub is set to.)

Scene Tasks:

Run Scene or Execute Scene (Runs a scene that you have chosen with in the task.
Get Scene( Is used by the Run Scene task to obtain a list of scenes you have on your hub)

Rules API:
COMMING SOON!
I have working tasks for:
Getting Rules
Creating Rule
Updating Rule
Deleting A Rule

These are all still works in progress and I need to build and work out a better UI for it before it is ready to be released.

Finally thoughts:

All of these are just examples. You can go into the tasks and use only the Http Request action however you want. These were just intended to examples of how to use the API calls in Tasker.

Currently I have to worked out a way to mimic the event Subscriptions that SharpTools plugin for tasker did. That would allow you to react to events in SmartThings as in a door opening or a light being turned on. From my understanding this would require a dedicated smartapp and currently that is out of my wheel house and beyond my skill set at the moment.

I will be happy to help build new tasks and help troubleshoot any problems that occur. Also if you find this helpful and you create new tasks I think it would be amazing if you shared the Http Request body text so that other can use it in their projects.

[Update]
Location Mode Tasks

* Get Current location Mode
* Get All Locations / IDs
* Create Location Mode
* Rename Location Mode
* Delete Location Mode

21 Likes

Reserved for future posts.

1 Like

Code Snippets.

•Device controls

audioVolume capability
Body

{ “commands”: [ {
“component”: “main”,
“capability”: “audioVolume”,
“command”: “setVolume”,
“arguments”: [%yourVoumeSetting]
} ] }

doorControl capability
{{Command}} can be open or close
Body

{ "commands": [ { 
"component": "main", 
"capability": "doorControl", 
"command": "{{Command}}", 
"arguments": [] 
} ] }

setColorTemperature capability (warm white to cool white)1000K-30000k %colorTemperature is any number between 1000-30,000
Body

{ "commands": [ {
"component":"main",
"capability": "colorTemperature",
"command": "setColorTemperature",
"arguments": [%colorTemperature]
} ] }

colorControl capability (set colors of RGB bulb - hue 0 / saturation 100 = Red, hue 66.6666666667 / saturation 100 = Blue)
Body

{ "commands": [ {
"component": "main",
"capability": "colorControl",
"command": "setColor",
"arguments": [{
    "hue": "%colorHue",
    "saturation": "%colorSaturation",
    "level":"%colorLevel"
                        }]
 } ] }

Virtual Presence Sensor created using the CLI
Url

https://api.smartthings.com/virtualdevices/{{deviceId}}/events

Body : Change value to either present or not present

{
  "deviceEvents": [
    {
      "component": "main",
      "capability": "presenceSensor",
      "attribute": "presence",
      "value": "present"
    }
  ]
}

Roku Driver by @TAustin - Turn on or off device.

Body: Change command to either powerOn or powerOff

{ "commands": [ { 
   "component": "main", 
   "capability": "partyvoice23922.rokupower",
   "command": "powerOn",
   "arguments": [] } ] 
}

Here are some new code snippet for use with @philh30 schlage lock driver.

Set Alarm Mode (argument - (off, activity, tamper, forcedentry))

 {"commands": [ { "component": "settings", "capability": "platinummassive43262.schlageLockAlarm", "command": "setAlarmMode", "arguments": ["{{argumentMode}}"] } ] }

Set Tamper Sensitive (level (1-5))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.schlageLockAlarm", "command": "setTamperSensitivity", "arguments": [{{level}}] } ] }

Set Activity Sensitivity (level (1-5))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.schlageLockAlarm", "command": "setActivitySensitivity", "arguments": [{{level}}] } ] }

Set Forced Sensitivity (level (1-5))

{ "commands": [ { "component": "settings", "{ "commands": [ { "component": "settings", "capability": "platinummassive43262.vacationMode", "command": "off", "arguments": [] } ] }capability": "platinummassive43262.schlageLockAlarm", "command": "setForcedSensitivity", "arguments": [{{level}}] } ] }

External Keypad Beep (command -(beep or off))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.keypadBeep", "command": "{{command}}", "arguments": [] } ] }

Auto Lock (command -(autolock or off))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.autoLock", "command": "{{command}}", "arguments": [] } ] }

Interior Schlage button (command- (disable or enable))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.schlageInteriorButton", "command": "{{command}}", "arguments": [] } ] }

Lock and Leave (command (lockandleave or off))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.lockAndLeave", "command": "{{command}}", "arguments": [] } ] }

Vacation Mode (command -(vacation or off))

{ "commands": [ { "component": "settings", "capability": "platinummassive43262.vacationMode", "command": "{{command}}", "arguments": [] } ] }

Get Device Health Status Task (Online, Offline,etc).

Here is a Profile that runs every 1 hour and displays what device(s) if any are Offline.
Every Hour Check Device Health UPDATED to handle if no devices are Offline

(WARNING You can run the task manually and change the check interval but, if the check interval is to small it will error out because you will hit the request limit of the API. )

•Location Controls

Create location mode
Url

https://api.smartthings.com/locations/{{locationId}}/modes

Body

{ "label" : "{{Name of new mode}}" }

Get current location mode
Body

https://api.smartthings.com/v1/locations/%locationId/modes/current

•Scene

Get Scenes Task
If you just want the url for the Task Http Request
Url

https://api.smartthings.com/v1/scenes

Execute Scene Task
This task uses the Get Scenes Task to obtain the ID of the scene to run. If you want to use the scene Id instead of a variable just replace the %sceneId with the ID you got from Get Scenes.
Here is just the url for the HTTP Request.

Url

https://api.smartthings.com/v1/scenes/%sceneId/execute

Credits

Command for controlling a device(Sonos speaker or other device) that has the
audioVolume capability. - courtesy of @bthrock

Create location mode - @orangebucket
VR Presence Sensor - @orangebucket

4 Likes

Is there a reason I get an error message “Error details: Missing action of type 391” when I try to import into Tasker?

That is a odd error, I am looking into it.

1 Like

I get the same error. Glad it’s not just me.

1 Like

I got that as well until I joined the Tasker Beta.

1 Like

Good to know. I have not been able to reproduce the error. Because all my phones are subscribed to the beta and Tasker is shared with my family account.

I will update the OP to include the need to have Tasker on the current beta.

2 Likes

Has anyone figure out the setup for Tasker to change the color of a zigbee light using the Tasker HTTP request? Please share if you have.

Thanks

Is there a way to do this through Tasker and then push a notification for multiple devices?

What do you mean by color? Temperature or RGB. If temperature I have updated the second post with the body to post for temp. I will post a RGB as soon as I have time. To work it out.

Yes, I believe this can be done. I will test for a device status if it returns offline using tasker and let you know.

2 Likes

Currently I have the outdoor INNR lights and can change the color from red, white, and blue thru another Edge driver I am using but it is not working as expected… just want to change all three bulbs to the three color mentioned above at the same time.

https://www.innr.com/en/product/outdoor-smart-spot-color-us/

If possible to check all/selected devices for online/offline status.

Okay those are a RGB bulb. I will look at the body needed to control that.

1 Like

I have added the body code for colorControl in the second post. It has the values for red and blue. I’ll work on the other items you asked about tomorrow.

So where does the HUE 0 / Saturation 100 go or replace in the code?

{ “commands”: [ {
“component”: “main”,
“capability”: “colorControl”,
“command”: “setColor”,
“arguments”: [{
“map”:{
“hue”: {“decimal”:“%colorHue”},
“saturation”: {“decimal”:“%colorSaturation”}
}
}]
} ] }

The %colorHue and %colorSaturation are Tasker variable’s. You can remove them and simple replace them the 0 for hue and 100 for saturation.

I did:

{ “commands”: [ {
“component”: “main”,
“capability”: “colorControl”,
“command”: “setColor”,
“arguments”: [{
“map”:{
“hue”: {“decimal”:“0”},
“saturation”: {“decimal”:“100”}
}
}]
} ] }

But get this error.

@swdeason I don’t have a RGB bulb to test so we can try this. That code is from the Rule API it probably doesn’t need the decimal.

{ “commands”: [ {
“component”: “main”,
“capability”: “colorControl”,
“command”: “setColor”,
“arguments”: [{
“map”:{
“hue”: {“0”},
“saturation”: {“100”}
}
}]
} ] }

Jake,

Have you tried running a Scene from Tasker? Is that possible?