MQTT message with null payload

The MQTT binding is working well for all messages which has a payload. But there are occasions when an external controller requests a value from Openhab (a typical topic could be prefix/22/1/2/0/24) and the message is sent with a null payload (i e empty).

If I define an item (for example a number) to pick up this message in order to return a value of some kind nothing happens because Openhab seems to ignore everything with a null payload. When adding any payload the logic works again.

In a way this is of course logical but there is a need for a way to handle an incoming request without payload and I am sure there is a solution which I have not found yet.

Any help will be much appreciated.

Typically you would have two MQTT topics for this sort of thing, an /input and and /output topic. By sharing one topic when you send the response your listener will see that response as well.

However by using separate topics your server can just subscribe to the /input topic, and publish to the /output channel, and therefore require no filtering to ignore the pubs from itself (hope that makes sense!).

Have you tried making the incoming MQTT item a String item - I am guessing that might support a null payload?

Thank’s Ben for replying. In this case the external device asks Openhab for an integer startup value. So in principle the empty incoming message should be returned with an integer value as payload. Once the device is running it continuously reports un updated value back to Openhab. Because of this I have not tested a string type item.

To get around the problem I already have revised the code so I disable this empty message and define one with a dummy payload which then trigger the return of the requested value using a rule.

This of course works but I wanted to find a way which did not require modification of code which seems to work for other types of controllers. But I have a feeling I have to give it up and stay with the current work-around. The Openhab log error message kind of confirms this. The message is:
016-02-12 10:21:53.575 [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn’t post update for ‘node2_pulsecounter_start’

Thought you might be working on a “pulse sensor” :slightly_smiling:
I’ve been hoping someone would come up with a solution so I can use a MySensors pulse sensor… Do update this topic if you come up with a solution please.

I have the pulse sensor working since long, very little problem to fix that. You can use the work-around I have posted elsewhere.

But I would have liked to make it work without any modifications to the code and thought I found the solution when using the new MQTT topic structure. Tested it today but unfortunately Openhab do not react on messages with a null payload and this is what is generated from the non-modified code.

So it seems that the modification I have used until now still is needed.

@mebj
Thanks Mats, are you able to post your code that does work for now?

As mentioned I use a much modified version and the one I tested yesterday is based on a sketch from the development branch which will not even compile unless this base is used. So what I have will be of no use to you, sorry.

If you take a look at the code for the “standard” version and the mods I gave you it is a quick job to fix the sketch. The sketch will not work without the response from Openhab so in any case the coding of Openhab items and rules are needed and these are very dependent on what you want to achieve.

Did anyone find a solution to this? I am trying to use a Sonoff Tasmota as a simple watchdog timer. I can send an MQTT message “Backlog 3000; Power1 3”. I have set a Blink of 0.5 seconds. At 4 minutes 59 seconds (if openHAB is still running correctly) I want to send an MQTT message of “Backlog” i.e. without a payload. This will abort the backlog but if no message is received the Sonoff will blip the power supply to restart the PC. The item is as follows (with the ? where I need to work out what to put. Sending anything other than null causes the Sonoff to blip immediately

Switch Watchdog "Watchdog" <switch> (GroundFloor) {mqtt=">[mosquitto:cmnd/sonoff-watchdog/backlog:command:ON:delay 300;power1 3],>[mosquitto:cmnd/sonoff-watchdog/backlog:command:OFF:?],<[mosquitto:stat/sonoff-watchdog/POWER:state:default]"}