How to implement a push button in sitemap for MQTT

I have an MQTT broker working fine, and one of the command topics requires a publish message to /mylan/tests/identify but the payload needs to be NULL (nothing). The mere posting of a null payload to the topic channel, is sufficient to secure a response on another channel.

This works fine using mosquito and logging to the terminal, i.e. mosquito_pub -t /mylan/tests/identify -n and I can read a value on another state topic.

So, question is, how do I implement this in OH? A switch type is no good as it posts ON/OFF or 0/1 etc. The publish must send a null payload otherwise the MQTT client will throw an exception.

Please note that this isnt my design, it is what I must work with, a company retailer, so please accept the poor design and provide a constructive solution - thank you. (yes yes yes, I know it isnt “right” !!!)

You coul try using the mqt action. I am not sure if you can send an empty payload though…
You could use the executeCommandLine action with the mosquitto_pub -t ..... command
You can use node-red, the mqtt node allow you to send an empty payload too.

perfect. Didnt think of those. Thank you

You might also try transformationPatternOut with a js that transforms anything to empty string “”.

I’ve heard that js transforms are a bit inefficient; maybe for a Switch with known commands, a MAP could be persuaded to map to empty string.

Another possibility is to use formatBeforePublish , but I haven’t worked out a way to get that to pass empty string.

Have to test it though, the binding may blow up on empty strings.

1 Like