Hi,
I have problem with few rules at startup. I have tried to check that all variables needed are available before proceeding in order to avoid trying to operate on nulls. However, I also have the same problem with rules where I use “builtin” data from OpenHAB, such as “now”. I am doing this wrong, or am I supposed to check that everything, even “now”, is not null before I try to use it?
One example:
// Update auto_glightsOutside_on when Astro updated or auto_glightsOutside_minBeforeSunset changed or once hourly
rule “lights_outside_evening_auto_updateTurnOnTime” when Item astro_sun_set_start changed or Item auto_glightsOutside_minBeforeSunset changed or Time cron “0 0 0/1 1/1 * ? *” then
// Default turn on at 19:00
var onTime = new DateTime(now.toString.split(“T”).get(0) + “T19:00:00+02:00”)
// Use astro & setpoint values if available
// Check that both values are set
if (astro_sun_set_start.state !== NULL && auto_glightsOutside_minBeforeSunset.state !== NULL) {
// Calculate turn on time
onTime = new DateTime(astro_sun_set_start.state.toString)
onTime = onTime.minusMinutes((auto_glightsOutside_minBeforeSunset.state as Number).intValue)
}
auto_glightsOutside_on.sendCommand(onTime.toString)
end
However, this results in an error:
2020-10-06 07:26:51.292 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘lights_outside_evening_auto_updateTurnOnTime’: ‘toString’ is not a member of ‘null’; line 189, column 28, length 12
Line 189 is the one with now.toString.