Problem sending Json via MQTT

I need to be able to send this via a channel;

mosquitto_pub -t “cmnd/nspanel/nspsend” -m ‘{“temperature”:10,“humidity”:0,“tempUnit”:0}’

Not getting much luck

My channel is this;

UID: mqtt:topic:mqtt_broker:nspanel
label: NS Panel
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mqtt_broker
location: Lower Hall
channels:
  - id: nspanel_temperature
    channelTypeUID: mqtt:number
    label: NS Temperature
    description: ""
    configuration:
      formatBeforePublish: '"{\"temperature\":%s,\"humidity\":0,\"tempUnit\":0}"'
      commandTopic: cmnd/nspanel/NSPSend

But whatever I change the formatBeforePublish to, All I see getting sent is;

Client (null) received PUBLISH (d0, q0, r0, m0, ‘cmnd/nspanel/NSPSend’, … (0 bytes))

What am I doing wrong?

Does not match

Watch your capitalisations.

If that isn’t the issue I would strongly recommend using MQTT Explorer or MQTT.fx to watch all traffic to/from your broker. That will make debugging a lot easier.

Of course, make sure that the Item that is linked to your Channel has an actual value…

As mentioned by @hafniumzinc , try to change the command topic.
I am also not sure if you need the / in the value format as for me it works without, example

I am using mosquitto_sub to look at traffic

sending this…

mosquitto_pub -t "cmnd/nspanel/nspsend" -m '{"temperature":10,"humidity":0,"tempUnit":0}'

shows as;

Client (null) received PUBLISH (d0, q0, r0, m0, 'cmnd/nspanel/nspsend', ... (44 bytes))
{"temperature":10,"humidity":0,"tempUnit":0}

which is working.

but from openhab
image

label: NS Panel
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mqtt_broker
location: Lower Hall
channels:
  - id: nspanel_temperature
    channelTypeUID: mqtt:number
    label: NS Temperature
    description: ""
    configuration:
      formatBeforePublish: '{"temperature":%s,"humidity":0,"tempUnit":0}'
      commandTopic: cmnd/nspanel/nspsend

sends this;

Client (null) received PUBLISH (d0, q0, r0, m0, 'cmnd/nspanel/nspsend', ... (0 bytes))

@chrismast , I changed is as per your example, which I’m sure I had already tried and it’s still no different.

last post I did has the files, which look like yours

I’m using 3.2 if that’s a factor.

What do the openHAB logs say when you send the payload to the broker?

I don’t see any errors or useful output. just the changes to the item;

2022-01-11 14:11:51.116 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'NSPanel_NSTemperature' received command 8.7 °C
2022-01-11 14:11:51.116 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'NSPanel_NSTemperature' received command 25
2022-01-11 14:11:51.117 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'NSPanel_NSTemperature' predicted to become 8.7 °C
2022-01-11 14:11:51.118 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'NSPanel_NSTemperature' predicted to become 25
2022-01-11 14:11:51.119 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'NSPanel_NSTemperature' changed from 25 to 8.7 °C

is there something I can do to increase the level of loggging that appears in openhab.log
nothing to do with the the MQTT message that’s trigger on the change

Is there anyway to increasing the logging level about what the channel is doing to make the payload up?

What’s the definition of your Item? Is it a normal number? I see the degrees symbol in the openHAB log. Maybe that’s the problem for MQTT?

The C sign is strange as it shows not in the item, maybe the semantic definition adds it?

Another thing you could try: %f instead of %s , or what happens if you remove the JSON string and send the raw item to MQTT? Same empty line?

Most likely the Item is linked incorrectly to a binding channel that supplies it.

Very good suggestion - start simple.

I think the issue was that channel was a Number. It seemed sensible to me, since it was a number I needed to pass to the json, but i think it was struggling in conversions. So I made the channel a String. Then when I set the item linked to the channel (which was pulled from another item which was Temperature) I did this;

events.sendCommand("ns_temperature",""+ir.getItem("CabinDevices_CabinRoomTemperature").state.intValue())

Which made 9.2 C → 9

then this;

{"temperature":%s,"humidity":0,"tempUnit":0}

worked

and I got;

Client (null) received PUBLISH (d0, q0, r0, m0, 'cmnd/nspanel/nspsend', ... (43 bytes))
{"temperature":9,"humidity":0,"tempUnit":0}

So all working now. was a struggle though, one to remember!! :slight_smile: thanks.

2 Likes