Execution of startup rule ‘Init’ has been postponed as items are still missing: An error occurred during the script execution: The name ‘.createTimer(,)’ cannot be resolved to an item or type.
I tried both syntax as I saw implementations using both. Still no Joy. I know “now” is valid… not sure what is causing this to not recognize .createTimer
Not sure whether you saw, but I can call my timers
timerActive = createTimer(now.plusSeconds(1)) [|
For clarity: Timer. createtimer: do not use Timer here
When I tried your syntax, Designer (see previous link) gives me already on the screen the error that .createTimer cannot be resolved for Timer; would strongly recommend using it
Actually, OP’s syntax for that part (i.e. , [|) is valid and actually my preferred way to create timers. It’s long and technical that I’ve written it up before and won’t go into here. The tl;Dr is the stuff in [| ] defines a lambda. Lambdas are a way to pass a function around to methods like any other object or primitive (a lambda is in fact an object). The syntax shortcut that lets you write creatTimer(sometime) [| code] hides that fact. IMHO it is a bit of syntactical sugar that saves a few keystrokes but obscures what is really going on so I don’t like it.
And now to bring up a little background as to why Timer.createTimer didn’t work. In another weird language decision (note that both of these decisions were made by Xtext, not the OH developers) one must use :: to access static methods and data members of classes. So the following probably would have worked:
Timer::createTimer( ...
The Rules DSL does some magic behind the scenes so that Timer, all the core classes, Joda DateTime, and Actions are imported by default so you don’t have to put the class name in front. This is why we can use createTimer without the Timer in front.
But for other Java classes that won’t be the case. Common examples include:
My suggestion: timers are fiddly, prone to bugs (unless you are very careful), and therefore a bit rubbish. Using the expire binding instead is much more elegant and efficient: see here