Do SmartThings Schema Interaction Types have updating and deleting device function?

Based on the SmartThings Schema Interaction Types, may I ask if there is any method to implement deleting device and updating device(friendlyName) through SmartThings Schema Interaction Types?

For example, if I change the name of my device, the device name can also be changes in SmartThings APP. If I delete a device in my APP, the device can also be deleted in SmartThings APP.

I tried to do send the new familyName in discoveryCallback while changing the device name, but It seems not the way I thought to change the device name.

If not, is there any other way?

I tried API(API | SmartThings Developers) and Personal Access Tokens to retrieve deviceID so that I can update certain device label or delete device, but it seems not workable. Because each Personal Access Tokens is corresponding to the user’s Samsung Account. Once the project is published, Other users will have their own accounts. Using API and Personal Access Tokens which is generated from my account cannot find others’ devices.

Thanks,

Hi!

To delete the device, you need to send the corresponding global error in a stateCallback. Here’s a post where I shared more information about the deletion process:

This cannot be done, the friendlyName parameter is only considered when the device is discovered for the first time. Please, take a look at this post:

That discussion seems to unlink the account or integration instead of deleting a device. What I asked is to initiate deleting a certain device from my side. If that is doable, the callback payload should have externalDeviceId to delete a certain device.

Or like this? Which is modified from device error example here.

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateCallback",
        "requestId": "abc-123-456"
    },
    "authentication": {
        "tokenType": "Bearer",
        "token": "token-received from SmartThings for callbacks"
    },
    "deviceState": [
        {
            "externalDeviceId": "partner-device-id-1",
            "deviceError": [
              {
                "errorEnum": "DEVICE-DELETED",
                "detail": "more detail from the partner"
              }
            ]
        }
    ]
}

How about the API and Personal Access Tokens method I mentioned? Is my understanding right?

Oh, sorry about that.

Let me make some tests and I’ll get back to you.

Update:
@exosite, the team confirmed you can use that error to delete the device from a stateCallback, just remember that, if you send the device again in a discoveryResponse, it will be created:

"deviceState": [
    {
        "externalDeviceId": "pdevice-1",
        "deviceError": [
            {
                "errorEnum": "DEVICE-DELETED",
                "detail": "messageDetail"
            }
        ]
    }
]

Yes, that can be done through the API but only by the owner, external PATs like yours cannot interact with the Connector’s users’ devices.

Also, here’s an example using the ST Schema NodeJS SDK:

let deviceState = [
    {
     externalDeviceId:"device-id",
     deviceError:[
       {
         errorEnum: "DEVICE-DELETED",
         detail: "Device deleted by third"
       }
     ]
   }
 ]
const updateRequest = new StateUpdateRequest(process.env.ST_CLIENT_ID, process.env.ST_CLIENT_SECRET);

updateRequest.updateState(accessTokens.callbackUrls, accessTokens.callbackAuthentication, deviceState)
.catch((error)=>{// the request shouldn't be successful as the error causes an exception that will delete the device
    console.log("delete success ", error)
})

Yeah, it works. Thanks for help!

1 Like