Exec-Node: Works fine in Linux Terminal, but not in Exec-Node

Hi,

I use terminal command to control my Samsung Oven mit SmartThings CLI. The command in the terminal is as follows and it works fine in the linux terminal:

smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

When I do run this in the Exec-Node I do get "command failed" due to the time-out that I did set.
Neither "exec" nor "spawn" options works. The time-out is 120s, which should be long enough.

It must be something about the options. If I do just call the "smartthings" command I do get a reply from the api.

I did copy & paste the command from terminal into the exec-node to be sure there is no typo.
Maybe something about the characters "/-

Try setting the full path to the command.

If still not working connect the exec node outputs to the debug nodes, configured to Output Full Message and show us what they show.

That should have read 'connect the exec node outputs to three debug nodes'.

You can find the full path to the command (smartthings) using the command
which smartthings
which will say something like
/usr/bin/smartthings
in which case the command to use in the exec node would be
/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

Hi @Colin
thanks for the fast reply.
Yes, the full path is this:
/usr/bin/smartthings
And the filling works in my linux terminal:
/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

Again, when using the Exec-Node I do rin into a time-out.
Status of the Exec-Node turns to killed

Only two of the three output nodes delivers a feedback (in exec mode):

{ _msgid: '959eef22fae89b04', topic: '', payload: { code: null, message: Command failed: /usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})', signal: 'SIGTERM' } }

{ _msgid: '959eef22fae89b04', topic: '', payload: '', rc: { code: null, message: Command failed: /usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})', signal: 'SIGTERM' } }

When switching into spawn mode, I do get the same result but only on one other the output nodes.

My timeout setting ist 120 seconds. On the linux terminal I do get a reply from the remote API after max 20 seconds.

Interestingly, when I do remove most of the parameters and switch into spawn mode, after sending this:
/usr/bin/smartthings devices:commands

I do get an instant reply from the remote API:
{ _msgid: 'd1307f656642a636', payload: 'logging in...', topic: '' }

Both myDeviceID and myToken are in format: XXXXX-XXXX-XXXXX....

As soon as I do add either the device ID, token or the command it does not work any more.

Can you export the exec node and paste it here? Change any sensitive IDs!
Paste as code using the </> button not as a screen capture.

Send the command via msg.payload

msg.payload = `smartthings devices:commands <myDeviceID> --token=<myToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'`

The Smartthings docs seem to say you don't need the = (ie --token XXXX..)
or maybe use a config file to hold the credentials ?

When passing a command including embedded quotes, in here '..."..."...' through exec node, I wonder if there is not a problem of quotes on what is executed on the host??

I would try to see effectively what is happening on the host by replacing the command itself /usr/bin/smartthings with a shell script that is saving the parameters of the exec command.

Maybe a red herring, though...

Thanks. But the issue does not seem to be just the token, but also the other parameters.

Of course as a work-around I could pack everything into a bash script and just call the script from with my exe node, but this would take some flexibility in sending different commands, that I would like to create later for more advanced use-cases.

Thanks. As suggested did use a "inject node" and did send all parameters as payload. Also I did active the "attach payload" checkbox in the exec-node.

It did not work, same result.

@jbudd here is the export

[
    {
        "id": "28321371bbc38f0c",
        "type": "exec",
        "z": "ba4e13d6eb48084d",
        "command": "/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx 'main:execute:execute(\"/mode/vs/0\",{\"x.com.samsung.da.options\":[\"Sound_Off\"]})'",
        "addpay": "",
        "append": "",
        "useSpawn": "true",
        "timer": "120",
        "winHide": false,
        "oldrc": false,
        "name": "Sound_Off",
        "x": 470,
        "y": 660,
        "wires": [
            [
                "cd1a879fb9ad1bd1"
            ],
            [
                "cd1a879fb9ad1bd1"
            ],
            [
                "cd1a879fb9ad1bd1"
            ]
        ]
    }
]

Try that. It may not work, which will tell us something.

I am not suggestions to do that forever. I am proposing to look on the host itself (in the Shell) how the full command looks like.
Simple quote and double quotes, even worse when they are embedded like in your case can give « interesting » results.

I thought that some of the "special" characters might be being mangled , deleted or misinterpreted by the shell. In fact I think your single quotes protect them all from the shell apart from the = in --token=blah
What happens if you put the single quotes around everything after smartthings?
And does this work?

/usr/bin/smartthings 'devices:commands' 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxx' '--token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx' 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

Just to clarify: when you say it works in the terminal, do you mean that typing that exact command at the dollar prompt works, or is smartthings interactive and you type in response to it's prompt?

What does file /usr/bin/smartthings show you?

Just to clarify: when you say it works in the terminal, do you mean that typing that exact command at the dollar prompt works, or is smartthings interactive and you type in response to it's prompt?

I am putting in the command and it will be executed - see screenshot:
image

The Command executed successfully is the reply from the remote API

I tried this:

/usr/bin/smartthings 'devices:commands d8965e25-caf9-5ef2-41b8-a4f11c87d25d --token=2eec27b1-3c0d-414f-b97c-912b3293e124 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})''

Doing so results in 2 errors, that appear instantly:

{"_msgid":"f1418cf01b86ebf7","payload":" › Warning: 'devices:commands is not a smartthings command.\n","topic":""}

{"_msgid":"f1418cf01b86ebf7","payload":"Did you mean devices:commands? [y/n]: ","topic":""}

And 3 further errors after a few seconds:

{"_msgid":"f1418cf01b86ebf7","payload":"\n","topic":""}

{"_msgid":"f1418cf01b86ebf7","payload":" › Error: Run smartthings help for a list of available commands.\n","topic":""}

{"_msgid":"f1418cf01b86ebf7","payload":{"code":127},"topic":""}

I also tried setting the single quotes after devices:command and also around each command. But then I had the same issue as in the beginning -> running into a time-out after 120 seconds

OK - I made a bash script called "sound_off.sh":

#!/bin/bash
/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'

Calling it on command line in the linux terminal works fine:

$ /usr/sbin/sound_off.sh
Command executed successfully

I did put the command /usr/sbin/sound_off.sh into my exec-node and interestingly getting this result after waiting 120 seconds (the timeout that I did set):

First a succes message and then a time-out error:
{"_msgid":"442ed2ec574d589e","topic":"","payload":"Command executed successfully\n","rc":{"code":null,"message":"Command failed: /usr/sbin/sound_off.sh\n","signal":"SIGTERM"}}

Same result in "exec" and "spawn" mode (in spawn mode the above message will be split into two messages)

And did it actually turn off the sound ?
Then it might be a matter of the way the script exits (or the smartthings command for that matter).