Loop rule (in OH2)

OH2 offers myTimer.hasTerminated() , but it doesn’t work unless the timer actually exists.

Problem fixed and worked perfectly well! I had to change that section for the following:

tBlink = createTimer(now) [|                                             // create a timer which is executed immediately
    iBlink++                                                            // count up (only available with int)
    if(iBlink < 201) {                                                  // while less than 201 (i.e. 100 * 2 + 1)
        gAllLights.sendCommand(if(gAllLights.state != ON) ON else OFF)  // toggle gAllLights
        tBlink.reschedule(now.plusSeconds(2))                           // reschedule Timer in 2 Seconds
    } else {                                                            // otherwise
        gAllLights.sendCommand(ON)                                      // switch ON
        tBlink = null                                                   // and delete timer
    }
]

Maybe you can explained difference between " createTimer(now,[| " and " tBlink = createTimer(now) [| ".

In fact I used that way to create timer seen in another thread without knowing exactly the difference. With the first version I had some log error related to an unhandled Exception.

2020-06-24 07:12:34.743 [ERROR] [org.quartz.core.JobRunShell ] - Job DEFAULT.Timer 58 2020-06-24T07:12:34.721-04:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
++
org.eclipse.xtext.xbase.impl.XIfExpressionImpl@13c28 (conditionalExpression: false)
} ] threw an unhandled Exception:
java.lang.NullPointerException: cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.reschedule(org.joda.time.base.AbstractInstant) on null

Well, there is no difference between

tTimer = createTimer(now, [|
    // foo
])

and

tTimer = createTimer(now) [|
    // foo
]

But the former version is more clear about the fact, that the lambda (the part between [ and ]) is a parameter of the function createTimer().