"Cannot assign a value in null context" - problem with DateTime


(Michal Szymanski) #1

In item file I have:

DateTime WtrLastDate "Data ostatniego podlewania [%1$ta %1$tR]" <calendar> (Wtr)

and in a rule:

sendCommand(WtrLastDate,now)

and during execution I’ve got:
201710-07 14:18:02.962 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Watering_garden_startup': Cannot assign a value in null context.

What is wrong with rule?

MIchal


(Udo Hartmann) #2

… Please, whenever possible use the method rather than the action:

WtrLastDate.sendCommand(now)

(Mr. Wiseman) #3

Hi Udo,

Looking for some advise on this topic:

Here are my variables in the rule file.

var Number		currMonth		= now.getMonthOfYear
var Number		currDay 		= now.getDayOfMonth
var Number		currDayofWeek	= now.getDayOfWeek 
var Number		currHour	    = now.getHourOfDay

I have numerous rules referencing these variables; which I do an update on them prior to checking them in the rule itself below:

rule "Kitchen HUE Motion Sensor 7 am - 5 pm"
    when
    	Item Kitchen_Motion_Sensor received update
    then

		currHour = now.getHourOfDay
		currMonth = now.getMonthOfYear

    	if (Kitchen_Motion_Sensor.state == ON && currHour >= 7  && currHour <= 17 && Home_Away.state == ON && KitchenSensor_Luminance.state <= 70 ) {			// hours 7 am to 5 pm
...

This all works but I get a TON errors during startup like this which I’m assuming is because of these 2 lines in the rule.

		currHour = now.getHourOfDay
		currMonth = now.getMonthOfYear

The errors during a clean boot up:

2018-12-10 09:37:52.723 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Kitchen HUE Motion Sensor 7 am - 5 pm': The name 'now' cannot be resolved to an item or type; line 995, column 14, length 3
2018-12-10 09:37:52.726 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Kitchen HUE Motion Sensor 10 pm - 12 am': The name 'now' cannot be resolved to an item or type; line 1151, column 14, length 3
2018-12-10 09:37:52.729 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Loft HUE Motion Sensor 7 am - 5 pm': The name 'now' cannot be resolved to an item or type; line 1073, column 14, length 3
2018-12-10 09:37:52.732 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Kitchen HUE Motion Sensor 7 am - 5 pm': The name 'now' cannot be resolved to an item or type; line 995, column 14, length 3
2018-12-10 09:37:52.734 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Kitchen HUE Motion Sensor 10 pm - 12 am': The name 'now' cannot be resolved to an item or type; line 1151, column 14, length 3
2018-12-10 09:37:52.736 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Loft HUE Motion Sensor 7 am - 5 pm': The name 'now' cannot be resolved to an item or type; line 1073, column 14, length 3

I’m running OH2.3 on a Synology NAS.

My gut feel tells me to make these items vs. variables?

What is your recommendation on fixing this?

Best, Jay


(Udo Hartmann) #4

First of all: Why using a var at all?
Secondly, you have to define the var before using it.