yes, it turns the sound off. But only after the node-execution is being terminated by the time-out and the node turns into status "killed"
Can you try to add
exit 0
in the script ?
and you could try to add >/dev/null2>&1
to the end of your command as well to ignore the output and then exit.
If your script works from the command line but not from Node-red it could be an environment difference, especially if smartthings is also a shell script. That's why I asked what file /usr/bin/smartthings
shows you.
Smartthings might behave differently if it is called from an interactive shell ie the command line, or a non-interactive one but I'd expect using your script to reveal that.
I am on my phone and can't immediately see whether you have told us what versions of node red and nodejs you are using.
Also interesting to compare the outcome in the linux terminal and the exec node (spawn-mode) calling these following commands:
First, just /usr/bin/smartthings devices:commands
without any further options:
Linux Terminal is turning into "login-mode" , waiting endlessly (can not do anything until CRTL-C, neither entering token, nor deviceID helps)
/usr/bin/smartthings devices:commands
logging in... โฃท
Using same command in the exec-node returns immediatly:
{"_msgid":"39f4c3aad4b441f2","payload":"logging in...","topic":""}
After the time-out the node turns to status "killed"
So far both ways work in a consistent way.
Now I do also add just the token, nothing else and do call this on both terminal and exec-node:
/usr/bin/smartthings devices:commands --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
The terminal looks like this:
$ /usr/bin/smartthings devices:commands --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Label Name Type Device Id
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 Herd [oven] Samsung OCF xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
? Select a device.
The output of the exec-node is this:
{"_msgid":"1958eb1335e84903","payload":"โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n # Label Name Type Device Id \nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n 1 Herd [oven] Samsung OCF xxxxxx-xxxx-xxxx-xxxx-xxxxxxx \nโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n","topic":""}
{"_msgid":"1958eb1335e84903","payload":"? Select a device. ","topic":""}
{"_msgid":"1958eb1335e84903","payload":[27,91,49,57,68,27,91,49,57,67],"topic":""}
And when time-out is reached:
{"_msgid":"1958eb1335e84903","payload":{"code":null,"signal":"SIGTERM"},"topic":""}
So again, the result is more or less consitent on both terminal and exec-node.
But now the interesting part: I use both deviceID and Token (nothing else, so far):
/usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
$ /usr/bin/smartthings devices:commands xxxxxx-xxxx-xxxx-xxxx-xxxxxxx --token=xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
Herd
Components:
โโโโโโโโโโโโโโ
1 main
2 cavity-01
โโโโโโโโโโโโโโ
The terminal goes into some interactive mode where I can chose some options.
On the exec-node this happens:
{"_msgid":"92d7fa0a8230efa1","payload":{"code":null,"signal":"SIGTERM"},"topic":""}
So, when adding the deviceID, the linux terminal and the exec-node do no longer appear to work in a constant way The reply from the API is not available on the exec-node, which is exactly the issue I have been running into at the start.
Please note:
The smartthings script enters some kind of interactive mode, when parameters are missing.
The smatterings script executes the command and exits on the terminal when all parameters are set correctly.
Node-Red: 5.2.1
JS-Controller: 6.0.11
Node red current version is 4.0.5. It is shown at the bottom of the Dropdown menu in the editor.
How did you install node-red?
For the nodejs version use node -v
If you can work out the sequence of commands needed when smartthings is in interactive mode, you may be able to fudge the exec node using a template node like below and exec with no command but "append msg.payload" ticked.
/usr/bin/smartthings devices:commands <myDeviceID> --token=<myToken> << !
(Your sequence of commands to control smartthings, 1 command per line)
(include "quit", "exit" or whatever works for smartthings)
!
The << !
and final !
is "inline redirection of stdin" and it's not pretty but it might just work!
(just passing bye)
Um, so if you can run a bash script
and it turns the sound off....
edit that script to accept options.... (or sorry: one)
That being to turn the sound either off or on.
#!/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"]})'
So something like:
#!/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":' $1
and run it with (sorry scripting is not my best)
Sound_Off
or Sound_On
as parameters.
See if you can get it working that way.
Yes, I know those examples are NOT the exact things needed. Only to show what I mean.
If you get it working that way, MAYBE you could expand on it that way.
Just a thought.
Frist of all, thank you very much for the many feedbacks. I just did register two day before to post my issue here and I did get so much support!!! Thanks.
Because I am a new user here, I am restricted in the number of post, and sometimes I have to wait for hours before I can post a reply. Therfore I am packing all replies into this post.
$ file /usr/bin/smartthings
/usr/bin/smartthings: symbolic link to ../lib/node_modules/@smartthings/cli/bin/run
/////////////////////////////////////////////
Node-Red: v3.1.9
node JS v18.20.4
/////////////////////////////////////////////
$ file /usr/bin/smartthings
/usr/bin/smartthings: symbolic link to ../lib/node_modules/@smartthings/cli/bin/run
/////////////////////////////////////////////
with the >/dev/null2>&1
I do get a "permission denied"
/////////////////////////////////////////////
Yes, did this and it works. I wrote a script /usr/sbin/samsung_setSound.sh
:
#!/bin/bash
/usr/bin/smartthings devices:commands $1 --token=$2 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["'$3'"]})'
exit 0
Then I do call it from the exec-node like this:
/usr/sbin/samsung_setSound.sh xxxxxx-xxxx-xxxx-xxxx-xxxxxxx xxxxxx-xxxx-xxxx-xxxx-xxxxxxx "Sound_Off"
As soon as the exec-node runs into the time-out, that I did set to as short 1s I get the results:
{"_msgid":"db9216da39f278ce","payload":"Command executed successfully\n","topic":""}
{"_msgid":"db9216da39f278ce","payload":{"code":null,"signal":"SIGTERM"},"topic":""}
Still not perfect because of the time-out, but at least I get what I was looking for.
I have boosted your trust level, so that should be improved.
I think it must be something unusual about the way the smartthings command is spawning sub-processes to do the work, which is confusing the exec node. If you run the command directly from the command line then after it returns to the prompt what does this command show?
ps aux|grep smartthings
I don't know whether there were any improvements in that area but it would be worth upgrading to the latest node-red, if you can, just in case the situation has improved.
You didn't answer the question - How did you install node-red?
Did you try my inline redirection suggestion?
This is how it looks like:
$ /usr/bin/smartthings devices:commands <deviceID> token=<authToken> 'main:execute:execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})'
Command executed successfully
$ ps aux|grep smart things
peter 5516 0.0 0.0 6612 2304 pts/0 S+ 00:47 0:00 grep --color=auto **smartthings**
It came with my ioBroker. There is an official so-called "adapter" for node-red. v3.1.9 is the latest available version of the adapter. I need to find out how to upgrade without breaking my ioBroker system.
In the interactive mode it goes like this:
$ /usr/bin/smartthings devices:commands <deviceID> --token=<authToken>
Herd
Components:
โโโโโโโโโโโโโโ
1 main
2 cavity-01
โโโโโโโโโโโโโโ
? Enter component index or id: main
Capabilities:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 ocf
2 execute
3 refresh
4 remoteControlStatus
...
24 custom.disabledCapabilities
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
? Enter capability index or id: execute
Commands:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 execute(command<string>, [args<JsonObject>])
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
? Enter command: execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})
Command executed successfully
$
So, I changed my script like this:
#!/bin/bash
/usr/bin/smartthings devices:commands <deviceID> --token=<authToken> << !
main
execute
execute("/mode/vs/0",{"x.com.samsung.da.options":["Sound_Off"]})
!
Result in linux terminal is: Error: got simple string from stdin
OK well
main
execute
...
is what I had in mind, so I assume that you have used the right syntax for the actual command, even though it looks like several commands combined as one.
And that's not exactly a simple string, so I wonder if it's the !
that triggers the error.
Is there a quit command for the CLI, besides CTRL - C, that you can include before the !
?
Maybe I have you chasing red herrings and it's not worth pursuing this approach any more.
Where did you actually find the command format you are using ?
Looking at the (extensive) documentation, it should be something like:
smartthings devices:commands <device-id> 'switchLevel:setLevel(50)'
No, the smartthings just exits automatically, either once a command is sent or the user inputs anything "invalid"
The SmartThings API works in a very generic way because it supports wide range of devices. There are many functions you could not call just like you described it above. In many cases you have to call an "execute" command and provide somethings that looks like a CLI that will be forwarded to the device. Sometimes the commands are not officially documented and people are "sniffing" their Samsung APPs to find out, what is going on.
I did find the commands for the sound setting here: LINK
Also in alternative to using the smartthings CLI script, you could call the RestAPIs directly using a http-request node, but when I started I thought it would be more convenient to use an official script, that handles all the communication and I "just" need to call the command...
Ok,
could you try your script using this:
#!/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"]})' & PID=$!; sleep 3; kill -s SIGINT $PID
it will capture its PID and kills it after 3 seconds. Run it in exec mode.