SmartThings API Library for Arduino IDE

All,

I created a Smartthings API library for use with Arduino IDE to programming various microcontrollers that will interact with the Smartthings platform

The ST_API library provides the following functionality:

  1. Execute a Rule
  2. Execute a Scene
  3. Get device online state
  4. Get device status
  5. Send commands to a device:
    1. Turn on or off
    2. Set dim level
    3. Turn on & set dim level
    4. Set color temperature
    5. Set hue and saturation
    6. Refresh (for supported devices)
    7. Send arbitrary json command

The library should work with any microcontroller that supports SSL clients and has sufficient memory. There are several example sketches and all have been successfully used with the ESP32 and MKR WiFi 1010 and have complied with several other Arduino microcontrollers.

See the repository read me for additional information about the library and how to use the examples

Check out the library at: GitHub - rambo350z/ST_API: Arduino Library for interacting with SmartThings API

5 Likes

Hi, I’m very new to the Smartthings hub-resident Edge driver concept, so I may be asking a dumb question…it’s OK if I am. The APIs in this post seem to be able to send a control command to a Smartthings enabled device (like if I want my wifi-enabled Arduino to turn a switch on), and the APIs also seem to receive a response from the Smartthings enabled device (like a temp sensor). If I want to press a button on the Smartthings app and have it send a command to the Arduino, are there any tutorials how to do that? Thanks.

The SmartThing (ST) API does not send out events, the Arduino has to poll SmartThing API to detect a change, such as a temperature or switch state change. The quickest I was able to poll was 2-3 seconds with most of this time taken to receive the response from ST (commands to devices seem to execute in < 1 second). Realistically I wouldn’t poll any faster the once every 5 seconds.

If polling at this rate would work for you, the ST_Device_Status sketch example in the library should give you a good starting point. The code below is what gets status from a switch (GetDeviceStatus() function) and pulls out the switch status from the resultant ST json response (CapValue() function).

You will need to get a ST Personal Access Token (PAT) and update the example sketch with the PAT, location id and device id for the switch in the ST platform

if (!GetDeviceStatus(Some_Switch, interval, Some_Switch_pm, false)) return;
interval = 60; //get status every minute
//set variables to state of various device capabilities
char switchState[4] {‘\0’};
CapValue(switchState, “{"switch":{"value":”, ‘,’); RemoveQuotes(switchState);
Serial.print("Switch is "); Serial.println(switchState);

2 Likes

Hello.
Have been there any changes to the API / endpoints, etc.

I’m trying to implement this for reading thermostat’s current status and settings; but I have not been able to make it work.

FWIW: Using uno R4. Changed for the proper wifi libraries, SSL, WDT, but don’t seem to be able to get device status. Refresh seems to be sending a json though.

Edit: main difference, I haven’t been able to get more than 5.5 sec of WDT on the R4; but managed to ad loops delays in the wd reset function to go up to the minute. It seems to just hang there when sending the get status command.

Thanks.

I know it may seem a bit confusing at first, but the process described in this thread is technically not using an edge driver and is not communicating directly to a SmartThings/Aeotec hub.

Instead, it is communicating with the public API in the SmartThings cloud. And it’s asking the SmartThings cloud to either get information from a connected device or to send a command to a connected device.

All of this is why you will need a PAT (personal access token) to the cloud account, which you would not need if it was an actual edge driver running on a SmartThings hub. But it isn’t. It’s using the public API to get information From the SmartThings cloud about a specific SmartThings account.

So under the SmartThings terminology, this is a “endpoint Smartapp”, not an “edge driver.“

You can write this type of Smartapp in any language that you want and host it anywhere you want and then you communicate to an existing SmartThings account via the public rest API.

There are some alternative methods which would use edge drivers to communicate locally between a SmartThings hub and a local server, either using local Webhooks or MQTT. You can find those projects on the quick browse list for “edge services.”

https://community.smartthings.com/tag/edge_services

I hope that clears up a little bit of the confusion. Carry-on. :sunglasses:

1 Like

Hi Ronny,

I haven’t looked at this in several months so I have forgotten many of the details

It sounds like you aren’t getting a response from the api request and it just hangs waiting

Have you set the log level to 3 and see what the response you are getting from SmartThings API in the Serial window

And the library is working for me though there was a change to the response json that I had to fix in my sketches. But my Adriano library wasn’t affected and seems to work

Well; I have narrowed it down to STControl::GetRequestResponse() hanging.

Don’t have a lot of time right now to figure it out; but at least now I know where the issue is.
It might be the changes you mention. I have not checked where is it that it gets lost. I’ll need to get rid of the WDT sections to check it out.

THanks