Problem with createTimer in Rules

Hi Guys,

I am having an issue with getting the createTimer function to work in my rules. I have the Timer library and var defined, but for some reason it can’t understand the ‘now.plusSeconds’ part of the code? Looking at the wiki and previous posts I seem to have everything exactly as explained elsewhere so I am wondering if this is a Win 10 issue as I have an issue with a binding that I’m also blaming on the OS.

import java.lang.*
import java.math.BigDecimal
import java.DecimalType
import java.boolean
import org.openhab.model.script.actions.Timer

var Timer timer = null

I think you are missing the following import:

import org.joda.time.*

Just added this import, still getting the same error? Is there something really obvious I am missing because it seems to me that this should just be working?

Does it run? It may just be a hick-up with Designer and not actually be a real problem with your code.

now should be accessible no matter what your imports are.

In the future, please post code, not screenshots of code. It is easier for future users experiencing similar problems to find this thread and possibly their solution, not to mention making it easier for those of us responding from mobile devices to read the text.

You can format the code by wrapping them in three back ticks:

your code

Is this true? I was sure that now, plusSeconds, etc. were all part of Joda time. Or is it so that Joda time is imported (available) by default in rules (i.e without and explicit import)?

I am also pretty sure that just a few days ago I had problems with a rule where a createTimer(now.plusSeconds(... construct simply would not fire - until I added import org.joda.time.*.

now is indeed a Joda DateTime object but it, along with your Items and Groups are part of the stuff that is automatically imported for you. At least that is what the wiki documentation implies. Of course I can no longer find where I remember reading about no on the wiki so maybe I’m nuts. I’ve never had a case where I used now and didn’t use other self created DateTime objects so I haven’t actually tested it.

In OH 2 even more things are automatically imported for you like org.openhab.core.items.* and org.openhab.core.library.types.*.

Ok I wanted to take a screenshot of the error’ I’ll post the code when I get home.

And no the code doesn’t run as intended, I thought the designer may have been having a sook too but no.

It should be turning off all the lamps, turning on the projector lamp and then turning it back off after 5 minutes. But it seems to be ignoring the timer line and a going All off -> projector on -> projector off.

What OS are you running OH on?

So I tried out the code on a different machine and it worked!

The working machine had openHAB 1.8.2 and Java Update 77. My OH server had OH 1.8.1 and the latest Java. So I thought okay maybe the OH files need to be updated, no, still didnt work, downgraded Java, no, I copied the entire openHAB and Designer folders from the working machine to my server and it works perfectly.

Im sorry I have no idea what was wrong. But to anyone that has the same problem just try it out on a different machine.

I am having the same issues with “now” in my rules. The rules aren’t executing and I am getting an error in the openhab.log file.

“Error during the execution of rule ‘Stairway Lights Off With No Motion - Bottom’: The name ‘now’ cannot be resolved to an item or type.”

Everything was working a couple days ago, now no rule using “now” works. Java issue?

openhab 1.8.2, ubuntu 14.04 all updates current.

java version "1.8.0_91"
Java™ SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot™ 64-Bit Server VM (build 25.91-b14, mixed mode)

timer2=createTimer(now.plusSeconds(120)) [|
            if (timers.state == ON)
            	sendCommand(Entry_Lights, OFF)

Any thoughts?

Also my log is nearly completely full of the following:

"2016-04-30 14:09:49.564 [ERROR] [e.x.l.lazy.LazyLinkingResource] - resolution of uriFragment 'xtextLink_::' failed.
java.lang.ClassCastException: null"


Do you have this imported?

import org.openhab.model.script.actions.*

I’m running on Win 10, openHAB 1.8.2 and Java Update 77. For me my issue wasn’t Java, something was corrupt or missing in my openHAB folder.

Do you have another machine you can test the code on?
Have you tried the demo rules? Does the timer rule work in that one?


Just double checked and I do have that import statement in all my rules files. I have a number of rules files and get the same error in all of them, even ones that haven’t changed in weeks.

Unfortunately I don’t have another system to try them out on, this is a dedicated system for openhab and zwave.



I believe I found the problem, the update to 1.8.2 added the zwave addon and I already had a 1.9 snapshot version up and running, so loading 2 is a problem. Took the snapshot one out and restarted and all seems much better. Will keep an eye on it over the next few days.


Glad it’s working for you.