I have a termo-sensor LM75, and I get temperature by python script (using special addon Exec Binding). It works fine, BUT type of result of script is a STRING. And i can’t use it in my rules.
my.items
String Temp_1f "real temp 1 floor [%s]" {channel="exec:command:c5d60dc7:output" }
and I try this ways:
- in rules I write
var teest = Temp_1f as Number
, but in log appears error: Error during the execution of rule ‘test’: Could not cast Temp_1f (Type=StringItem, State=25.12, Label=real temp on 1 floor, Category=null) to java.lang.Number
- After it i found a post with a same problem. I create special item
Number Temp_1f_numb "Temp is [%.1f °C]"
and make rule for converting
Temp_1f_numb.postUpdate(Float::parseFloat(String::format("%s",Temp_1f.state).replace(' ','')))
And it works, BUT a can’t compare getted value in my rule:
var set1temp = Reg_1f.state as Number
Temp_1f_numb.postUpdate(Float::parseFloat(String::format("%s",Temp_1f.state).replace(' ','')))
var cur1temp = Temp_1f_numb
if (cur1temp < set1temp) logInfo("info", "O, Yeees!)
else logInfo("info", "Omg, NO")
In log instead my text appeared Error during the execution of rule ‘test’: Unknown variable or command '<'
My questions are: What wrong in my second way? And, maybe, there is more easier, right solution for compare results?