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: