Get an Ardiuno Device to Send a Status

I have a ‘dumb’ lock that I want to send the status (lock\unlock) to the Smartthiings HUB. A lever switch is in the door frame where the bolt is. If the bolt is pressing against the switch then I know the door is locked otherwise, the door is unlocked. The switch is connected to an Arduino and (at least it used to before the new API) sends a switch status (on or off). Right now, the status states it’s connected as a LAN Device (whatever that means). Before the API change, I used a custom device handler, but now everything is different, I have no idea where to start. I don’t even know if it is possible. Could someone point me in the right direction? I started reading the developer’s guide, but it’s a lot to take in. I was hoping maybe someone has done something similar or can give me some advice.

Hi Peter,

Yes, it is possible, depending on the type of Arduino.

Below is a link to an article I posted. The ‘ST_Device_Toggle’ sketch in the library is an example of how to send commands to turn off/on a switch device in ST.

In your case, the easiest way to implement this in ST using this library would be with a ST virtual switch that the Arduino would change to state of based on the lock state.

Todd Austin’s Virtual Device Creator edge driver can create a virtual lock which would also work, though that would require generating raw JSON command that the Arduino would send to change the lock state. See the ‘ST_RawJSON_Command’ sketch for an example of sending raw JSON

SmartThings API Library for Arduino IDE

1 Like

Thanks for pointing me in the right direction. I am looking at the RawJson_Command sketch. I am wondering if you have any samples on the JSON. I am a little slow with this Smartthings API. or could you direct me to the relevant part in Samsung Smartthings API documentation?

Here is the link to the ST devices API documentation

Use the ‘ST_RawJSON_Command’ sketch as an example for sending json commands to a device
The relevent line from the sketch is:
myHome.STDeviceCmd(Some_Light, DeviceJSON, Some_JSON_Raw, true);
changing the Some_JSON_Raw variable to the variable to set the ST device lock state

Below are the device json commands that will lock and unlock a ST virtual lock
const char locked = {R"({
“commands”: [
{
“component”: “main”,
“capability”: “lock”,
“command”: “lock”
}
]
})"}

const char unlocked = {R"({
“commands”: [
{
“component”: “main”,
“capability”: “lock”,
“command”: “unlock”
}
]
})"}

The way I usually go about determining the necessary json commands is I create a routine in ST for the desired device setting the appropriate commands in the Then part of the routine. I then use Todd Austin’s excellent API Browser+ to get the details for the routine which shows the necessary capability and command information for the device I want to control from an Arduino

Finally getting to this. I am unsure where the variable DeviceJSON is defined and what the value should be.

myHome.STDeviceCmd(Some_Light, DeviceJSON, Some_JSON_Raw, true);

You put your device id in the ST_ID.h header file that gets included with the main sketch