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


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: 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

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

You mean, in the display?

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.

I hope you can help me too …
I would like to send values from 0 to 100 for a dimmer channel.

My MQTT channel is:

Type dimmer : h801_2550_dimmer      	"LED H801 #1: Dimmer" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/dimmer" ]

And the linked item:

Dimmer      OG_bad_l_led1_dim               "Bad OG: LED - Dimmer"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_dimmer"}

In OH log it seems to work fine

[ome.event.ItemCommandEvent] - Item 'OG_bad_l_led1_dim' received command 75
[nt.ItemStatePredictedEvent] - OG_bad_l_led1_dim predicted to become 75
[vent.ItemStateChangedEvent] - OG_bad_l_led1 changed from 38 to 75

But the output in MQTT is :
(which leads to switch off the LED (dimmer =0) - instead of setting the dimmer to 75)

How can one translate it into the right value?

Doesn’t have anything to do with sitemaps or formatting. I recommend starting a new thread with an MQTT related topic.

What are you using to monitor that?
Looks like the binding is taking the 75% command and using it as a fraction (of one).
I don’t think that should happen with a dimmer type channel.
You should identify your MQTT binding version, there have been changes with this.