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:
Execute a Rule
Execute a Scene
Get device online state
Get device status
Send commands to a device:
Turn on or off
Set dim level
Turn on & set dim level
Set color temperature
Set hue and saturation
Refresh (for supported devices)
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
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);
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.
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.â
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.