Rules / string value problem

Hi all, need some rule help please with my 1.6.2 config

for this item:

String AlarmString " [%s]" (Security)

I have this rule:

rule "test cron"

when
Time cron “0 28 10 * * ?”
then
if ( AlarmString.state = “unset” )
{
sendCommand(Light_GF_Hall_Lamp, ON)
sendCommand(Light_GF_Hall_Lamp, OFF)
}
end

But im getting this error:

2015-10-04 19:05:00.054 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule test cron
java.lang.RuntimeException: The name ‘unset’ cannot be resolved to an item or type.
at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:67) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAssignment(XbaseInterpreter.java:843) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateIfExpression(XbaseInterpreter.java:327) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_60]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) ~[na:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) ~[na:na]
at org.openhab.model.script.internal.engine.ScriptImpl.execute(ScriptImpl.java:59) ~[na:na]
at org.openhab.model.rule.internal.engine.ExecuteRuleJob.execute(ExecuteRuleJob.java:55) ~[na:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]

any ideas guys please?

Did you want “==” (equality operator) for the comparison of AlarmString.state to “unset”?

indeed i did, must have removed one when ive been playing about trying to get the rule working - now corrected :smile:

so when i put ‘unset’ in double quotes, the rule doesn’t seem to trigger.

when i don’t use any quotes i get this error

2015-10-04 19:55:00.070 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule test cron
java.lang.RuntimeException: The name ‘unset’ cannot be resolved to an item or type.

Is it possible the state is not the string “unset”?

I’ve got the value displayed on the sitemap - it seems to be set correctly.

thinking there might be something wrong with the string element, i’ve changed the rule to use a switch - but this isn’t working either. So, am i nesting the when/then/if correctly?

@BigCol,
Try adding a logInfo call like:

   logInfo("mydata", "#" + AlarmString.state.toString + "#")
   if ( AlarmString.state.toString == "unset" ) {
      ...
   }

This will let you see the runtime value, at the time of Rule execution, in your openhab.log file, and help validate @steve1’s question.

Alternatively you can look at the events.log file. You may have spaces (etc) that are impacting the exact-match comparison.

2 Likes

so I’ve learnt a little about logging too now :smile:

2015-10-07 23:11:00.040 [INFO ] [.model.script.alarmstringvalue] - alarmstring alarmstring.state: [unset].

This shows that the value of the string item seems to be correct