Help with rule, possibly type conversation problem

Hello Everyone,

I’m trying to create a rule for my Receiver to always start with a specific volume. Problem is, only command I can give to it is volume up or down (VU, VD, ?V via telnet)

?V gives me VOL053 or similar outputs

I came up with the following logic:

var String CurrentVolume = executeCommandLine("python /etc/openhab2/scripts/pioneer.py ?V", 2000)
        //var CurrentVolumeInt = Float::parseFloat(CurrentVolume.substring(4)) as Number
        var CurrentVolumeInt = Integer.parseInt(CurrentVolume.substring(4))
            if (CurrentVolumeInt < 55) {
                var Difference = (55 - CurrentVolumeInt)
                var i = 1
                while ((i=i+1) < Difference) {
                    executeCommandLine("python /etc/openhab2/scripts/pioneer.py VU", 1000)
                }
            }            
        logInfo("","" + CurrentVolumeInt)

Basically, I check the current volume, if its lower then my desired (55) then I calculate how low, and send that many VU commands.

Its not working (obviously) and I suspect I do not properly understand how to convert the String value I get from the ?V command to an Int to do the calculations/looping
I tried to read other threads and try the things from there, as you can see from the commented line, but no luck.

I get this error on the log:

2021-01-04 17:20:16.238 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'PioneerVolume': For input string: "39
"

Any ideas what am I doing wrong here?

Try with

var CurrentVolumeInt = Integer.parseInt(CurrentVolume.substring(5))

or add logInfo with CurrentVolume value before parse.
It looks that you parse quotation mark together with number.

@mqm0
After migration from oh2 to oh3 all my rules with execteCommandLine become buggy. It seems there have been some changes in oh3. executeCommandLine needs following setup

// When you are not interested in the script output
executeCommandLine("path/to/my/script.sh", itemState1, itemState2);

// When you need the output in your further rule processing
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh", itemState1, itemState2);

or Try with

        var Number CurrentVolumeInt = new DecimalType(CurrentVolume.split("VOL").get(1))