Struggeling with decimals and integers

I have a (dummy) Number item as following:

Number      OpenWB_setSofortCurrent  "A direct laden"

Which is controlled in my sitemap through a setpoint element:

Setpoint	item=OpenWB_setSofortCurrent label="A direct laden [%d]" minValue=6 maxValue=16 step=1	

The issue is that this item is a decimal type. The value is for example 16.0 (not 16)
I need to send this value to OpenWB (another software) and I do this using MQTT.
However, the value needs to be an integer, hence I have used following code in my rule to transform from decimal to integer

rule "OpenWB set minimum A for direct loading" 
		Item  OpenWB_setSofortCurrent received command
    val mqttActions = getActions("mqtt","mqtt:broker:myUnsecureBroker2")
    var OpenWB_setSofortCurrentInt =(OpenWB_setSofortCurrent.state as Number).intValue
    mqttActions.publishMQTT("openWB/config/set/sofort/lp/1/current",OpenWB_setSofortCurrentInt.toString, true)

This works… but not perfectly. Sometimes I change the setpoint from 6 to 7 and then it works. But then I go from 7 to 8, but the value stays at 7. If I then go to 8 again, then it works
My hypothesis is that this is due to the decimal type and the rounding to the integer, which for example rounds it down and hence the setpoint does not move higher.

Could someone help me out on this?

This construction is doomed to the failure that you describe.
A command is a “do something” instruction.
A state is a “this is how it is” condition report.
It always takes real time to execute instructions.

If your rule looks at the state of Item immediately after a command issued (which is what you have written it to do) you may get the ‘before’ or ‘after’ state.

Usually you just need to choose rule trigger carefully.

If you want to send your MQTT when the Item changes state, choose the state changed trigger for your rule.
If you want to send your MQTT when a command is sent, use the receivedCommand implicit variable instead of Item state.

I do however think you can do this without using a rule at all, using the formatBeforePublish feature of an MQTT channel, with format %.0f