Strange formatting problem

I’m running openhab2.4 on a raspberry PI and am gradually migrating from openhab1. I’ve just added the MQTT 2.4 binding and I’m getting a very strange formatting error.

I have an MQTT sensor that is reporting humidity as a floating point number. The MQTT messages are being sent correctly and are being received by the openhab2.4 MQTT binding. The event log indicates that the humidity item is being correctly updated and the chart of the item looks good.

The one niggling thing that is wrong is that in the classic UI, the basic UI and the android app the value is being multiplied by 100, so for example an RH value of 57.375 % is being reported on screen as 5737.5 %. I’m using a formatting string of [%.1f %%] in the item description. It’s exactly the same formatting string as I’m using for another (one-wire) sensor item, which is displaying correctly.

I emphasise that the value is correct, it’s just being displayed wrongly. The item is defined as a dimensionless number of type Humidity and has been set up using paperUI.

This is probably something really silly, but I can’t work out what.

Use [%.1f %] instead

No that doesn’t work. You need to double the % in order to get a % sign in the output. A single % just gives you “Err” for the whole string.

Although, using [%.1f] results in the number being displayed properly, just without the “%”. Which is even more weird.

That’s odd, it should work.
Have you tried removing the formatting in the item description and putting it in the sitemap instead?

Hmm, not sure how to do that. The item is being displayed as part of a group in the sitemap.

Frame {
Group item=Humidity label=“All humidity” icon=“climate”

Add the items one by one

Text item=TempItem label="Temperature 1 [%.1f %%]"

Hmm, exactly the same… value times 100 and a following % sign.

And the value of the item in the log?

The event log?

2019-01-11 11:22:22.713 [vent.ItemStateChangedEvent] - LoftHumidity changed from 63.3125 to 63.0
2019-01-11 11:22:53.309 [vent.ItemStateChangedEvent] - LoftHumidity changed from 63.0 to 63.3125
2019-01-11 11:23:54.345 [vent.ItemStateChangedEvent] - LoftHumidity changed from 63.3125 to 63.625

Ok so there is no % there
Can I see a screen shot of your item definition in the paperUI, please?

Are you willing to try a text based item instead of PaperUI?

This is after taking out the %%, the formatting string causing the trouble is [%.1f %%]

Yes, of course… but I’ll need to do that a bit later. This is eating into Real Job

First delete the item from the paperUI (Remember the name and the groups)

Then create a file called temperatures.items in the items folder
With the following contents:

Number:Dimensionless LoftHumidity "Loft Humidity [%.1f %%]" <humidity> (g_Loft, Humidity, g_Chart, g_Chart_Humidity) { channel="thechanneltolinktofrompaperUI" }

Mine look like this:

Number:Dimensionless SmallBedroom_ThermostatHumidity       "Small Bedroom Humidity [%.1f %%]"             <humidity>    (SmallBedroom, Humidity, BedroomsHumidity, MQTTv2)                                                             { channel="mqtt:topic:MosquittoMqttBroker:SmallBedroomThermostat:Humidity" }



PaperUI Control:

Ah ha! That worked

So why didn’t it work with paperUI?

That’s a good question. It might be possible to fetch the Item via REST and compare details. It’s possible PaperUI is messing with % symbols or something.

I was having this same issue with OpenHAB 2.5. I found that if I leave the Dimension value blank in the Item properties the formatting works correctly in the sitemap when using the traditional syntax.

Text item=NWSCurrentRelativeHumidity label=“NWS Humidity [%.1f %%]”