How to send numbers as intergers and not floats using Outgoing value formatting

Tags: #<Tag:0x00007faee0936890> #<Tag:0x00007faee09366b0>

Hi,

I am in the process of migrating from mqtt v1.0 plugins to 2.0 plugins, and I am running into an issue I cannot solve. I have searched high and low and cannot find an answer. Unfortunately I do not really understand the documentation either.

I am hoping someone can help me out.

In the documentation here: https://www.openhab.org/addons/bindings/mqtt.generic/ there is talk about “Format before Publish”

The issue I have is that I have some custom build devices that is expecting to receive a value from 1 to 100. (A percentage), but all I can get openhab2 to send is a float. 1.0 - 100.0. How can I get rid of the “.0” suffix?

I think the problem is that I do not understand the format I am supposed to write the transformations in.

Second problem is regarding the same functionality. I would like to have a “%”-sign after a value I receive from a device, but I cannot figure out how to escape the %-sign so that openhab will stop tripping over it.

Please help…

Best Regards
BK

What type of Item are you linking, to what kind of channel? A Dimmer type sounds appropriate.

You mean, in the display?
sitemap

Text item=myItem label="some label [%d %%]"

or you can put the format in the Item definition label

Format before publish

Maybe you were thinking of using %.0f

rossko57: Thanks for replying

I have tried them all I think. A dimmer sends a value of 0.0000 to 1.0000 or something like that. I think it is just set to a number right now.

I tried setting %.0f in the Outgoing value formatting, but it does not seem to do anything.

Can I add [%d %%] in the Item definition label?

What do you mean by “you can put the format in the Item definition label”?

I am very uncertain how that is done.

This is an Item definition, in the format used in xxx.items files

Number myItem "some label [%d %%]" <someIcon> (channel= ....

The label is the part in " "
"some label [%d %%]"
which contains a format in [ ]
[%d %%]
and that’s the default format to display this Item’s state.
In this case, it means “show a decimal number with a percent sign”

Maybe you use PaperUI to create and edit Items. The principle is the same, it all goes in the Label box in the form.

If you use a sitemap based UI, you can optionally add a label in each line, which in turn can contain a [ format ], and that will override the default in the Item definition.