This OP is about using the ScriptExecution.callScript Action. You are using the Exec.executeCommandLine Action. Very different critters.
I’m still thinking in Jython… I updated my post… try that one .
This OP is about using the ScriptExecution.callScript Action. You are using the Exec.executeCommandLine Action. Very different critters.
I’m still thinking in Jython… I updated my post… try that one .
Ahhh! Wasnt aware that existed.
Cool, accepts it now! But unforunately doesnt work, the log doesnt populate with the results and theres no errors thrown which is odd. Ill have to keep digging. It could be the script…but i thought it would at least populate the KDS_Command string item
Seems the rule is wrong, because KDS_Command isnt being updated. It still shows as 0
Don’t think that rule works Scott as you’ve defined it, if it did then it should have the right state. So i think the val command etc etc is not right.
if i go back to my old rule, tweaked
rule "Put KDS into Standby"
when
Item KDS_Power received command
then
if(KDS_Power.state == ON){
KDS_Command.postUpdate('Action Preamp/Product 2 SetStandby "0"')
var result = executeCommandLine("sudo /etc/openhab2/scripts/linn.sh@@" + KDS_Command.state,5000)
logInfo("linn", "results- " + result)
}
if(KDS_Power.state == OFF){
KDS_Command.postUpdate('Action Preamp/Product 2 SetStandby "1"')
var result = executeCommandLine("sudo /etc/openhab2/scripts/linn.sh@@" + KDS_Command.state,5000)
logInfo("linn", "results- " + result)
}
end
Nada
The log wont print the contents of your val scott
rule "Put KDS into Standby"
when
Item KDS_Power received command
then
val new_state = 'Action Preamp/Product 2 SetStandby "' + if (KDS_Power.state == ON) '0"' else '1"'
logInfo("Linn", "State=" + new_state)
KDS_Command.postUpdate(new_state)
end
This works fine for me…
rule "Put KDS into Standby"
when
System started
then
val new_state = 'Action Preamp/Product 2 SetStandby "' + if (Virtual_Switch_1.state == ON) '0"' else '1"'
logWarn("Rules", new_state)
Virtual_String_1.postUpdate(new_state)
end
2020-05-14 21:09:47.423 [WARN ] [org.eclipse.smarthome.model.script.Rules] - Action Preamp/Product 2 SetStandby "0"
openhab> smarthome:status Virtual_String_1
Action Preamp/Product 2 SetStandby "0"
I just rebooted openhab and now its started to work but still an error
Found this: [SOLVED] String update through rules
So I rebooted
13:34:01.442 [WARN ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "sudo /etc/openhab2/scripts/linn.sh" (in directory "."): error=2, No such file or directory)
The file is there as being executable.
13:34:01.136 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'KDS_Power' received command ON
13:34:01.150 [INFO ] [smarthome.event.ItemStateChangedEvent] - KDS_Power changed from NULL to ON
13:34:01.391 [INFO ] [smarthome.event.ItemStateChangedEvent] - KDS_Command changed from NULL to Action Preamp/Product 2 SetStandby "0"
kris@ihp:/etc/openhab2/scripts$ ls -la
total 64
drwxr-xr-x 4 openhab openhab 4096 May 15 13:23 .
drwxr-xr-x 14 openhab openhab 4096 Mar 19 14:05 ..
-rw-r--r-- 1 openhab openhab 870 Apr 25 2019 backup.sh
-rw-r--r-- 1 openhab openhab 844 Apr 25 2019 bomradar.sh
drwxr-xr-x 2 openhab openhab 4096 Apr 25 2019 digestAuthenWrapper
-rw-r--r-- 1 openhab openhab 197 Apr 25 2019 kodi_rescan.sh
-rwxr-xr-x 1 root root 116 May 15 11:37 linn.sh
Permissions. Make sure the openhab account can access /etc/openhab2/scripts/linn.sh. What do you see with…
ls -alh /etc/openhab2/scripts
OK… you did that . The openhab account can read it.
doh!!! root owns it, not openhab
kris@ihp:/etc/openhab2/rules$ ls -alh /etc/openhab2/scripts
total 64K
drwxr-xr-x 4 openhab openhab 4.0K May 15 13:39 .
drwxr-xr-x 14 openhab openhab 4.0K Mar 19 14:05 ..
-rw-r--r-- 1 openhab openhab 870 Apr 25 2019 backup.sh
-rw-r--r-- 1 openhab openhab 844 Apr 25 2019 bomradar.sh
drwxr-xr-x 2 openhab openhab 4.0K Apr 25 2019 digestAuthenWrapper
-rw-r--r-- 1 openhab openhab 197 Apr 25 2019 kodi_rescan.sh
-rwxr-xr-x 1 root root 117 May 15 13:39 linn.sh
Right, but everyone has read. Can you just run the script from the command line using the openhab account?
Yep! i can
kris@ihp:/etc/openhab2/scripts$ sudo -u openhab ./linn.sh
ALIVE Preamp 4c494e4e-0026-0f22-3898-012366860133
ALIVE Ds 4c494e4e-0026-0f22-3898-01236686013f
ALIVE MediaRenderer 4c494e4e-0026-0f22-3898-012366860171
I have no idea what that means . What’s in the script? Maybe add some logging to it? Or just comment out everything but a simple log to make sure that the rule runs OK.
I think its the executeCommandLine, because if I remove the @@ i get another error, totally different
13:55:06.701 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'KDS_Power' received command ON
13:55:06.999 [INFO ] [g.eclipse.smarthome.model.script.linn] - results: sudo: /etc/openhab2/scripts/linn.shAction: command not found
The script is:
#!/bin/sh
IP=192.168.0.64
PORT=23
echo ${1} | nc ${IP} ${PORT}
Let’s see… try this for the script… I will too…
#!/bin/sh
#IP=192.168.0.64
#PORT=23
echo ${1}# | nc ${IP} ${PORT}
Same issue for me, how’d you go? Basically, the rule is meant to execute the script and send the string contents as the command for the script
It will be used to switch on/off a UPNP device using the ‘NC’ program.
Had to get some ice cream… gimme a sec…
Try this for the script…
#!/bin/sh
echo ${1}
This will help show that the rule is working and openhab has access to the script.
Same issue Scott with your script
14:47:11.461 [WARN ] [clipse.smarthome.io.net.exec.ExecUtil] - Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "sudo -u openhab /etc/openhab2/scripts/linn.sh" (in directory "."): error=2, No such file or directory)
14:47:11.462 [INFO ] [g.eclipse.smarthome.model.script.linn] - results:
Try this for the rule…
rule "Put KDS into Standby"
when
Item KDS_Power received command
then
val new_state = 'Action Preamp/Product 2 SetStandby "' + if (receivedCommand == ON) '0"' else '1"'
logInfo("Linn", new_state)
KDS_Command.postUpdate(new_state)
val result = executeCommandLine("/etc/openhab2/scripts/linn.sh@@" + new_state, 5000)
logInfo("Linn", "result: {}", result)
end
We have a winner!!
That works so far Scott!
15:09:23.619 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'KDS_Power' received command OFF
15:09:23.620 [INFO ] [g.eclipse.smarthome.model.script.Linn] - Action Preamp/Product 2 SetStandby "1"
15:09:23.621 [INFO ] [smarthome.event.ItemStateChangedEvent] - KDS_Power changed from ON to OFF
15:09:23.622 [INFO ] [smarthome.event.ItemStateChangedEvent] - KDS_Command changed from Action Preamp/Product 2 SetStandby "0" to Action Preamp/Product 2 SetStandby "1"
15:09:23.673 [INFO ] [g.eclipse.smarthome.model.script.Linn] - result: Action Preamp/Product 2 SetStandby "1"
OK! So, how are things if you put your script back the way it was?