craigh
(Craig)
May 4, 2017, 4:25pm
1
Hi,
I have temperature readings coming in on a mqtt topic that have 2 digits of precision.
Can I easily drop 1 of those digits of precision? So if 15.24 is published on the topic, would like my Cellar_Temp item to update to 15.2.
e.g. item definition
Number Cellar_Temp "Cellar Temp [%.1f]" (TempSensors) {mqtt="<[hammy:sensors/basement/winecellar/temperature:state:default"}
thanks,
craig
I got my item (please note I crated my item via PaperUI)
Number Workstation_temperature "Office Temperatur" <temperature> (All, Office_First_Floor)
and my sitemap
Text item=Workstation_temperature label="Temp is [%.3f]"
This tells the the sitemap to display 3 digits.
" Temp is [%.3f]"
Which looks like this
1 Like
craigh
(Craig)
May 5, 2017, 2:16pm
4
Thanks, but I am looking for something which changes the actual value, not just format its value within a UI.
http://docs.openhab.org/configuration/transform.html
Could explain really short what you try to achieve ?
This sounds like you want to change the precision of the measurement?
craigh
(Craig)
May 5, 2017, 2:40pm
6
Yes, the sensor sends measurements with more precision than I care. I would like to just intake the values with 1 digit of precision.
Why would you want to make it less precise, when you can trim the digits?
2 Likes
Dim
(Angelos)
May 5, 2017, 2:44pm
8
A “dirty” way to do this would be to use an Exec transformation and call an external script that modifies the value and returns it to the item’s state…
There must be a better way, but I am not aware of it.
I think that the RegEx xformation will not work here since the state value should be a number (not a string)
BrutalBirdie:
Why […] ?
ditto!
1 Like
craigh
(Craig)
May 5, 2017, 2:55pm
9
As for why, more precision than I care about causes unnecessary activity/load within my openhab.
It causes more item change events than I desire, which causes more database activity than I need, and more rule triggering than is desirable.
Hi @craigh
Why not introducing a helper item with full precision; then a rule reduces the precision (some math ) and updates the real thing (if really changed).
with kind regards,
Patrik
1 Like
… which ultimately creates more “activity/load” than just staying with the higher precision. So @craigh I have to repeat the question:
“more item change events than I desire” - so what?
“more database activity than I need and more rule triggering” - fair point.
Hence I would go with @patrik_gfeller solution. Here’s an untested idea:
rule "reduce precision"
when
Item Cellar_Temp_raw changed
then
Callar_Temp = round(Cellar_Temp_raw.state, 1)
end
2 Likes