Correct syntax for SmartThings CLI devices:commands

I’ve tried several permutations to use the devices:command syntax with no luck. Any help is appreciated.

henryrobinson@RobinsonFamily smartthings % smartthings devices:commands                                               
──────────────────────────────────────────────────────────────────────────────────────────────────────────
 #   Label                    Name                            Type   Device Id                            
──────────────────────────────────────────────────────────────────────────────────────────────────────────
 1   Aeotec MultiSensor 6     aeotec-multisensor-pr           ZWAVE  5ccd5cd8-d12b-4000-bd25-987ae0da8b9f 
 2   Deck                     ge-plugin-scene                 ZWAVE  e36c7b5a-b4db-499e-bc05-f097492cfc6a 
 3   Dining Room Alcove       Leviton Dimmer Switch           ZWAVE  6c092e48-d616-423b-a621-ee951f8acab1 
 4   Eric Closet              Leviton Dimmer Switch           ZWAVE  83751c00-3a5b-4061-8601-969f838a1974 
 5   Eric Closet Switch       Leviton Dimmer Switch           ZWAVE  b1a290d6-1fa2-4de0-a922-3f3f8b73034e 
──────────────────────────────────────────────────────────────────────────────────────────────────────────
 6   Front                    c2c-ring-camera-rtsp            VIPER  ee392f84-6615-48fc-bc15-5f7d259a6d37 
 7   Gate                     c2c-ring-doorbell-battery-rtsp  VIPER  15360905-82b0-4f88-8f90-c281fd602e4a 
 8   Hearts                   ge-plugin-legacy                ZWAVE  8c350809-d794-4e44-abcc-102d253e8bc9 
 9   Hutch                    ge-plugin-legacy                ZWAVE  b2078dfa-fd21-404f-b216-8787a67ac090 
 10  Hutch Under Counter      Leviton Dimmer Switch           ZWAVE  8f98b012-9310-4770-a0f5-5a519e5d2d17 
──────────────────────────────────────────────────────────────────────────────────────────────────────────
 11  Kitchen 4 button         Leviton-zrcs4-pr                ZWAVE  ec735f32-1b14-4463-837e-c86b5f07272c 
 12  Kitchen Cabinet Cans     Leviton Dimmer Switch           ZWAVE  9a5495d8-1114-4429-bf1a-8ba6b8d2c7cd 
 13  Kitchen Can              Leviton Dimmer Switch           ZWAVE  5476f709-c4a1-4f1a-94b1-c530b90be841 
 14  Laundry Light            Leviton Dimmer Switch           ZWAVE  e1a90f5e-3faa-4fa4-af03-70a4d9af5fc8 
 15  Leviton 1 Button Switch  Leviton-zrcs1-pr                ZWAVE  a6fed7df-4497-41de-b197-bfe6b2c78e28 
──────────────────────────────────────────────────────────────────────────────────────────────────────────
 16  Leviton 4 Button Switch  Leviton-zrcs4-pr                ZWAVE  e0d01d4f-0bf5-4ca2-8ac9-3fc660660404 
 17  SmartThings Hub          SmartThings v3 Hub              HUB    00ffe28e-3b89-4222-8a64-964fb0fca545 
 18  Under Cabinet Lights     Leviton Dimmer Switch           ZWAVE  7d81640d-d222-4711-85a2-d8fb3acce457 
 19  Window                   Leviton Dimmer Switch           ZWAVE  75965001-38f5-4a82-97a2-1c900efbcded 
──────────────────────────────────────────────────────────────────────────────────────────────────────────
? Select a device. 11

Kitchen 4 button

Components:
────────────
 1  main    
 2  switch2 
 3  switch3 
 4  switch4 
────────────

? Enter component index or id 1

Commands:
──────────
 1  off() 
 2  on()  
──────────

? Enter command 1
Command executed successfully
henryrobinson@RobinsonFamily smartthings % smartthings devices:commands ec735f32-1b14-4463-837e-c86b5f07272c 'main:off()'
    Error: Request failed with status code 422: {"requestId":"BE7DAC4F-531B-4CD4-96E2-17E936FD2BBF","error":{"code":"ConstraintViolationError","message":"The request is 
    malformed.","details":[{"code":"NotValidValue","target":"commands[0].capability","message":"main is not a valid value.","details":[]}]}}
henryrobinson@RobinsonFamily smartthings % smartthings devices:commands ec735f32-1b14-4463-837e-c86b5f07272c 'main:off'  
    Error: Request failed with status code 422: {"requestId":"BA8D28CA-440B-4A61-8C98-96A9B48F9AE2","error":{"code":"ConstraintViolationError","message":"The request is 
    malformed.","details":[{"code":"NotValidValue","target":"commands[0].capability","message":"main is not a valid value.","details":[]}]}}
henryrobinson@RobinsonFamily smartthings % 
 > smartthings devices:commands --help
execute a device command

USAGE
  $ smartthings devices:commands [ID] [COMMAND] [-h] [-p <value>] [-t <value>] [--language <value>] [-j] [-y] [-i <value>]

ARGUMENTS
  ID       the device id
  COMMAND  the command [<component>]:<capability>:<command>([<arguments>])
8<--snip--8<

So I’d suggest smartthings devices:commands ec735f32-1b14-4463-837e-c86b5f07272c main:switch:off based on that.

That said, the help text actually implies a leading : and trailing ().

It will also allow you to select the device and guide you through the command hierarchy if you simply enter “smartthings devices:commands”.

? Select a device. 26

Front Door Lock

Components:
─────────────
 1  main     
 2  settings 
─────────────

? Enter component index or id 1

Capabilities:
────────────────────────────────────────
 1  lock                                
 2  platinummassive43262.unlockCodeName 
 3  lockCodes                           
 4  tamperAlert                         
 5  battery                             
 6  refresh                             
────────────────────────────────────────

? Enter capability index or id 3

Commands:
───────────────────────────────────────────────────────────────────
 1   setCodeLength(length<integer>)                                
 2   reloadAllCodes()                                              
 3   unlock()                                                      
 4   unlockWithTimeout()                                           
 5   setCode(codeSlot<integer>, codePIN<string>, codeName<string>) 
 6   requestCode(codeSlot<integer>)                                
 7   lock()                                                        
 8   updateCodes(codes<JsonObject>)                                
 9   deleteCode(codeSlot<integer>)                                 
 10  nameSlot(codeSlot<integer>, codeName<string>)                 
───────────────────────────────────────────────────────────────────

? Enter command 2
Command executed successfully

Thank you both. Yes, using the command hierarchy was a good start but then the cli wanted the capability (switch) between the component and command. Now I get it.

Thanks

I think that was what the OP was trying to replicate. Unfortunately the CLI flow didn’t make it clear that there was an intermediate stage where it would have prompted for the switch attribute had a choice been required.

Some commands may require the parens:

 st devices:commands c51f9d0f-8e2b-4966-9644-6d5f5d889eeb main:lockCodes:setCode\(8,\"987654\",\"Test\"\)

and in Linux, at least, must be escaped as shown above.

I tried the following and both were accepted:

henryrobinson@RobinsonFamily smartthings % smartthings devices:commands ec735f32-1b14-4463-837e-c86b5f07272c 'switch2:switch:on()'
Command executed successfully
henryrobinson@RobinsonFamily smartthings % smartthings devices:commands ec735f32-1b14-4463-837e-c86b5f07272c 'switch2:switch:on'  
Command executed successfully
henryrobinson@RobinsonFamily smartthings % 
1 Like