Why Cloud connected stateCallback interaction type has BAD-REQUEST error response?

I am implementing SmartThings Cloud Connected devices to my system.
I faced a problem while sending Device State Callback:

After OAuth login, finishing Discovery interaction type response and saving the access token to my system, I sent a Device State Callback request to smartThings like this:

{
    "authentication": {
        "tokenType": "Bearer",
        "token": "###"
    },
    "deviceState": [
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_LIGHT",
            "states": [
                {
                    "attribute": "level",
                    "value": 25,
                    "capability": "st.switchLevel",
                    "timestamp": 1633318280000,
                    "component": "main"
                },
                {
                    "attribute": "switch",
                    "value": "on",
                    "capability": "st.switch",
                    "timestamp": 1633318280000,
                    "component": "main"
                },
                {
                    "attribute": "healthStatus",
                    "value": "online",
                    "capability": "st.healthCheck",
                    "timestamp": 1633318280000,
                    "component": "main"
                }
            ]
        },
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_FAN",
            "states": [
                {
                    "attribute": "fanSpeed",
                    "value": 0,
                    "capability": "st.fanSpeed",
                    "timestamp": 1633318281000,
                    "component": "main"
                },
                {
                    "attribute": "switch",
                    "value": "on",
                    "capability": "st.switch",
                    "timestamp": 1633318281000,
                    "component": "main"
                },
                {
                    "attribute": "healthStatus",
                    "value": "online",
                    "capability": "st.healthCheck",
                    "timestamp": 1633318281000,
                    "component": "main"
                }
            ]
        }
    ],
    "headers": {
        "requestId": "FAF8BE73D71D925CE3E",
        "interactionType": "stateCallback",
        "schema": "st-schema",
        "version": "1.0"
    }
}

I can receive normal response 204 and the device state in SmartThings APP was synchronized in the beginning but after a period of time I received 400 error status code and the response body is like this:

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateCallback",
        "requestId": "FAF8BE73D71D925CE3E"
    },
    "deviceState": [
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_LIGHT",
            "deviceError": [
                {
                    "errorEnum": "BAD-REQUEST",
                    "detail": "deviceState[0] does not correspond to any ST device"
                }
            ]
        },
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_FAN",
            "deviceError": [
                {
                    "errorEnum": "BAD-REQUEST",
                    "detail": "deviceState[1] does not correspond to any ST device"
                }
            ]
        }
    ]
}

According to the deviceError, I don’t know why deviceState[0] (st.switchLevel) is illegal for a “c2c-dimmer” device handler and why deviceState1 is illegal for a “c2c-fan-controller-4speed” device handler?
I think my Device State Callback request is legal, please tell me where I was wrong?

My Discovery Response to SmartThings is this:

{
    "requestGrantCallbackAccess": true,
    "devices": [
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_LIGHT",
            "deviceHandlerType": "c2c-dimmer",
            "manufacturerInfo": {
                "hwVersion": "4.0.0",
                "modelName": "type1-1",
                "swVersion": "2.2.0",
                "manufacturerName": "TENX"
            },
            "friendlyName": "My New My Product Light 20F543E0ED3BD5CC5661D4F1"
        },
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_FAN",
            "deviceHandlerType": "c2c-fan-controller-4speed",
            "manufacturerInfo": {
                "hwVersion": "4.0.0",
                "modelName": "type1-1",
                "swVersion": "2.2.0",
                "manufacturerName": "TENX"
            },
            "friendlyName": "My Product Fan 20F543E0ED3BD5CC5661D4F1"
        }
    ],
    "headers": {
        "requestId": "50C703D7-8C5E-4669-8CBB-7877E6CD5C71",
        "interactionType": "discoveryResponse",


        "schema": "st-schema",
        "version": "1.0"
    }
}

Hey, @exosite

I’m quite sure that it is because you’re trying to push a Health Check (healthStatus) state, but such capability is not supported by any Device Handler Type.

