Command formatting

Dear developers,

Yesterday I got my new Samsung fridge and I am trying to understand how to interface with it. I found the Core SDK for Javascript and that seems to work just fine. However, the documentation is a bit minimal, for example on how to execute a commands on Devices.

So for example, I am able to read the temperature of the cooler by running this:

client.devices.getCapabilityStatus(UUID,’cooler','temperatureMeasurement').then(reply => {
    console.log(reply);
  })

Which gives this awesome output:

{
  temperature: { value: 4, unit: 'C', timestamp: '2022-09-23T06:42:23.201Z' }
}

But now I am trying to set the temperature. Where I am supposed to find out how to format the command? What I found it this, which does not apply to coolers, but does give a hint on formatting:

Here seems to be some documentation on the thermostatCoolingSetpoint

But I can’t seem to get it right. Here’s what I have now:

var command = 
  {
    "component": "cooler",
    "capability": "thermostatCoolingSetpoint",
    "command": "setCoolingSetpoint",
    "arguments": 
      {
        "value": 6,
        "unit": "C"
      }
  
  };

client.devices.executeCommand(UUID,command).then(reply => {
    console.log(reply);
  })

It generates an error

(node:9898) UnhandledPromiseRejectionWarning: Error: Request failed with status code 422: {"requestId":"A55ABAA6-2C56-474D-8341-458915BEAD63","error":{"code":"ConstraintViolationError","message":"The request is malformed.","details":[{"code":"BodyMalformedError","target":"commands.arguments","message":"The request body is malformed and cannot be processed by server.","details":[]}]}}

So apparently I am not talking in the right language. Can someone help me plz?

You can see the configuration of the capability from the API. The SmartThings CLI helps you make requests to the API from the console.

For example, to get the capability definition, similar to the link above (because this one is getting the info directly from the API, the repo can be out-of-date):

smartthings capabilities thermostatCoolingSetpoint -j
  1. In the capability definition, the command setCoolingSetpoint expects only one parameter.
  2. Also, the property Arguments is an array.
  3. If you take a look at the request sent, the body should have the following syntax:
{"commands":[{"component":"main","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[6]}]}

The main property commands is also an Array, so, you should set the variable command as an Array as well…

TL;DR, try something like this:

let commands=  [{
    "component": "cooler", 
    "capability": "thermostatCoolingSetpoint",
    "command": "setCoolingSetpoint",
    "arguments": [6]
 }]
2 Likes

Thank you. It works like a charm! The CLI is indeed helpful.

2 Likes