Unable to send Capability value from Lambda to Smartthings

Hello everyone,

I’m trying to integrate a Thing from AWS IoT into Smartthings.
I’m almost there, my Thing is added to Smartthings but I am not able to update the Capability value.

My thing is a custom made Arduino project, and I monitor my swimming pool temperature, PH level and ORP value. Those values are sent to AWS.

Here is my setup:

  1. I have a Smartthings Schema Connector Project:

  2. The project is setup as an AWS Lambda, and all Device Cloud credentials are working fine.

  3. Also in this ST project, I have a Device Profile:


    and I added a standard Temperature Measurement capability:
    image

  4. My ST project is deployed to test and I can add the device in Smartthings.

  5. Here is my Lambda function code:

     const { lambda } = require("st-schema");
    
     async function discoveryRequest(request, response) {
         console.log('discoveryRequest', JSON.stringify(request,null,2));
         response.addDevice('PoolBoy-0001', 'PoolBoy', '951c7b9e-60a8-4ce5-97e0-35588731ccd8')
             .manufacturerName('Charles de la Sablonnière')
             .modelName("PoolBoy Home Made")
             .roomName('Backyard');
     }
    
     async function stateRefreshRequest(request, response) {
         console.log("stateRefreshRequest: ", JSON.stringify(request,null,2));
         response.addDevice('PoolBoy-0001', [
           {
             component: 'main',
             capability: 'st.temperature',
             attribute: 'temperature',
             value: 32.5
           }
         ]);
     }
    
     async function commandRequest(request, response) {
         console.log('commandRequest', JSON.stringify(request,null,2));
     }
     module.exports.handler = lambda({
         discoveryRequest,
         commandRequest,
         stateRefreshRequest
     });
    
  6. The stateRefreshRequest function is called, I can see this in AWS CloudWatch logs:

2020-08-06T07:21:26.845Z	b0b71cd0-7972-4b31-915d-3e07f8c17bc1	INFO	response back to SmartThings 
{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateRefreshResponse",
        "requestId": "60617cac-125c-527d-8c59-2b09a3ea0106"
    },
    "deviceState": [
        {
            "externalDeviceId": "PoolBoy-0001",
            "states": [
                {
                    "component": "main",
                    "capability": "st.temperature",
                    "attribute": "temperature",
                    "value": 32.5
                }
            ]
        }
    ]
}

The problem is, I never see the temperature value display “32.5” in the Smartthings app. It is always “0”
Anyone can help me with that? What am I doing wrong?

Thanks for your help,

Charles

Tagging @erickv @nayelyz

I don’t know how the schema works with regard to when and where you need to prepend the capability ID with ‘st.’, but I do know that the capability ID for Temperature Measurement is ‘temperatureMeasurement’ and not ‘temperature’. Could that be significant?

1 Like

Thanks @orangebucket for your input.

You were right on! :grinning:

Here is the response that made the value change in the Smartthings app :

2020-08-06T16:15:18.819Z	e121ca56-50ae-4381-bc60-26777c5ce019	INFO	response back to SmartThings 
{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateRefreshResponse",
        "requestId": "D517F053-7D08-4F0E-A36B-B3E85A9D83C1+ff5130df8968a138"
    },
    "deviceState": [
        {
            "externalDeviceId": "PoolBoy-0001",
            "states": [
                {
                    "component": "main",
                    "capability": "st.temperatureMeasurement",
                    "attribute": "temperature",
                    "value": 82,
                    "unit": "F"
                }
            ]
        }
    ]
} 

It needs the “st.” I also added the unit, which is required according to the Capabilities reference (https://smartthings.developer.samsung.com/docs/api-ref/capabilities.html#Temperature-Measurement)

Another interesting thing is that if I set the values for multiple capabilities, and only one of them is not “formatted” properly, all values are ignored.

Thanks for your help,

Charles

I’m trying to do similar, but as soon as I reference the device profile ID in my discovery request rather than a standard capability, the smartthings app fails to recognise the device list when adding the device, instead returning a blank list. I’ve checked the logs for what is returned to Sametthings and it appears ok:

{
“headers”: {
“schema”: “st-schema”,
“version”: “1.0”,
“interactionType”: “discoveryResponse”,
“requestId”: “2AEEDD98-B933-4B32-B89C-6C1A05045F06”
},
“devices”: [
{
“externalDeviceId”: “30AEA4C55518”,
“friendlyName”: “iParcelBox-085024”,
“deviceHandlerType”: “0bb4da60-d1bb-4865-9ce7-9a22fe712e0b”,
“manufacturerInfo”: {
“manufacturerName”: “iParcelBox Ltd”,
“modelName”: “Smart Parcel Delivery Box”
}
},
{etc…

Is there any reason my app isn’t recognising the device profile?