I´m on Openhab 2.5 and have a question about state presentation: I have a temperature item (from openweathermap binding). Because I don´t need any decimal place I´ve changed %.1f to %.0f (https://community.openhab.org/t/solved-question-aboute-1f-c-d-3f-kw/62420/2)
But nothing changes. Here is an example:
2020-05-23 15:15:17.151 [vent.ItemStateChangedEvent] - TestTemperatur1 changed from NULL to 17.13 °C
2020-05-23 15:15:17.152 [vent.ItemStateChangedEvent] - TestTemperatur0 changed from NULL to 17.13 °C
2020-05-23 15:15:17.152 [vent.ItemStateChangedEvent] - TestTemperatur2 changed from NULL to 17.13 °C
Maybe try and round the number in a different rule.
rule “Round Temperature Livingroom Sensor”
when
Item HT_Temperature_LR received update
then
if (HT_Temperature_LR.state != NULL){
val roundedNumber = (Math::round((HT_Temperature_LR.state as DecimalType).floatValue()* 10)).floatValue() /10
sendCommand(HT_Temperature_LR_rounded,roundedNumber)
}
end
You can’t do that “automatically” in a sitemap: only single values can be rendered this way, not multiple values (such as a temperature range).
So you need to write a rule to populate that item. That rule can then take care of properly rounding the temperatures to the desired precision.
Please note that I moved away from Rules DSL a while ago so all my rules are now based on Jython and NGRE. Works much faster and requires less CPU & RAM.
It would be helpful if you could specify a scale for items. Either when you define them or a global for all items. I have all sorts of items with false precision when they get converted between units of measure, for example C to F, mm to inches, etc.
The uploaded picture is from my sitemap and the populated item is generatet by your rule I thought if I take rounded values right away, I could save myself the conversion.