[SOLVED] Trying to put Number item into a timer

Hello. My rule is a simple run a timer for X hours… X being a Number item.
When I do not have the .intValue conversion… the error is:
2018-05-07 13:43:47.226 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘poolpump_hourrun_command_rule’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusHours(int) on instance: 2018-05-07T13:43:47.223-07:00

When .intValue is there I get this error:
2018-05-07 13:41:30.413 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘poolpump_hourrun_command_rule’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: pool.rules#|::0.2.0.2.0.1.2.0.1::0::/1)

Any ideas on how to get an item value into a timer?

var Timer timer_RunPump = null
rule "poolpump_hourrun_command_rule"
when
	Item poolpump_hourrun_number received command
then
	if(timer_RunPump !== null){
        timer_RunPump.cancel
        timer_RunPump = null
    }

    if(receivedCommand == 0) {
    	logInfo("rules","pool pump timer disabled.")
    }
    else {
	    logInfo("rules","setting pool pump timer for " + receivedCommand.toString + " hours.")
	    timerGL = createTimer(now.plusHours((receivedCommand as DecimalType).intValue)) [|
	        logInfo("rules","pool pump timer finished.")
	        poolpump_hourrun_number.postUpdate(new DecimalType(0))
	        timer_RunPump = null
	    ]
	}
end

Lets try this:
Create a global int variable pumpHours that can be accessed inside the timer lambda
Your bracket for the timer were in the wring place

var Timer timer_RunPump = null
var int pumpHours = 0

rule "poolpump_hourrun_command_rule"
when
	Item poolpump_hourrun_number received command
then
    pumpHours = (receivedCommand as DecimalType).intValue
    if(timer_RunPump !== null) {
        timer_RunPump.cancel
        timer_RunPump = null
    }

    if(pumpHours == 0) {
        logInfo("rules","pool pump timer disabled.")
    }
    else {
        logInfo("rules","setting pool pump timer for " + receivedCommand.toString + " hours.")
        timer_RunPump = createTimer(now.plusHours(pumpHours) [ |
            logInfo("rules","pool pump timer finished.")
            pumpHours = 0
            poolpump_hourrun_number.postUpdate(pumpHours)
            timer_RunPump = null
        ] )
    }
end

Thanks vzorglub. Good idea to move the variable to a global. The trigger bracketing was actually correct.
I did discover that my timer was named wrong! timerGL instead of timer_RunPump! :sweat_smile:

Thanks for your help!

Just found out that one can actually put the timer lambda inside or outside the brackets.
Good on you!