OH4 MQTT incorrectly converting to integer

I have a Victron Venus OS running on a Rasperry Pi3. It has its own MQTT broker. I have created a second bridge to it. Keep Alive and first couple of items are below

UID: mqtt:topic:Venus:VenusMQTT
label: Venus MQTT
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:Venus
channels:
  - id: KeepAlive
    channelTypeUID: mqtt:string
    label: Keep Alive
    description: ""
    configuration:
      commandTopic: R/d83add4fb652/keepalive
  - id: Victron_SoC
    channelTypeUID: mqtt:number
    label: Victron SoC
    configuration:
      stateTopic: N/d83add4fb652/battery/512/Soc
      transformationPattern: JSONPATH:$.value
  - id: Victron_ACW
    channelTypeUID: mqtt:number
    label: Victron AC W
    configuration:
      stateTopic: N/d83add4fb652/inverter/0/Ac/Out/L1/P
      transformationPattern: JSONPATH:$.value

The Inverter is sending float

512
Dc
0
Power = {"value":418}
Current = {"value":8.5}
Voltage = {"value":49.220001220703125}
Temperature = {"value":9.199999809265137}

openHAB just displays the voltage as 49. I’m not sure what I’m doing wrong (I tried changing the outgoing to .2f% but it made no difference).
Any ideas?

What’s the Item configuration like?

I would expect the (advanced options) unit parameter to be set:

UID: mqtt:topic:Venus:VenusMQTT
label: Venus MQTT
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:Venus
channels:
  - id: KeepAlive
    channelTypeUID: mqtt:string
    label: Keep Alive
    description: ""
    configuration:
      commandTopic: R/d83add4fb652/keepalive
  - id: Victron_SoC
    channelTypeUID: mqtt:number
    label: Victron SoC
    configuration:
      stateTopic: N/d83add4fb652/battery/512/Soc
      unit: %
      transformationPattern: JSONPATH:$.value
  - id: Victron_ACW
    channelTypeUID: mqtt:number
    label: Victron AC W
    configuration:
      stateTopic: N/d83add4fb652/inverter/0/Ac/Out/L1/P
      unit: W
      transformationPattern: JSONPATH:$.value

Then, the Item Type should be Number:Dimensionless and Number:Power respectively.

Take a look at the Item list (Main UI - > Administration → Items) Do the values show up as Integers or are they of type float, and only shown as integer in the Item details? Then try to set the State Description Pattern to %.2f %unit%.

If using QuantityType Items (Number:), please also ensure to set the correct unit ONCE in th eItem metadata. Please be aware that this unit should be set only once, as it influences the value stored in the Item (and therefor the persisted value as well).
The Display unit can be set as often as you want.

Interesting. In the Items list it appears as float but in the item in the Thing (and the Sitemap despite it having %.2f in the label) it’s an integer.
I don’t have the problem with the Mosquitto broker.
I changed the unit to V for a voltage one and it made no difference.
I deleted them all and re-created them and it’s fine now (apart from showing as an integer in the channel)

Wait, this part is shown in the Item state? Then you missed something when configuring.

  • Don’t add %.2f to the label
  • Add Item → Metadata → State Description → Pattern instead with %.2f %unit%

With text file (*.items in $OPENHAB_CONF/items/) it’s like this:

Number:Dimensionless Victron_SoC "Victron SoC" {channel="mqtt:topic:Venus:VenusMQTT:Victron_SoC",unit="%",stateDescription=""[pattern="%.1f %unit%"]}
Number:Power Victron_ACW "Victron ACW" {channel="mqtt:topic:Venus:VenusMQTT:Victron_ACW",unit="W",stateDescription=""[pattern="%.1f kW"]}

Don’t setup the state format through the label:

Number:Dimensionless Victron_SoC "Victron SoC [%.1f %unit%]" {channel="mqtt:topic:Venus:VenusMQTT:Victron_SoC",unit="%"}
Number:Power Victron_ACW "Victron ACW [%.2f kW]" {channel="mqtt:topic:Venus:VenusMQTT:Victron_ACW",unit="W"}

This will only work for Sitemaps, but not for Main UI.

If configuring through Main UI, the second option won’t work at all, even for sitemaps!

I started with OH2 and use the sitemap as my main view (including in the app) so all of my items have the format in the label. I only use the main UI for checking things are working. I don’t want to re-write the whole of the sitemap for 1 device which is giving issues.
I suspect that the problem was caused because I copied the code from the node-red supplied data into the Victron Thing and something got lost in the shuffle.
I configure the Things in the UI but use items files (I find it easier - I create the first Channel and copy it a few times in the code - just change 1 letter - BatI to BatV - then create one item in the items file and do the same)
I tried patterns when I upgraded to OH4 but it didn’t work correctly with a couple of bindings.
One day I will sit down and go through everything but it’s sort of, if it ain’t broke don’t fix it.

Then forget about checking in Items but only check in Item list. The Item list shows the real value (in the meaning of more accurate) The Item details and the Item in Channel view will show the pattern formatted value.

I don’t want to be offensive, but I’m pretty sure that this is due to wrong configuration.