Please remove it and let me know if it helps.

Hi, Eric

But the Device State Callback example in document has health check. And in the beginning of device handler page says the Health Check and Refresh Capabilities are mandatory for each Device Profile. The health check is legal in State Refresh Response and Command Response but illegal in Device State Callback? I am very confused. Please clarify that I should follow your suggestion or the document? I will try your suggestion by the way.

It’s really interesting some of the inconsistencies you’ve found right there.

You’re right, it shouldn’t have it, since the c2c-rgbw-color-bulb, doesn’t support Health Check.


This is true for device profiles, which is the case of the second device example (pdevice-2) which provides usage reference of a custom device profile.


I’ll suggest some changes to that document to improve the context provided. Also, to have a better level of consistency across your integration, I recommend you build your custom device profile at the Developer Workspace.

Hi Eric,

I tried your suggestion but still got the same error. I have removed the Health Check state. During my working daytime, I won’t see this error. After a night, when I came back to the office in the morning. I push the device button to change the status then my log shows this error again.

{
    "authentication": {
        "tokenType": "Bearer",
        "token": "###"
    },
    "deviceState": [
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_LIGHT",
            "states": [
                {
                    "attribute": "level",
                    "value": 25,
                    "capability": "st.switchLevel",
                    "timestamp": 1633572680000,
                    "component": "main"
                },
                {
                    "attribute": "switch",
                    "value": "on",
                    "capability": "st.switch",
                    "timestamp": 1633572680000,
                    "component": "main"
                }
            ]
        },
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_FAN",
            "states": [
                {
                    "attribute": "fanSpeed",
                    "value": 1,
                    "capability": "st.fanSpeed",
                    "timestamp": 1633572680000,
                    "component": "main"
                },
                {
                    "attribute": "switch",
                    "value": "on",
                    "capability": "st.switch",
                    "timestamp": 1633572680000,
                    "component": "main"
                }
            ]
        }
    ],
    "headers": {
        "requestId": "FA1F6B1FBB76FE02B79",
        "interactionType": "stateCallback",
        "schema": "st-schema",
        "version": "1.0"
    }
}

The response:

{
    "body": "{\"headers\":{\"schema\":\"st-schema\",\"version\":\"1.0\",\"interactionType\":\"stateCallback\",\"requestId\":\"FA1F6B1FBB76FE02B79\"},\"deviceState\":[{\"externalDeviceId\":\"20F543E0ED3BD5CC5661D4F1_LIGHT\",\"deviceError\":[{\"errorEnum\":\"BAD-REQUEST\",\"detail\":\"deviceState[0] does not correspond to any ST device\"}]},{\"externalDeviceId\":\"20F543E0ED3BD5CC5661D4F1_FAN\",\"deviceError\":[{\"errorEnum\":\"BAD-REQUEST\",\"detail\":\"deviceState[1] does not correspond to any ST device\"}]}]}",
    "status_code": 400,
    "headers": {
        "x-amz-apigw-id": "G0KTWEiYoAMF3zw=",
        "X-Amz-Cf-Pop": "SFO5-C1",
        "X-Cache": "Error from cloudfront",
        "Date": "Thu, 07 Oct 2021 02:11:20 GMT",
        "Content-Type": "application/json",
        "Content-Length": "454",
        "X-Amzn-Trace-Id": "Root=1-615e5748-5437539f250b95e93c1f5ee4;Sampled=0",
        "Connection": "keep-alive",
        "x-amzn-RequestId": "1816cb8a-8958-4bfd-888e-d09b124c9167",
        "Via": "1.1 36a6d536e73f7d347cd93b9a754ee828.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "vXXNZAff15RCOIaMc-mCmUCbSmhSnsRrF1AtuLye9btpUMKVdEKphA=="
    }
}

