Status on CodeDevice

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
Emilp
Posts: 12
Joined: 17 Oct 2015 11:15

Status on CodeDevice

Post by Emilp »

Hi,

I can´t figure out what to write to get the correct status on my switchBinary CodeDevice.
I have a shellscript turntv.sh with different inputs turns my tv on or off. I use it in Code Device like system("/opt/scripts/turntv.sh on").
The problem is that the device always shows it as off. If i run the script in shell it will echo on or off. I also have a status parameter that returns on or off but the device always shows off.

Can someone push me in the right direction here?
Guenter
Posts: 6
Joined: 15 Dec 2015 20:16

Re: Status on CodeDevice

Post by Guenter »

what you echo inside the script will be printed to stdout, but is not the result value of the 'system' call.
you can use the exit code inside the script, e.g call 'exit 0' for 'on' and 'exit 1' for 'off' and let the CodeDevice do the rest:
system('/path/to/script')[0]==0 ? 'on' : 'off'

( I am new to JavaScript, so don't ask me why this system call returns an array )
Guenter
Posts: 6
Joined: 15 Dec 2015 20:16

Re: Status on CodeDevice

Post by Guenter »

just tested the system call using the second array element, which seems to contain the Output of the script:

Code: Select all

system('/path/to/script')[1]
in this case you should avoid printing the newline at the end, like:

Code: Select all

echo -n on
Emilp
Posts: 12
Joined: 17 Oct 2015 11:15

Re: Status on CodeDevice

Post by Emilp »

Adding [0]==0 ? 'on' : 'off' after calling the script did the trick! Big thank you Guenter!
Post Reply