The value of the local variable xy is not used

the following rule is running fine, altough I always receive this message in openhab.log:

The value of the local variable adddelay is not used

the rule for that:

rule "Systemdevice is offline"
    when
        Member of gHeartbeat changed from ON to OFF
    then
        var Timer adddelay = null
        adddelay = createTimer(now.plusMinutes(2), [ |
            if (gHeartbeat.state == OFF) {
                logInfo("Systemdevice is offline", "check device: " + triggeringItem.name)
                }])
    end

I found lots of rule example exactly doing the same Timer delays, but why do I always get that messages?

Because you are creating a variable named adddelay.

You then assign a new Timer that you created to adddelay.

Then the Rule exits and adddelay goes away without ever being used.

If you want to be able to look at the created Timer the next time the Rule runs or some other Rule runs, move the var Timer adddelay = null above all the Rules so it is a global.

If you don’t, get rid of it because you aren’t doing anything with it.

        createTimer(now.plusMinutes(2), [ |
            if (gHeartbeat.state == OFF) {
                logInfo("Systemdevice is offline", "check device: " + triggeringItem.name)
             }
        ])

I have a rule where I am seeing the same thing, but not on every reload.
BTW I never see that message when the rule is reloaded after an edit.

In my alarm decode rules I have

val String PATTERN = "MM/dd HH:mm "

rule "Front Door"
when
    Item zone1 changed from CLOSED to OPEN
then
    var String ts = now.toString(PATTERN)
    var String home = Home_Away.state

    if (home == NULL || home != "AWAY") home = "HOME"

    postUpdate(zone1_Last, ts + "Front Door Opened")
    if (home != "HOME" || 
	  (home == "HOME" && (now.getHourOfDay > 22 || now.getHourOfDay < 6))) {
        sendBroadcastNotification("Front Door Opened")
    }
end

Every rule have the same lines until the postUpdate, so both home and ts have always been used

Sometimes I have seen the message repeated a few time, but mostly it reports one or both ts and home once

One other form I have is like this for the windows: (and one non-entry door)

rule "Side Door"
when
    Item zone5 changed from CLOSED to OPEN
then
    var String ts = now.toString(PATTERN)

    postUpdate(zone5_Last, ts + "Side Door Open")
end

Also is there a way to invoke the rule parser without doing a restart?

tom

I had an incident of this transient error just last night, , value of local variable id not used. “id” is a declaration within a rule, set to this or that, and used in a postUpdate, not dissimilar to that last example.

Occurred at system boot time, re-saving the .rules file parsed just fine.
OH 2.4.0 release.

May be significant that we have two-character names in common, but I doubt that.
In my case, i had two similar rules with a local id (string) variable, which should be fine of course, but later changed one to different name as a precaution.

Ok I changed ts to timestamp and same problem.

i will clean the file up and if I still get problems I will post the whole thing

Very strange… I split the file by putting all the ones that did about the same thing together.

No warnings

Here are both files,I even put them back together and the error came back!

val String PATTERN = "MM/dd HH:mm "

rule "Front Door"
when
    Item zone1 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)
    var String home = Home_Away.state

    if (home == NULL || home != "AWAY") home = "HOME"

    postUpdate(zone1_Last, timestamp + "Front Door Opened")
    if (home != "HOME" || 
	  (home == "HOME" && (now.getHourOfDay > 22 || now.getHourOfDay < 6))) {
        sendBroadcastNotification("Front Door Opened")
    }
end

rule "Laundry Door"
when
    Item zone2 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)
    var String home = Home_Away.state

    if (home == NULL || home != "AWAY") home = "HOME"

    postUpdate(zone2_Last, timestamp + "Laundry Door Opened")
    if (home != "HOME" || 
	  (home == "HOME" && (now.getHourOfDay > 22 || now.getHourOfDay < 6))) {
        sendBroadcastNotification("Laundry Door Opened")
    }
end

rule "Back Door"
when
    Item zone8 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)
    var String home = Home_Away.state

    if (home == NULL || home != "AWAY") home = "HOME"

    postUpdate(zone8_Last, timestamp + "Back Door Opened")
    if (home != "HOME" || 
          (home == "HOME" && (now.getHourOfDay > 22 || now.getHourOfDay < 6))) {
        sendBroadcastNotification("Back Door Opened")
    }
end

and

val String PATTERN = "MM/dd HH:mm "

rule "FR Motion"
when
    Item zone3 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)

    postUpdate(zone3_Last, timestamp + "FR Motion")
end

rule "DR Motion"
when
    Item zone4 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)

    postUpdate(zone4_Last, timestamp + "DR Motion")
end

rule "Side Door"
when
    Item zone5 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)

    postUpdate(zone5_Last, timestamp + "Side Door Open")
end

rule "BR Windows"
when
    Item zone6 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)

    postUpdate(zone6_Last, timestamp + "BR Windows Open")
end

rule "MBR Windows"
when
    Item zone7 changed from CLOSED to OPEN
then
    var String timestamp = now.toString(PATTERN)

    postUpdate(zone7_Last, timestamp + "MBR Windows Open")
end

It remains a mystery, for now…

Try giving each var a unique name e.g. timestamp1 , timestamp2. Obviously this shouldn’t matter but it might give a lead for recreating the problem for a bug report.