Rounding MQTT received values

Hi all,
I feel bad about this one, as I’m sure it is a pretty rudimentary mistake I’m making. I’m receiving a value on MQTT, but want to round it.

Current code:

    configuration:
      formatBeforePublish: "%s"
      stateTopic: N/0cae7d0c1344/solarcharger/258/Yield/Power
      transformationPattern: JSONPATH:$.value

I have also tried (this one causes the value to freeze):

      configuration:
      formatBeforePublish: "%s"
      stateTopic: N/0cae7d0c1344/solarcharger/258/Yield/Power
      transformationPattern: JSONPATH:$.value∩%.2f

My main concern is to round the incoming value:

You have to set a pattern in the corresponding Item (State Description → Pattern)
like that: %.1f W

Perfect, thank you so much!

1 Like