smartthings-cli icon indicating copy to clipboard operation
smartthings-cli copied to clipboard

question: How to run multiple commands at one?

Open deltamelter opened this issue 9 months ago • 5 comments

What is your question? Please describe. How can I run multiple commands?

I want to submit multiple commands like this: [ {"capability":"samsungce.dryerCycle", "command":"setDryerCycle", "arguments":["Course_1F"]}, {"capability":"samsungce.dryerDelayEnd", "command":"setDelayTime", "arguments":["642"]}, {"capability":"samsungce.dryerOperatingState", "command":"start"}, ]

This is possible with curl POST but I don't want to have to keep renewing the PAT/bearer token ever 24 hours. How long does the token last with this cli tool? It's been > 24hrs since I last authenticated so I assume smartthings-cli uses a long living token or smartapp token maybe?

deltamelter avatar Feb 23 '25 19:02 deltamelter

Ah, never mind I had a type-typo in the json, it works as required with -i <file.json>.

deltamelter avatar Feb 23 '25 21:02 deltamelter

-i file.json works, but can't get this to work with -j even when using the same json.

./smartthings devices:commands cdXXXXXX-275e-XXXX-ef4b-XXXXXX6ba429 -j '                   [
      {
        "capability": "samsungce.dryerCycle",
        "command": "setDryerCycle",
        "arguments": ["Course_1F"]
      }]'
    AxiosError: Request failed with status code 422:
    {"requestId":"40229XXXXXXXXXX7115","error":{"code":"ConstraintViolationError","message":"The request is
    malformed.","details":[{"code":"NotValidValue","target":"commands[0].component","message":"\n    [\n
      {\n        \"capability\" is not a valid value.","details":[]}]}}
    Code: ERR_BAD_REQUEST

deltamelter avatar Feb 24 '25 18:02 deltamelter

The -j ~command~ flag doesn't take any arguments and you can't specify more than one command on the command line like that. You could instead pipe the commands to the CLI:

echo '[{"component": "main", "capability": "switch", "command": "off"}]' | st devices:commands <device-id>

(Note that JSON is the default for non-tty input so there is seldom a need for the -j flag.)

rossiam avatar Feb 24 '25 20:02 rossiam

Thanks. this works just as required and with multiple commands.

Will the authentication token work indefinitely of will it need to be renewed/re-auth'd periodically?

deltamelter avatar Feb 24 '25 20:02 deltamelter

No, the token won't work indefinitely - you'll be prompted to log in once it expires.

rossiam avatar Mar 06 '25 14:03 rossiam

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 06 '25 02:05 github-actions[bot]