[Cloud Connection] How do I report the status to ST when my device status has changed?

Hello,

I checked that the status of the app is reflected according to the data responded from the webhook Address by following the document provided by ST.

But,
If the connection with the device is unstable and the disconnect is returned, ST does not send a status check signal when I re-enter the ST user app and update the screen.

In this case, I think I have an obligation to report the status to ST again and reflect the status on the app screen.

And even if the status of the device (for example, switch) is turned on or off, I want to reflect it on the app screen.

How can I report the status to ST?

tagging @nayelyz

1 Like

Welcome to the SmartThings Community, @partain!
You’re using an ST Schema, right?
For this, you can send a device error in a state callback indicating that the device is offline. The request would look like the following:

{
   "headers":{
      "schema":"st-schema",
      "version":"1.0",
      "interactionType":"stateCallback",
      "requestId":"a079bbc8-5025-..."
   },
   "authentication":{
      "tokenType":"Bearer",
      "token":"...."
   },
   "deviceState":[
      {
         "externalDeviceId":"...",
         "deviceError":[
            {
               "errorEnum":"DEVICE-OFFLINE",
               "detail":"Device offline"
            }
         ]
      }
   ]
}

Then, to make it back online, you should send another stateCallback using the healthCheck capability as follows:

{
  "headers": {
    "schema": "st-schema",
    "version": "1.0",
    "interactionType": "stateCallback",
    "requestId": "eb8b6b93-3198-..."
  },
  "authentication": {
    "tokenType": "Bearer",
    "token": "..."
  },
  "deviceState": [
    {
      "externalDeviceId": "...",
      "states": [
        {
          "component": "main",
          "capability": "st.healthCheck",
          "attribute": "healthStatus",
          "value": "online"
        }
      ]
    }
  ]
}

_Note: You can also implement the good practice to send the healthCheck event in each commandResponse and callback to indicate this activity means the device is available

Important things to consider:

  • It is different when the Access Token granted by the third-party cloud (you) isn’t valid anymore.
    • In this case, all devices will be marked offline.
    • You will still be able to send callbacks to ST from your cloud
    • But, ST won’t be able to access the devices and interactions like discoveryCallback will fail because a stateRefreshRequest is sent immediately after (from ST to your cloud).