The response body:

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateCallback",
        "requestId": "FA1F6B1FBB76FE02B79"
    },
    "deviceState": [
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_LIGHT",
            "deviceError": [
                {
                    "errorEnum": "BAD-REQUEST",
                    "detail": "deviceState[0] does not correspond to any ST device"
                }
            ]
        },
        {
            "externalDeviceId": "20F543E0ED3BD5CC5661D4F1_FAN",
            "deviceError": [
                {
                    "errorEnum": "BAD-REQUEST",
                    "detail": "deviceState[1] does not correspond to any ST device"
                }
            ]
        }
    ]
}
1 Like

Hmmm, this is interesting. Let me share this with our team and double-check if we’re not hitting an unexpected bug.

I am pretty sure my Reciprocal Access Token is not expired and even I refreshed it, the error is still the same.

{
    "message": "SmartThingsModel.refreshCallbackAccessToken response",
    "refreshCallbackAccessTokenResponse": {
        "body": "{\"headers\":{\"schema\":\"st-schema\",\"version\":\"1.0\",\"interactionType\":\"accessTokenResponse\",\"requestId\":\"61DA1E9C216F2796951\"},\"callbackAuthentication\":{\"tokenType\":\"Bearer\",\"accessToken\":\"###\",\"refreshToken\":\"###\",\"expiresIn\":86400}}",
        "status_code": 200,
        "headers": {
            "x-amz-apigw-id": "G0QbCGogIAMFi4A=",
            "X-Amz-Cf-Pop": "SFO20-C1",
            "X-Cache": "Miss from cloudfront",
            "Date": "Thu, 07 Oct 2021 02:53:07 GMT",
            "Content-Type": "application/json",
            "Content-Length": "569",
            "X-Amzn-Trace-Id": "Root=1-615e6113-3910ce4846e1ce98292707f5;Sampled=1",
            "Connection": "keep-alive",
            "x-amzn-RequestId": "87171a27-7210-4c02-838d-3b97d38505d5",
            "Via": "1.1 67c5370c4ea2e5f9f865960e31ef2d86.cloudfront.net (CloudFront)",
            "X-Amz-Cf-Id": "gz2ZB5BrLdTYe9ZTyxf_Oh3UyEel7IhLgUkAChb5rDLKg10ZwWbfgA=="
        }
    },
    "module": "smartthings_model"
}

There’s another finding.
Under current error situation if I send Discovery Callback request, The response was 204 seems successful but the new device did not show in SmartThings APP.

My Discovery Callback Request:

{
    "authentication": {
        "tokenType": "Bearer",
        "token": "###"
    },
    "devices": [
        {
            "externalDeviceId": "88835D98B2BF366A5E61B058_LIGHT",
            "deviceHandlerType": "c2c-dimmer",
            "manufacturerInfo": {
                "hwVersion": "4.0.0",
                "modelName": "type1-1",
                "swVersion": "2.4.0",
                "manufacturerName": "TENX"
            },
            "friendlyName": "88835D98B2BF Light 88835D98B2BF366A5E61B058"
        },
        {
            "externalDeviceId": "88835D98B2BF366A5E61B058_FAN",
            "deviceHandlerType": "c2c-fan-controller-4speed",
            "manufacturerInfo": {
                "hwVersion": "4.0.0",
                "modelName": "type1-1",
                "swVersion": "2.4.0",
                "manufacturerName": "TENX"
            },
            "friendlyName": "88835D98B2BF Fan 88835D98B2BF366A5E61B058"
        }
    ],
    "headers": {
        "requestId": "913C15B331F5182A810",
        "interactionType": "discoveryCallback",
        "schema": "st-schema",
        "version": "1.0"
    }
}

Received Discovery Callback Respoonse:

