The device can only be added once, SmartThings Schema Cloud Connector

When I add the device, everything is OK the first time I add it. When I try to add more devices, I always get the discoveryRequest to the my callback address. Although I think I should get an grantCallbackAccess. How can devices be added?

When I press next here, I get the discoveryRequest response.

Hi, @Heikki_Pirttinen!

The grantCallbackAccess interaction is triggered the first time you add the connector, not for every device it discovers.
To add devices on-demand, you should use the discoveryCallback integration as mentioned here: Interaction Types | SmartThings Developers

Otherwise, if we go to “add device”, we’ll be calling the discovery request. This means your discovery response should include the new devices.
Remember the connector makes a periodic discovery so, make sure it will respond with the correct devices list.

Does this mean I can’t add devices from SmartThings App? Adding devices must be done through our cloud?

If you do it from the app, you need to send a discovery response with the new devices. Have you tried that?
What would be the scenario? For example, you’re adding a new device for your tests, or it’s a simulation of how a user would add a device after connecting it on your side.

The process for the first device now goes like this:

  1. The user selects add a new device from the SmartThings App.
  2. Our Authorization URI receives the POST message. Which contains the callback URL.
  3. Since the message is POST, at this point we can ask the user which device he/she wants to add.
  4. After the device selection, we will send our authentication code.
  5. Our Token URI receives the GET command. We return our authorization Token to the query.
  6. Our Hosting/Callback URI receives GET command grantCallbackAccess
  7. Our Hosting/Callback URI receives GET command discoveryRequest. We return a new list of devices.
  8. Our Hosting/Callback URI receives GET command stateRefreshRequest. We return the state of the devices.

Since the discoveryRequest is GET, we cannot ask the user which device he/she would like to add. In addition, there is no information in the discoveryRequest about whether it is now a matter of adding a new device. You can only answer the discoveryRequest which devices have already been added. We can add the device at that point if it has first been added in our own cloud.

It’s difficult for the user to understand that you can’t add a device in the same way as the first time.

It is strange that the add new device command asks for the status of the devices (discoveryRequest).

Ok, so, that specific scenario won’t work on the ST side, the ST Schema will have access only to those devices your connector has defined to discover.
The POST call of the callback URL won’t be triggered again until the connector is completely deleted and added again.
Instead, you should define a UI on your cloud to allow users to add more devices to SmartThings and you would need to send a discoveryCallback.
The same happens if you need to delete a single device, if it’s deleted on the ST side, your cloud won’t get a notification, so, the user needs to indicate on your side he wants to remove it from ST so you can send a stateCallback with the corresponding error message.

Take a look at this post:

I tried removing the device from the SmartThings App and sending it an stateCallback. I got the following error message.

deviceState: [
0: {
  externalDeviceId: "Sa2-test"
  deviceError: [
  0: {
    errorEnum: "BAD-REQUEST"
    detail: "deviceState[0] does not correspond to any ST device"

Why do I get the Global Error enum even though the documentation says that there should be a Device Error? I expected to get a device error, DEVICE-DELETED.

You sent the stateCallback after you deleted the device, right?
This means the device you used in the callback doesn’t exist so, the error is correct.

When are you expecting to get this error? As a response to the callback when a device no longer exists?
As I mentioned before:

This means that on the ST side, the device doesn’t exist anymore, it won’t have a registry that the device used to be there and was deleted.
The device and global errors are for you to use in your responses to SmartThings.