Water Pressure Formatting Rule?

I have a hardware knx temperature value like:
Number Weather_Pressure “Water pressure [%.1f Pa]” {knx=“1/1/63”}
Diplaying is the raw variable value:154992.2 Pa.
Really should be the value divided by 1000000 to display 1.55 Pa.
How should be created a rule or can be specified a format for diplaying the 1.55 value ?
Thanks.

Jozef

Here’s one way:

your.items

Number Weather_Pressure "Water pressure (wrong) [%.1f Pa]"	{knx="1/1/63"}
Number Weather_Pressure_corrected "Water pressure [%.1f Pa]"

your.rules

import java.math.BigDecimal
// uncomment on OH1:
// import org.openhab.core.library.types.DecimalType 

rule CorrectPressure
when
  Item Weather_Pressure changed
then
  val BigDecimal corrected = (Weather_Pressure.state as DecimalType).toBigDecimal.movePointLeft(5)
  Weather_Pressure_Corrected.postUpdate(new DecimalType(corrected))
end

Thanks, but with errors on rules -see attachment

Sometimes openHAB Designer flags errors that aren’t errors. Also, if running on openHAB 1.x, you must uncomment the import for DecimalType.

Thank’s watou, but is not correct working. Please some another method for openhab2.

It now OK, thanks

items
Number Water_Pressure “Tlak vody (surovy) [%.1f Pa]” (Temperature, GF_Obyvacka) {knx=“1/1/63”}
Number Water_Pressure_corrected “Tlak vody [%.1f Pa]” (Temperature, GF_Obyvacka)

rules
// This rule will be used to divide raw value to format pressure
rule "Round water pressure"
when
Item Water_Pressure changed or
System started
then
var Number P = Water_Pressure.state as DecimalType / 100000
postUpdate(Water_Pressure_corrected, P)
end

sitemap
Text item=Water_Pressure_corrected