How to compare State of String Item to integer as integer

In my rule I have value from temperature sensor saved in String Item’s state. Value is retrieved from shell script via exec binding and looks like this (example): 24.6 (always rounded to one decimal, contains point).
How can I use this value in my if statement?

This does nothing:

if(MyStringItem.state > 30) {
 # very hot

This throws “Could not cast…”

if((TempOut.state as Number) > 30) {
 # very hot

This throws “Could not cast…”

if((TempOut.state as DecimalType) > 30) {
 # very hot

This throws “Could not invoke method…”

if(Integer::parseInt(TempOut.state) > 30) {
 # very hot

I am lost :frowning:

OpenHAB 3.x
Raspberry Pi with openhabian

But your string is a decimal?

var fred = Float::parseFloat("22.1")
var mary = Float::parseFloat(yourItem.state.toString)
1 Like

Thanks. It did the job.

Not sure of the type. It is retrieved value from exec binding. Source of the value is shell command output.
Is there simpler documentation version then this xtend documentation? As far I understand OpenHAB rule scripts follow this syntax. As a non programmer I have trouble using official Xtend documentation.

You defined the type of your Item when you created it, you told us it was a String type.

Okay, no openHAB docs are going to tell what results you get from some external script.
The binding docs do tell you that whatever the results are, they are fed into a string type channel.

Nope. Best resource is this very forum and its search feature.

If you are not comfortable using Rules DSL, don’t use it. Jython and javascript are also popularly used as rules languages.

I did not know that. I will check it.