OH3 HowTo omit trailing '0' in rules

I have created some items, which are written via Rest API

When this item becomes changed then follwowing rule is triggered

triggers:
  - id: "2"
    configuration:
      itemName: MB_I_Reg_01
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: |
        HzgAussenTemp.sendCommand ((MB_I_Reg_01.state as DecimalType) / 10)
    type: script.ScriptAction

The changed Modbus value from Item ā€œMB_I_Reg_01ā€ is divded by 10 and passed via sendCommand to final item ā€œHzgAussenTempā€ which has following config

The result of the rule is

How can I avoid all this trailing ā€˜0ā€™ ?

Is there a better/different way to write that rule? (I am coming from OH2)

Under the metadata select state description and in the pattern add %.1f

To elaborate on Gregā€™s reply, you donā€™t want to actually remove or truncate the actual value. When you do that all sorts of rounding errors build up to the point you end up with wrong values.

Instead, you want to round/truncate the value only when itā€™s shown to a human. Thatā€™s what Gregā€™s answer does. It rounds the value to one decimal place before showing the value to the human on the display.

1 Like

Thank you,

that did the work.

To elaborate on Gregā€™s reply, you donā€™t want to actually remove or truncate the actual value. When you do that all sorts of rounding errors build up to the point you end up with wrong values.

This may not be the right aproach.

I have a device which I can ask every 30 seconds for values. This device is giving me the raw meassured value for example the outside temperature (12.06467 ) with 5(!) digits.

So every 30s I will have a fully changed temperature written to my influxdb. This will consume a lot of space on my disk.

So I really would prefer to round the measured value to 1 digit, then have the check if the value has changed to the last one and if so, then written to the database.

How can I achieve this?

Apply a read transformation in your Modbus data Thing to round to whatever places.

This is what I tried to do with this ā€œstate formatterā€, but when I enter it, then there is no value written at all. Also there is no log entry complaining anaything.

I suppose I have something wrong in the syntax or my understanding.

Your hint to do it with an transformation may solve the problem, but I have no clue where to enter that transformation. In the item definition I do not see a possibility

I said to add it to the Modbus data Thing.
The binding docs give an example of a ā€˜divideā€™ JS.
Donā€™t forget transformation services like JS or REGEX are add-ons needing tobe installed.