[SOLVED] Help water pump

Hi,

I’m struggling with a rule where I need your help with:

Aim: Turn water on for 2 min/5min, depending on a setpoint item ( vRegnerDauer ) in the sitemap, turn off for 30sec and repeat this 4 times.
The 30sec is done via the expire binding, using a dummy switch (Beregnung_Timer30s )
The pump itself is controlled via a plug (item eg_az_l_stecker1)

var Timer TimerBeregnung = null

rule "Beregnung an"

when

Item test_rainbird changed to ON or
Item Beregnung_Timer30s changed from ON to OFF

then

val Dauer = (vRegnerDauer.state as DecimalType).intValue
if(!(BeregnungsCounter.state instanceof Number)){
BeregnungsCounter.postUpdate(1)
} // Initializing the counter if  NULL

if(BeregnungsCounter.state > 4 ){
BeregnungsCounter.postUpdate(1)
} // reset of Counters if >4

logInfo("Beregnung", "Phase " + BeregnungsCounter.state + " startet")

if(BeregnungsCounter.state <= 4 && BeregnungsCounter.state >=1){
BeregnungsCounter.postUpdate(1+(BeregnungsCounter.state as Number))
} // count repetitive watering

if( BeregnungsCounter.state >= 1 && BeregnungsCounter.state <= 4 ) {
TimerBeregnung = createTimer(now.plusMinutes(vRegnerDauer)) [|
eg_az_l_stecker1.sendCommand(ON)]
}

if( BeregnungsCounter.state <= 3 ) { 
Beregnung_Timer30s.sendCommand(ON) 
} else {
test_rainbird.sendCommand(OFF)
logInfo("Beregnung", "Alle 4 Beregnungsphasen beendet")
}

end

This to turn off the pump:

rule "Beregnung aus"

when Item Beregnung_Timer30s changed from OFF to ON
then
eg_az_l_stecker1.sendCommand(OFF) 
end

What’s wrong with my logic here?

Error log:

2018-06-22 08:27:09.545 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Beregnung an': 
An error occurred during the script execution: 
Could not invoke method: org.joda.time.DateTime.plusMinutes(int) on instance: 2018-06-22T08:27:09.542+02:00

Kurt

var Timer TimerBeregnung = createTimer(now.plusMinutes((vRegnerDauer.state as DecimalType).intValue), [|
TimerBeregnung = createTimer(now.plusMinutes(Dauer)) [|

Thanks for both your help.
I’m still a bit lost and would love an explaination:

  1. @hr3: Why the semicolon before the [|? I’ve seen this in some of the rules posted in the forum, albeit all my other timers work without it.
  2. @vzorglub: argh…thanks for the hint…will try. (and why no semicolon in your solution btw?)

Kurt

Your code is sound apart from a couple of syntax errors.
You get the int for the amount of minutes at the begining of your rule so use that!
You need to put a space after the [ of the timer lambda
And the lambda itself goes into the createTimer action
Check the timer is null before creating it or you may end up with several if them running in parallel
Also reset the timer at the end of the timer lambda

val Dauer = (vRegnerDauer.state as DecimalType).intValue
...
if( BeregnungsCounter.state >= 1 && BeregnungsCounter.state <= 4 && TimerBeregnung === null) { // check the timer if null too...
    TimerBeregnung = createTimer(now.plusMinutes(Dauer), [ |
        eg_az_l_stecker1.sendCommand(ON)
        TimerBeregnung = null // reset the timer
    ] )
}
1 Like