Rule issue

anyone can help me to fix this rule ?

rule "Reboot Display EG" 
when
Item resetdisplay changed to ON
then {
	val String results1 = executeCommandLine("ssh root@10.10.10.13 shutdown -r 2>/dev/null", 5000)
    logInfo("Reboot display", results1)
    resetdisplay.sendCommand(OFF)
	 }
end

results in

==> /var/log/openhab/openhab.log <==
2020-10-19 11:07:13.892 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: An error occurred during the script execution: array element type mismatch in haus

thanks
Thomas

I moved your off-topic post to a new thread.
Stay on topic please.

The rule was working in OH 2.5.9 and stopped in 3.0 !

Just guessing, but the { after then and } before end are not needed.

Your issue likely is not specific to the OH3 code (more likely to your setup), and for sure not of general nature as I requested everybody a couple of posts up.

1 Like

I don’t see some reference to “haus” in your rule, and I assume the error must be somewhere else?

the file is called haus.rules
removed the {} but still the same, i guess the issue is with the executeCommandLine script in OH3
the rule was working perfect in 2.5.9
thanks
Thomas

2 ideas you could try

  • Exchanging the whitespaces with @@ (but this should´ve be a problem in OH2 also)
  • Maybe theres a need to add your command in the exec.whitelist (as you have to do, when triggering an exec cmd from the thing channel-configuration)

Just guesses, without testing any of these.

Hmm, a redirect. What will be a bit different from “native” OH2 rule to OH3 rule running under a DSL interpreter of the new rule engine … is the context.
Pipes and so on are often problematic with executeCommandLine, because it does not run in a shell context.
I believe the exec code does some uhh kludges to try and work with simulating pipes by itself, maybe this is where the “array” comes in.

This is not the same, but feels similar. I have no knowledge to look deeper or experiment, but would at least try without the redirect.

removed the redirect, still same … will play around and update if there is a solution

Here’s a post I stumbled on

the syntax of the executeCommandLine changed in the DSL syntax, but i managed to find my way:

but the new example makes little sense to me!

EDIT - aha, parameters greatly changed

Thanks rossko57
this solves the error in the log, but the remote pi is not booting

rule "Reboot Display EG" 
when
Item resetdisplay changed to ON
then {
	val String results1 = executeCommandLine(Duration.ofSeconds(15),"/usr/bin/sh","/usr/bin/ssh root@10.10.10.13 shutdown -r")
	logInfo("Reboot display", results1)
	resetdisplay.sendCommand(OFF)
	 }
end

this solves only the error but the remote pi is not booting :frowning:

Is ‘sudo -u openhab ssh root@10.10.10.13 shutdown -r’ working, on manual execution?

yes, only solution to get it work is creation of reboot sh file

[13:24:15] root@t2:/etc/openhab/scripts# more reboot_display.sh
ssh root@10.10.10.13 shutdown -r 2>/dev/null

  • chmod + chown +adding it to whitelist
    and the below rule
rule "Reboot Display EG" 
when
Item resetdisplay changed to ON
then {
	var result=executeCommandLine(Duration.ofSeconds(15),"/usr/bin/sh","/etc/openhab/scripts/reboot_display.sh")
	logInfo("Reboot display", result)
	resetdisplay.sendCommand(OFF)
	 }
end

The parameters of executeCommandLine have changed.
The timeout is now the first parameter and has changed from integer in milliseconds to Duration type.
Then are following the command string(s).
Before it was one string, now it has to be splitted at every space delimiter or at the @@ delimiter.

Your old command:

val String results1 = executeCommandLine("ssh root@10.10.10.13 shutdown -r 2>/dev/null", 5000)

New command:
val String results1 = executeCommandLine(Duration.ofSeconds(5), “ssh”, “root@10.10.10.13”, “shutdown”, “-r”, “2>/dev/null”)

3 Likes

Thanks for the Info, working fine now !

Would it be possible to add this to the docs as an example? After updating from OH 2 to OH 3, it took me some time to find this solution.

1 Like