OH2 to OH3 script conversion

Hi All

This mostly works, but pops up errors constantly.

Script execution of rule with UID 'spotify-2' failed: An error occurred during the script execution: index=1, size=1 in spot

I saw there was a change to the way it executes command line, so I managed to fix the array error, but this is a new one

I believe it’s one of the first 2 rules


rule "Spotify run script"
when
                Item spotify_forceupadte received update
        then
        var resp =  executeCommandLine("/usr/bin/python /etc/openhab2/scripts/spotify.py", 5000)
//        logInfo("Spotify", resp)
end

rule "Spotify Action"
when
                Item spotify_action received update
        then
        var resp =  executeCommandLine("/usr/bin/python /etc/openhab/scripts/spotify.py", + spotify_action.state.toString, 5000)
 //       logInfo("Spotify", resp)
end

rule "spotify live update"
when
        Time cron "0/30 * * * * ?"
then

    if (spotify_current_playing.state == ON && parse(spotify_lastConnectionDateTime.state.toString).plusSeconds(40).isBefore(now)) {
        sendCommand(spotify_forceupadte, ON)
    }
end

rule "spotify update"
    when
        Time cron "0 0/30 * * * ?"
    then
        logInfo("Spotify", "Chron prelock")
        if (parse(spotify_lastConnectionDateTime.state.toString).plusSeconds(45).isBefore(now)) {
            sendCommand(spotify_forceupadte, ON)
        }
end

Any pointers?

Thanks guys

Check OpenHab docs EXEC actions.

Your first rule and second rule should probably have the following for executeCommandLine:
1.

executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python", "/etc/openhab2/scripts/spotify.py")
executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python", "/etc/openhab2/scripts/spotify.py", spotify_action.state.toString)

The syntax of the execute CommandLine has changed. Try:

var resp =  executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python","/etc/openhab/scripts/spotify.py",spotify_action.state.toString)
1 Like

Thank you Martin!!

This tells you it is complaining about the second rule from file spotify.rules, for a head start in debugging.

This unhelpful but common message tells you it has something to do with “arrays”.
But wait, I don’t have arrays in my rule?
In this context it is usually talking about the ‘array’ of arguments (x,y,z) to some function.

logInfo("test")
for an example will produce that same error, because logInfo() wants at least two parameters.

So here you’ve only one function, executeCommandLine(), and can deduce there is something wrong with its parameters.

There is a typo in your rule:

rule "Spotify Action"
when
                Item spotify_action received update
        then
        var resp =  executeCommandLine("/usr/bin/python /etc/openhab/scripts/spotify.py", + spotify_action.state.toString, 5000)
                                                                    //  problem is here ^^^

 //       logInfo("Spotify", resp)
end

Either use comma or plus, not both. I guess you have to also add a space.

1 Like

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