Error when running code in timer

I’m trying to get the sunset rule to work with one of my switches, but keep getting an error, and nothing I’ve tried has resolved it. Here’s the error:

02:30:45.259 [ERROR] [org.quartz.core.JobRunShell ] - Job DEFAULT.2016-02-22T02:30:45.250Z: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | { sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>) } ] threw an unhandled Exception: java.lang.RuntimeException: The name '<unkown>' cannot be resolved to an item or type.

and here’s the rule:

` import org.joda.time.*
import org.openhab.model.script.actions.Timer

var Timer tOutdoorLights

rule "React to sunset"
when
    Time cron "0 0 16 * * ?"   // Every day 16:00 hours, evaluate sunset
then
    var year   = now.getYear
    var month  = now.getMonthOfYear
    var day    = now.getDayOfMonth
    var datum  = Sunset_Time.state
    logInfo("Sunset","datum = " + datum)
    var DateTime sunset = new DateTime((Sunset_Time.state as DateTimeType).calendar.timeInMillis)
    logInfo("Sunset", "action =" + sunset.minusMinutes(518))
    var now = new DateTime()
    logInfo("Sunset", "now =" + now)

     // Cancel timer to avoid reschedule
    if(tOutdoorLights!=null) {
            logInfo("Sunset","Timer tOutdoorLights cancelled")
            tOutdoorLights.cancel()
    }
    logInfo("Sunset","Timer tOutdoorLights created")
    tOutdoorLights = createTimer(sunset.plusMinutes(15)) [|
            sendCommand(Switch_Outside, ON)
    ]
end`

The item Switch_Outside is definitely defined, and if I run that command outside of the timer it works fine.

I cannot directly see anything in your rule that I believe is wrong - of course, there may still be something that I did not spot.

Anyway, I just wanted to let you know that I believe your rule could be made much simpler by using the Astro binding and a “Sunset_Event” item like this:

Switch Sunset_Event {astro="planet=sun, type=set, property=end, offset=15"}

rule "React to sunset"
when
  Item Sunset_Event received update
then
  Switch_Outside.sendCommand(ON)
end

I realize that you may know this, and have decided against it, but just in case you did not know…

I was under the impression that the Astro binding events didn’t work in OH2. I already have the binding setup…that’s what I’m using to grab the sunset time. If I’m mistaken and Astro events do work in OH2 I’ll gladly switch to that.

From looking at the error message I get when the timer runs, it appears as though the timer is having issues accessing the item.

I did not pay attention to the tags, so I did not realize that this question was specifically related to OH2. My apologies, :frowning:

As a user of OH1 I cannot tell you whether the astro bindnig events work or not in OH2. Sorry.