Get started with rules:string /number / integer

I just started to create rules in Openhab.
Although a lot of experience in programming, but not JAVA, simple tasks appear impossible !
In my case with MaxCube binding for actual temperature
From log:
Studie_Max_Act state updated to 19.89999999999999857891452847979962825775146484375

In rules:
val B = Studie_Max_Act.state

When I want to calculate with B: (add 1°C and the update: + 1 )
Incompatible types:“expected java.lang.number but was” or
Incompatible types:"expected java.lang.number but was

So I have a number/real but cannot make calculations.
(also tried Studie_Max_Act.value / Studie_Max_Act / Studie_Max_Act.value: all same result)
Spent a lot of time figuring out, but could not find any clue.

So I have 2 questions:

  1. How to resolve this issue
  2. Where can I find documentation on how to … (Xtend page did not resolve my question)

Thanks !


Hi Ruud,

You need to declare B as int if you want to use B as integer.

var int B = (Studie_Max_Act.state as DecimalType).intValue

Hope this will help you solve your issue.

Hallo Manfred
Thanks for your quick answer:

When I try this I get :
Error during the execution of rule ‘StudieTemp’: Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType

Is there also a way I could have found (somewhere in the Wiki) the syntacs “(Studie_Max_Act.state as DecimalType).intValue”

The current state of Studie_Max_Act is undefined when you are trying to use it as a DecimalType. You could either use a persistence service to save and restore its previous state, or put a check in your rule to make sure it is currently a numeric value:

if (Studie_Max_Act.state instanceof DecimalType) {
  var int B = (Studie_Max_Act.state as DecimalType).intValue
  // or however you want to use it