MQTT formatBeforePublish not working with decimal

Hi all,

I try to send a decimal payload from a SetPoint in my sitemap but the formatBeforePublish option is not working, the payload is the decimal raw. When I change the setpoint to an integer, the payload format is correct (see below) but the value is not (obviously).

//sitemap
Setpoint item=PoolProcessPhSetPoint minValue=6.8 maxValue=7.4 step=0.1

//payload
7.299999999999998         // strange value by the way !
//sitemap
Setpoint item=PoolProcessPhSetPoint minValue=68 maxValue=74 step=1

//payload
{"PhSetPoint":68}

Regards,
Feji.

There isn’t a formatBeforePublish option in a sitemap.
Would you like to how us the Item and MQTT channel that you are having trouble with?

There is the thing :

Thing mqtt:topic:piscine "MQTT Piscine" (mqtt:broker:Mosquitto) @ "Piscine" {
    Channels:
	Type number :	PoolProcessPhSetPoint	"Consigne pH" 						[ stateTopic="OpenHAB/Piscine/Set2", transformationPattern="JSONPATH:$.pHSP", commandTopic="OpenHAB/Piscine/API", formatBeforePublish="{\"PhSetPoint\":%d}"]
}

And the item :

Number      PoolProcessPhSetPoint     "Consigne pH [%.1f]"                                                           (gPool)	{channel="mqtt:topic:piscine:PoolProcessPhSetPoint"}

OK, my mistake, rereading my post, replacing %d with %f help ! Obviously.
Sry to post for nothing :slight_smile:

1 Like