[Solved] Error subtracting two variables

running OPENHAB2 on Ubuntu
a snippet of a rule I’m having an issue with

var tempdiff = (HOTWATER.state - HotwaterTempBefore)

I’m getting :error : ScriptExecutionException: Unknown variable or command ‘-’;
How both variables have values but I can’t understand why I’m getting an error subtracting two numbers ??

2018-05-10 11:17:16.308 [ERROR] [org.quartz.core.ErrorLogger         ] - Job (DEFAULT.2018-05-10T11:17:16.287+10:00: Proxy for org.eclipse.xtext.xbase.lib.Proce
dures$Procedure0: [ | {
  <null>.myTimer = <XNullLiteralImplCustom>
  <XFeatureCallImplCustom>.sendCommand(<XFeatureCallImplCustom>)
  var boost_time
  var tempdiff
  var msg
  <null>.msg = <XBinaryOperationImplCustom>
  <null>.msg = <XBinaryOperationImplCustom>
  logInfo(<XStringLiteralImpl>,<XFeatureCallImplCustom>)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@4869df18
  logInfo(<XStringLiteralImpl>,<XFeatureCallImplCustom>)
  sendMail(<XFeatureCallImplCustom>,<XStringLiteralImpl>,<XFeatureCallImplCustom>)
} ] threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
        at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [115:org.eclipse.smarthome.core.scheduler:0.10.0.b1]
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [115:org.eclipse.smarthome.core.scheduler:0.10.0.b1]
Caused by: java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy154.apply(Unknown Source) ~[?:?]
        at org.eclipse.smarthome.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:49) ~[?:?]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[?:?]
        ... 1 more
Caused by: org.eclipse.smarthome.model.script.engine.ScriptExecutionException: Unknown variable or command '-'; line 62, column 21, length 35
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:137) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:225) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:215) ~[?:?]

it would be easier to debug if you posted the entire rule set.

The first number is the state of an item, while the second number is a pre-defined variable?

You may need to cast the values for this to work (something like val HWVal = HOTWATER.state as Number or as DecimalType)

https://docs.openhab.org/configuration/rules-dsl.html#number-item

thanks for your reply,
I already tried casting var but looking at the error seems to be complaining about the “-” rather than var type?
note the HOTWATER is a ITEM defined as a NUMBER already.

Number HOTWATER “Hotwater [%.1f C]” (temperature) { http="<[hotwaterCache:600000:JSONPATH($.[0].Temperature)]" }

and other variable is defined in rule as follows:

var HotwaterTempBefore = 0.0

var tempDiff = (HOTWATER.state as Number) - HotwaterTempBefore

perfect that actually works , although I did try something like :

((HotwaterMins.state as DecimalType).intValue

but that didn’t work…

anyway thanks

Please mark the tread as solved, thanks