{
    "discoveryCallbackResponse": {
        "body": "",
        "status_code": 204,
        "headers": {
            "x-amz-apigw-id": "G0XS8GA0IAMFu-w=",
            "X-Amz-Cf-Pop": "SFO5-C1",
            "X-Cache": "Miss from cloudfront",
            "Date": "Thu, 07 Oct 2021 03:40:03 GMT",
            "Content-Type": "application/json",
            "Content-Length": "0",
            "X-Amzn-Trace-Id": "Root=1-615e6c12-4c639c632f0607521f598de3;Sampled=1",
            "Connection": "keep-alive",
            "x-amzn-RequestId": "fd54b74b-7ad0-4cee-b299-998618a82e4d",
            "Via": "1.1 be84d08eeed51234cd122d3c30e6f7c1.cloudfront.net (CloudFront)",
            "X-Amz-Cf-Id": "A-RVlqPRO_fbNeXs7xceRWhL83V4qKq2AQ3eOJVPorGTYxXJ5v3R-g=="
        }
    },
    "module": "smartthings_model",
    "message": "SmartThingsModel.sendDiscoveryCallback response"
}

But send list devices API to list my devices, I cannot see my device “88835D98B2BF Light 88835D98B2BF366A5E61B058” added successfully.

[
    {
        "restrictionTier": 0,
        "roomId": "7b3a428b-1ce0-4e2a-9781-800fc71d1912",
        "name": "c2c-dimmer",
        "viper": {
            "hwVersion": "4.0.0",
            "modelName": "type1-1",
            "swVersion": "2.4.0",
            "manufacturerName": "TENX"
        },
        "profile": {
            "id": "3a743caf-1268-424f-8d7a-c0a280a82910"
        },
        "createTime": "2021-10-06T11:03:55.802Z",
        "deviceId": "51dc0809-57e2-4854-a023-2e801f30022a",
        "label": "device1 Light 88835D98B2A2AB785D61C101",
        "manufacturerName": "SmartThings",
        "type": "VIPER",
        "presentationId": "SmartThings-smartthings-c2c-dimmer",
        "components": [
            {
                "categories": [
                    {
                        "name": "Light",
                        "categoryType": "manufacturer"
                    }
                ],
                "capabilities": [
                    {
                        "version": 1,
                        "id": "switch"
                    },
                    {
                        "version": 1,
                        "id": "switchLevel"
                    },
                    {
                        "version": 1,
                        "id": "refresh"
                    },
                    {
                        "version": 1,
                        "id": "healthCheck"
                    }
                ],
                "id": "main"
            }
        ],
        "locationId": "f64d1996-db82-4ee0-92cc-06a9c4a75371"
    },
    {
        "restrictionTier": 0,
        "roomId": "7b3a428b-1ce0-4e2a-9781-800fc71d1912",
        "name": "c2c-fan-controller-4speed",
        "viper": {
            "hwVersion": "4.0.0",
            "modelName": "type1-1",
            "swVersion": "2.2.0",
            "manufacturerName": "TENX"
        },
        "profile": {
            "id": "d77d72d7-5912-4e4b-a474-b093ce42fbac"
        },
        "createTime": "2021-10-06T05:51:48.619Z",
        "deviceId": "489ddc99-7623-41c0-9d8c-7c121dfc8bba",
        "label": "My device1 Fan 20F543E0ED3BD5CC5661D4F1",
        "manufacturerName": "SmartThings",
        "type": "VIPER",
        "presentationId": "SmartThings-smartthings-c2c-fan-controller-4speed",
        "components": [
            {
                "categories": [
                    {
                        "name": "Fan",
                        "categoryType": "manufacturer"
                    }
                ],
                "capabilities": [
                    {
                        "version": 1,
                        "id": "healthCheck"
                    },
                    {
                        "version": 1,
                        "id": "refresh"
                    },
                    {
                        "version": 1,
                        "id": "switch"
                    },
                    {
                        "version": 1,
                        "id": "fanSpeed"
                    }
                ],
                "id": "main"
            }
        ],
        "locationId": "f64d1996-db82-4ee0-92cc-06a9c4a75371"
    },
    {
        "restrictionTier": 0,
        "roomId": "7b3a428b-1ce0-4e2a-9781-800fc71d1912",
        "name": "c2c-dimmer",
        "viper": {
            "hwVersion": "4.0.0",
            "modelName": "type1-1",
            "swVersion": "2.2.0",
            "manufacturerName": "TENX"
        },
        "profile": {
            "id": "3a743caf-1268-424f-8d7a-c0a280a82910"
        },
        "createTime": "2021-10-06T05:51:48.618Z",
        "deviceId": "0b0cd219-caa0-4375-ac52-6f22acf1990d",
        "label": "My device1 Light 20F543E0ED3BD5CC5661D4F1",
        "manufacturerName": "SmartThings",
        "type": "VIPER",
        "presentationId": "SmartThings-smartthings-c2c-dimmer",
        "components": [
            {
                "categories": [
                    {
                        "name": "Light",
                        "categoryType": "manufacturer"
                    }
                ],
                "capabilities": [
                    {
                        "version": 1,
                        "id": "switch"
                    },
                    {
                        "version": 1,
                        "id": "switchLevel"
                    },
                    {
                        "version": 1,
                        "id": "refresh"
                    },
                    {
                        "version": 1,
                        "id": "healthCheck"
                    }
                ],
                "id": "main"
            }
        ],
        "locationId": "f64d1996-db82-4ee0-92cc-06a9c4a75371"
    },
    {
        "restrictionTier": 0,
        "roomId": "7b3a428b-1ce0-4e2a-9781-800fc71d1912",
        "name": "c2c-fan-controller-4speed",
        "viper": {
            "hwVersion": "4.0.0",
            "modelName": "type1-1",
            "swVersion": "2.4.0",
            "manufacturerName": "TENX"
        },
        "profile": {
            "id": "d77d72d7-5912-4e4b-a474-b093ce42fbac"
        },
        "createTime": "2021-10-06T11:03:55.803Z",
        "deviceId": "b65e4bba-54c6-4310-93b6-974c499e97b6",
        "label": "device1 Fan 88835D98B2A2AB785D61C101",
        "manufacturerName": "SmartThings",
        "type": "VIPER",
        "presentationId": "SmartThings-smartthings-c2c-fan-controller-4speed",
        "components": [
            {
                "categories": [
                    {
                        "name": "Fan",
                        "categoryType": "manufacturer"
                    }
                ],
                "capabilities": [
                    {
                        "version": 1,
                        "id": "healthCheck"
                    },
                    {
                        "version": 1,
                        "id": "refresh"
                    },
                    {
                        "version": 1,
                        "id": "switch"
                    },
                    {
                        "version": 1,
                        "id": "fanSpeed"
                    }
                ],
                "id": "main"
            }
        ],
        "locationId": "f64d1996-db82-4ee0-92cc-06a9c4a75371"
    }
]

In conclusion:

  1. After a period of time(for me, after leaving office from 7:00pm to the next day 9:30AM ) the error showed up. It’s hard to test how long it will happen.
  2. I have checked the the access token was not expired.
  3. Under the error situation, even I refreshed access token, I still got the same error.
  4. Under the error situation, the Discovery Callback returned 204 which seems successful, but my new device wouldn’t show in SmartThings APP. And I checked with list devices API. It is truly not added in my device list.

The error can be gone if I do adding devices in SmartThings APP ( Discovery ) again. But users won’t know that. They will feel weird why need to do adding devices again. Please notice that the error will happen again after a nighttime.

I agree, and that’s the purpose of the callbacks, to provide consistency across platforms.

So, I’ve been checking if other partners were experiencing these or similar issues, and yes, some of them reported unexpected errors from callbacks, stateCallback precisely.

In addition, I’ve documented your issue specifically, and as soon as I have a resolution from our engineers, I’ll share with you the details.