Extracting values from a Numerical value with AND mask

Hello all.

I receive a string value from a sensor using MQTT, this string has sensor values and after beying parced I store it in a numerical variable, lets call it Sensor1, the data.
Until here all OK. :slight_smile:

This variable is has an 8 bit value, form 0 to 255 where each bit represents a boolean state of a device.
So I need to retrieve the value from bits 0,1,2… to update switch type items from Sensor1 using a AND mask.

I tried


if (Sensor1 AND 0x01) postupdate(Alarm1,ON)
else postupdate(Alarm1,OFF)

but I get erros…
Whow should be the check made?

Thanks

Have a look at this old post.

Thanks.

It works fine if the value is comming from an Item

"
var myState = (Gen_Alarm.state as DecimalType).toBigDecimal.toBigInteger

 if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
  else postUpdate(Gen_lowFuel,ON)

"

but if the value comes from a variable I get an error

"
var myState = valor.toBigDecimal.toBigInteger

if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
else postUpdate(Gen_lowFuel,ON)
"
valor is a Numerical variable.

Use a logInfo to display the differences and what is the error?

Back

As I posted before if I use the source of data from a Item all works;


var myState = (Gen_Alarm.state as DecimalType).toBigDecimal.toBigInteger

But, if I use a Numerical variable like below

"
var Number valor=7 (value here is hardcoded just for example)

var myState = valor.toBigDecimal.toBigInteger
logInfo(“test”,“nhala parcing, ITEM:” + myState.toString )

	 if (myState.testBit(1) ) postUpdate(Gen_lowFuel,OFF)
	  else postUpdate(Gen_lowFuel,ON)

"

I get this error in Eclipse

"
Multiple markers at this line

  • Couldn’t resolve reference to JvmIdentifiableElement ‘toBigDecimal’.
  • Couldn’t resolve reference to JvmIdentifiableElement ‘toBigInteger’.
    "

And, if I run it, I get the following error:

" Error during the execution of rule ‘nhala rec’: The name ‘.toBigDecimal’ cannot be resolved to an item or type.
"

Any ideas?

Try valor.toString.toBigDecimal.toBigInteger

Thanks for the help Jürgen,

I triyed the solution of your post


Try valor.toString.toBigDecimal.toBigInteger

It still shows the error:

"
Multiple markers at this line

  • Couldn’t resolve reference to JvmIdentifiableElement ‘toBigDecimal’.
  • Couldn’t resolve reference to JvmIdentifiableElement ‘toBigInteger’.
    "

:frowning: