Hi,
i am currently programing a rule which involves comparing a humidity sensor reading optained from the Deconz binding to a threshold.
Logging the Item state with
logInfo("Info", deconz_humiditysensor_414706f1_humidity)
yields the following output
deconz_humiditysensor_414706f1_humidity (Type=NumberItem, State=58.36 %, Label=Humidity, Category=null)
The problem i am facing is, that comparing the item state against a threshold does not work, due to the appended “%” character in the state of the item.
E.g. the following does not work:
if(deconz_humiditysensor_414706f1_humidity.state>=90)
{
// do this
}else{
// do that
}
The workaround i have found looks like this:
val DecimalType humidityThresh= new DecimalType(90)
var DecimalType sensorReading = new DecimalType(deconz_humiditysensor_414706f1_humidity.state.toString().replace("%","").replace(" ",""));
if(sensorReading >=humidityThresh)
{
// do this
}else{
// do that
}
Those skilled in the art of openhab rule making surely know a simpler way, right?