Rule error: The name 'now' cannot be resolved to an item

I’m getting an error I don’t understand why this is an error.

[me.internal.engine.RuleContextHelper] - Variable ‘start_boost’ on rule file ‘hotwater.rules’ cannot be initialized with value ‘.millis’: The name ‘now’ cannot be resolved to an item or type; line 9, column 24, length 3

line 9
var long start_boost = now.millis

this has worked before why is it failing now?

Please post the complete rule, thanks

What OS, openHAB and java version do you use?

I’m running openhab on Ubuntu , java version 1.8

Here is the first block of the rule file

// rules
//import org.joda.time.DateTime
var ESP_URL = 'http://esp8266-1950B1/rpc/relay'
var String HWupdateURL= "http://localhost/hotwaterbooster.php"
var Timer myTimer = null
var HotwaterLow = 37.0
var BoostTime = 60
var HotwaterTempBefore = 0.0
var long start_boost = now.millis
var email = "home@xxxxx"

var ESP_URL = “http://esp8266-1950B1/rpc/relay
Just for consistency

Thinks; this seems to a global variable. Note that “now” would be evaluated once only, at the time of the rule file being loaded. And the variable would remain set to that same value until next reload.

From past experience, trying to do evaluations in the rule file global context doesn’t seem to work as you expect anyway.

var xx = 1   // works
var yy = xx + 1  // does not work I think
                         // xx is available to rules but not in global context
                         // I guess same applies to 'now'

I checked your example on Windows10, with openHAB 2.3.0 Release Build, java 1.8.0_172 and it work without errors.

I’ve used this rule for about 12 months on v2. 2 without error so I’m sure it works, it must a random bug in 2.3

Try remove the underscore in the var ‘start_boost’
I have a slight idea that may be the reason.

Note weirdly enough I refreshed the rule by doing a edit save without changing anything and it works now as usual, it only happen after restart of openhab the other day

I get similar errors on restart only as well:

2018-06-15 21:33:01.594 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Records last thermostat update time': The name 'postUpdate' cannot be resolved to an item or type; line 47, column 3, length 48
2018-06-15 21:33:03.426 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'John's Phone': The name 'NULL' cannot be resolved to an item or type; line 66, column 23, length 4

My rule is quite simple and shouldn’t fail - it’s the check with NULL that it complains about:

rule "John's Phone"
        Item Johns_Phone changed
        logInfo("John's Phone", "John's Phone State Updated: " + Johns_Phone.state)
        if (previousState == NULL) return;

Question, will developers pick up this bug or will we need to raise it elsewhere?

hmmm getting this error again.

Is it only on restart?

Not every restart

I think they are working on a fix for this but it is very difficult apparently.
We have to live with it in the meantime.