Hello all,
I have had a bit of trouble converting an output of the EXEC 2.0 (OH2) binding (which is always a “String” type) into a “Number” type, with many solutions being only valid for OH1.X it seems. So for anyone who wants a simple conversion, here is my ugly-but-works solution:
The output of the EXEC looks already like a Number, in this case it was e.g. 23.30
.
Basically, I had to create another item of “Number” type and then write a rule that fires whenever the EXEC output changes. The rule then converts the output into a Float type. The “replace” part now replaces blanks if there are any. It could also be used to replace e.g. “°C” to nothing etc.
example.items:
String Pi_temp "Temperature [%s °C]" {channel="exec:command:pitemp:output"}
Number Pi_temp_num "Temperature [%.1f °C]"
example.rules:
rule "Pi Temperature String to Number"
when
Item Pi_temp changed
then
Pi_temp_num.postUpdate(Float::parseFloat(String::format("%s",Pi_temp.state).replace(' ','')))
end
I am sure this solution is not the prettiest but - it works!
If you have a simpler or more direct way to convert this, let me know.