Rule stopped working

I have a rule that was working once, but recently I noticed it didnt anymore and I cant figure out why.
It is supposed to set a timer when my garagedoor opens and then after 20 min send an email with a warning it is still open.
However… nothing happens.

In Eclipse designer I do get an error on ‘The method sendMail is undefined’ but I understand that to be a non error.
I know my sendmail setup is working as it is working in other rules.

My rules file looks like this

var Timer garageTimer

rule "Garage open too long"
when 
	Item Garage_Door changed to OPEN or
	Item Garage_Door changed to CLOSED
	//Item Garage_Door received update
then
	if(garageTimer != null) {
		garageTimer.cancel
        garageTimer = null
    }
    
    if(Garage_Door.state == OPEN){
		garageTimer =  createTimer(now.plusMinutes(20)) [|
		logInfo("org.openhab","Logging timer state")

		sendMail("xxxxl@gmail.com","WARNING Garage Door has been open for 20 minutes", "Close It")
	      ]
      }
      
end

If I look at my loginfo I do see something odd:

The name 'sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.
Apparently there is an ‘unhandled exception’, but I have no idea why that is.
Below the bar I have put some more info from the log file.

Anyone any idea what this could be?? The mailbinding is installed, the mail.cfg is populated and other ‘mailing’ rules work fine.
The item does generate a state change:


//===============

org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  logInfo(<XStringLiteralImpl>,<XStringLiteralImpl>)
  sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)
  sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>)
  sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>)
  <XFeatureCallImplCustom>.sendCommand(<XFeatureCallImplCustom>)
} ] threw an unhandled Exception: 
java.lang.RuntimeException: The name 'sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:112)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:29)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at com.sun.proxy.$Proxy102.apply(Unknown Source)[:]
	at org.eclipse.smarthome.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)[104:org.eclipse.smarthome.core.scheduler:0.9.0.b5]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)[104:org.eclipse.smarthome.core.scheduler:0.9.0.b5]
2017-11-11 13:39:46.577 [ERROR] [org.quartz.core.ErrorLogger         ] - Job (DEFAULT.2017-11-11T13:39:46.569+01:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  logInfo(<XStringLiteralImpl>,<XStringLiteralImpl>)
  sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)
  sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>)
  sendCommand(<XFeatureCallImplCustom>,<XFeatureCallImplCustom>)
  <XFeatureCallImplCustom>.sendCommand(<XFeatureCallImplCustom>)
} ] threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.RuntimeException: The name 'sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)[104:org.eclipse.smarthome.core.scheduler:0.9.0.b5]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)[104:org.eclipse.smarthome.core.scheduler:0.9.0.b5]
Caused by: java.lang.RuntimeException: The name 'sendMail(<XStringLiteralImpl>,<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:112)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:29)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
	at com.sun.proxy.$Proxy102.apply(Unknown Source)[:]
	at org.eclipse.smarthome.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)[104:org.eclipse.smarthome.core.scheduler:0.9.0.b5]
	... 1 more

How do you edit your rule files?
Maybe there is a (invisible) char or a false line feed…

thanks Udo. I use eclipse smart designer and sometimes bluefish. That should be ok I guess.
I understand from yr answer that at least u see no faults in my rule :slight_smile:

Dear Kees. I had sometimes strange error messages with rules as well. Try renaming the rule file garage.rules -> garage.test and back again…

Thank you, i will give that a try, although the rule does run and the timer is created, it just crashes on the sendmail.

Sadly that wasnt the solution either

Yes, that’s correct. however, you could change the two trigger lines to one simple line.

Item Garage_Door changed

would fit, as the Item shouldn’t change to a state other than OPEN or CLOSED, should it?
But this wouldn’t solve the problem. I can’t see any typo and nor does the designer itself.

indeed, I tried several changes in that section, but the code runs undisturbed till after the timer is created and then crashes on the sendMail. Can’t figure it out. I know one can get that message if there is an undefined state, like right after start up, but that’s also not the case.
Really have no idea what is wrong

The last thing to try is, to write down the rule in a new rule file (don’t copy and paste though but do it manually!!!)

I had been thinking about that. Weird as it is.
I already tried pasting it in a simple straight text editor, hoping to get rid of any stray characters (in case that would be the issue), but that didnt help. I will give it a try.

Sadly, same problem

This rule works without problems:

var Integer RandomInterval = (Math::floor((Math::random * (25) + 5).doubleValue).intValue)
rule "General - lightsoff"
when
Time cron "0 29 22 1/1 * ? *" // 10.29pm  => 10.34 <>10.54
then
   	 RandomInterval = (Math::floor((Math::random * (15) + 0).doubleValue).intValue)
   	  LightsOffTimer = createTimer(now.plusMinutes(RandomInterval)) [| sendMail("xxxxxx@gmail.com", "burglarrules", "het licht is uitgegaan") ]
  
end

so I really cant figure out what is wrong with the orther rule

Just to make sure, I renamed the item. That didnt help.
Anybody have another solution??

I am having a similar issue… Did this get resolved? Would there be a way to see stray characters if using vi editor?

I have a rule that sets status of a device and it runs a few times and then just stops. I am looking for tips on how to troubleshoot. The device is a z-wave lock, I have tried looking at the z-wave and the rules logs via Karaf but I see nothing that calls my attention.

How can I check if the rules engine is running?

Please consider to use VSCode with openHAB plugin to edit any file. VSCode is the official editor for openHAB, eclipse Smarthome Ddesigner is end-of-life.

3 Likes

Hector, apologies that I haven’t picked up on your reaction earlier.
I am not sure anymore if this got solved as in fact I still have some trouble with this rule and some others that only seem to work for one day, but that is the subject of a more recent post

@Udo_Hartmann I will try setting that up and see how it goes editing the files through there. I typically just ssh to my OH box, will I be able to connect to a remote server using that setup?

@Kees_van_Gelder Ill keep poking around the forum to see if I find anything that will help. So far it seems like its this one rule so I am thinking there may be something OH doesn’t like. I implemented that rule I found on a post in this forum and it seems like it works for others so I may be missing something in my setup.

1 Like

You have to setup a samba share to get remote access to the configuration. When using openHABian, this is activated by default.

Ok great, not using openHABian but I did find some documentation that should be helpful on the openhab web site. I’ll give that a try.

Just got VSCode with openHAB plugin set up. In case anyone runs into this, you can find the info here…

VSCODE
https://code.visualstudio.com/Download

and

openHAB plugin
https://github.com/openhab/openhab-vscode/blob/master/README.md

I have used it to modify my files and while I have not been able to get it to work, I can say that I see it very useful.

I was able to resolve my issue, turns out I had MySQL persistence for the particular items in my rule incorrectly set up. Fixing the items not only got my persistence to work correctly, but also fixed my rule at the same time.

Thanks Hector.
Sadly that’s not gonna help me as I have no persistence set up for those items.
I am afraid the suggestion of card failure that was made also didn’t help me. I complete reinstall shows the same problem.
Currently I make do by restarting Openhab every day

Although it should only be necessary for lambda rules, I experienced something similar with my timers when not using a space.
This was introduced recently in the snapshot release, so try

garageTimer = createTimer(now.plusMinutes(20)) [ |

instead of

garageTimer = createTimer(now.plusMinutes(20)) [|