Script execution of rule failed - array Element type mismatch

Hi,

My rule fails when I execute a script, but when I try it manually it works fine.

owm.rules

When
Item OWM_Local_Current_Icon changed                       
then                      
if(OWM_Local_Current_Icon.state != NULL) {                                                 
val cmd = "/etc/openhab/scripts/base642png.sh currentweather \"" + OWM_Local_Current_Icon.state.toFullString.replace("data:image/png;base64,","") + "\""                                                                                                 
logInfo("owm.rules",cmd)                                                           
executeCommandLine(cmd,2000)                                               
}                                                                          
end

I will get this error:

2021-01-15 21:06:39.437 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'openweathermap-1' failed: An error occurred during the script execution: array element type mismatch in openweathermap

When I run the logged cmd in cli with sudo -u openhab /etc/openhab/scripts/base642png.sh currentweather "iVBORw0KGgoAAAANS.......... Hgf"
It’s working as expected.

Can someone help my? I can’t find the Problem.
Increasing the log Level to DEBUG for internal.handler.ScriptActionHandler doesn’t Show more Details.

Do you use OH2 or OH3 ?
The rule seems to follow the syntax of OH2 for executeCommandLine.
The error message seems to show that you use OH3 as well as the tag that is related to your post.

For OH3 the syntax of executeCommandLine has changed.
See Actions | openHAB
e.g.

var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh", itemState1, itemState2);

All arguments have to be separted by a comma.

I used OH3 and your answer fixed the error! Thanks!

Argh…

IT worked but now I get this error:

2021-01-15 23:00:52.062 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Failed to
execute commandLine '[/etc/openhab/scripts/base642png.sh currentweather "iVBO...... HhGG"]' 

In case it sometimes works but not always could the problem be related to base64 argument ?
You can add a line in your script that writes something to /tmp/ to check if the script itself is being executed.

This is my base64 Script which won’t be executed:

#!/bin/sh
echo "Hello World" > /tmp/out.file
/bin/echo "$2" | base64 -d > /etc/openhab/icons/classic/$1.png 

Still same error in log. So script won’t be executed.

Rule:

rule "Copy Current Weather Icon"                                                   
when                                                                                       
Item OWM_Local_Current_Icon changed                                        
then                                                                                       
if(OWM_Local_Current_Icon.state != NULL) {                                                 
val cmd = "/etc/openhab/scripts/base642png.sh currentweather \"" + OWM_Local_Current_Icon.state.toFullString.replace("data:image/png;base64,","") + "\""                                                                                                 
logInfo("owm.rules",cmd)                                                           
executeCommandLine(Duration.ofSeconds(5), cmd)                             
}                                                                          
end 

I See the log of the cmd (which works when I run it on console) and then the error.

Any ideas?

openhabian@openHABianDevice:/etc/openhab$ ll scripts/
total 16K
drwxrwxr-x  2 openhab    openhab 4.0K Jan 16 19:29 ./
drwxrwxr-x 14 openhab    openhab 4.0K Jan  4 22:27 ../
-rwxr-xr-x  1 openhabian openhab  110 Jan 16 19:25 base642png.sh*
-rw-rw-r--  1 openhab    openhab  236 Dec 21 15:29 readme.txt 

As stated above you have to split all the arguments for executeCommandLine to separate strings:

executeCommandLine(Duration.ofSeconds(5), "/etc/openhab/scripts/base642png.sh", "currentweather", OWM_Local_Current_Icon.state.toFullString.replace("data:image/png;base64,", ""))
1 Like

BTW since you don’t use the return value of executeCommandLine you should leave the duration parameter:

executeCommandLine("/etc/openhab/scripts/base642png.sh", "currentweather", OWM_Local_Current_Icon.state.toFullString.replace("data:image/png;base64,", ""))

That fixed it!
Thanks!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.