[SOLVED]MQTT 1.x follow channel

Hello,

Here is the things, I have an item that is polling its value from a modbus sensor and I would like to forward that value to a MQTT broker using the follow profile and the MQTT 1.x binding. It seems to connect to the broker but not to send the correct payload.

Number TemperatureKMInt16            "[%.1f °C]"    <temperature> (Room001)    { channel="modbus:data:PLCTCP:holding:temperatureKM:number", mqtt=">[mybroker:modbus/temperature:command:*:JSONPATH($.Temperature)" [profile="follow"] }

I would like the JSON payload to be:
{“Temperature”: 24.2}

Any idea of what am I doing wrong ?

thank you in advance

As I understand it, the [profile="follow"] part would require you to specify another Item to follow - so I don’t think that does anything at all here and can be left out.

mqtt=">[mybroker ... should be sufficient to what you want, but I know nothing of configuring MQTT 1.x

I do.

First, use the state instead of command.
Second, the JSONPATH transform only works one way. You can’t do it this way.
You will need to use a JS transformation

tojson.js In transformation folder

(function(temp) {
    return '{"Temperature":' + temp + '}';
})(input)

Your item:

Number TemperatureKMInt16            "[%.1f °C]"    <temperature> (Room001)    { channel="modbus:data:PLCTCP:holding:temperatureKM:number", mqtt=">[mybroker:modbus/temperature:state:*:JS(tojson.js)" }

Well, well well, I really through that it would work but it doesn’t and I don’t know why. It should.
Maybe I am now on 2.5…

You are going to need a proxy item young man

Actually I’ve found a solution using version 2 that adds mqtt as a channel. I don’t know why it did not get to my mind yesterday. Way easier !!!

Need to add a mqtt Bridge thing with channels and commandTopic. Then add an item and the correct channel, in order to format to json, there’s the Format before Publish feature that allows that.

Yes, good find. well done