Getting Started With API call to control devices (Life after WebCORE)

In an attempt to condense the back story. When I was first setting up my theater, which uses an ST hub to control lights and ceiling LEDs and such, I used an Odroid device running Kodi with an addon called CinemaVision to create the theater experience for friends and family. Lights dim to a certain level, trailers play, lights go full off when movie starts, etc… To do that, I used WebCORE with a couple of pistons that were triggered by URL calls that I could hit from within the CinemaVision script. Over time, I switched to an Nvidia shield, and CinemaVision lost support and went dark, so I stopped worrying about it. Fast forward to today when there’s a new plugin on the horizon and I start looking to bring the automations back to life only to discover WebCORE and Groovy have been EOLd, leaving me to learn if/how I can do this another way, and I’m most definitely getting lost in the weeds.

From what I can tell, what I’m looking to do CAN still be accomplished with an API call, but where I’m struggling is how to set up the back end part of it (what would replace the proverbial piston). In short, I need to create a URL, that when called would set the lights to a given dimmer level (and in the case of the LEDs a color). Am I correct in thinking that is possible? And if so, is there a good guide to start? I’m no programmer, but I can muddle my way through basic code or scripting if I have a guide and examples to follow, but I’m striking out figuring out if it’s even possible.

Interestingly, I noticed that my original URLs still return an OK response when called. Not sure if that is just the old API still floating around, or if that means I’m not too far from still being able to do this. The URL was formatted as:

https://graph-na02-useast1.api.smartthings.com/api/token/xxxx/smartapps/installations/xxxx/execute/:xxxx:

Is there anywhere I can start for just a simple “How To Turn On Lights From The Web” style guide by chance?

Hi, @Moebius

Yes, that is part of the legacy platform and based on its configuration you enabled access for third-parties like WebCORE to control your devices.

So, if I understand correctly, your lights and ceiling LEDs are connected to the ST Hub and want to execute something based on a third-party event, right?

Currently, you can use the SmartThings API (with a Personal Access Token as the authentication) to send commands (REST requests) to devices from different sources. For example:

//this is the URL:
https://api.smartthings.com/v1/devices/deviceID/commands

//This is an example of the body turning on a light
{
    "commands": [
        {
            "component": "main",
            "capability": "switch",
            "command": "on",
            "arguments": []
        }
    ]
}

//This is an example of the body changing the color of a light
{
  "commands": [
    {
      "component": "main",
      "capability": "colorControl",
      "command": "setColor",
      "arguments": [{hue:53,saturation:45}]
    }
  ]
}

The device ID can be found if you list the devices with this URL: https://api.smartthings.com/v1/devices

There’s a tool called SmartThings CLI which allows you to interact with the API through the console, here are the instructions to install it: Get Started With the SmartThings CLI | Developer Documentation | SmartThings

Also, users like to use this tool created by a Community developer that allows you to interact with the API through a web browser:

2 Likes

Yes. So basically, a URL call goes out from a third party app (Kodi and the plugin in this case) and when the URL is called, it would trigger the light controls. I’m not sure if the script engine can format an entire API call or just trigger a URL, but I’ll dig in, and dig into that API Browser which might point me where I need to go.

Thanks!

Another option might be to create multiple Scenes in the ST app that set the various theater modes you are wanting to create. You could then use the ST API to trigger those scenes from Kodi and the plug-in using the API call https://api.smartthings.com/v1/scenes/{sceneId}/execute

Quick question on this as I’m trying to go through the API. I do actually have scenes for all of my states as that was how I originally created the pistons in WebCORE. However, when I use the URL as you listed, I get the error that GET method isn’t allowed for the Execute command. Am I right in thinking since the execute command required a POST method, I’d need to build some manner of “bounce through” URL that on trigger would then format a POST call to the API?

If there’s a way to execute a scene directly through a URL, that would be perfect, but I can’t tell if that’s possible.

Yes, it’s a POST method vs a GET. I used the URL I provided to execute one of my Scenes using a Postman-like tool in the Firefox browser. The Bearer in the Auth header is your PAT.

Thanks, that’s what I was wondering. In the case of the script engine I’m working from, I believe it only has the ability to call a URL. So what I’d need to do is build a page that can take some parameters from the URL string, then format that to a post call to the API. Using parameters would prevent an inadvertent hit to the URL suddenly turning on my lights or the like.

1 Like