I want to send an receive data via MQTT. Receiving works fine, but sending don’t work at all. My Sitemap Item gets changed if I send Data with another device to that channel, but changing it in openHAB doesn’t send new data back. There are no erros or warnings in the log.
Topics are one-way communications. Someone publishes on a topic, someone else(s) listens to it. If you subscribe to the same topic that you publish to, you disappear up your own backside. It’s not a complete disaster, but no sensible setup does it that way.
More normal usage is like - somedevice/sometopic/SwitchA/command somedevice/sometopic/SwitchA/status
where a remote device listens for command, and sends out state. The openHAB end listens to state, and sends out command.
I use the Android App “MQTT Snooper”. There I can send Command to a Topic, and then I see that my ESP32 reacts to them with changing the LED Stripes. And I can also see there the Sensor Data I publish via MQTT. The Sensor Data is also visible in openHAB. And If I have the stateTopic configured, the Item in openHAB also changes when I send a command with the MQTT Snooper.
But if I try to send a command with openHAB, I see absolute nothing. No log entries, nothing in the MQTT Snooper and nothing on the ESP32.
None? If your UI sends a command to a non-existent Item, you will see an error in your openhab.log. If your UI sends a command to a valid Item, you will see an entry in your events.log. If you see neither of those, your UI is blocked off from openhab or talking to the wrong port or something.
I’ve replicated your configuration on my setup and, whilst it’s definitely unconventional to use the same state and command topics, it does of course work.
You are of course free to ignore my suggestions from #2, but I really would look at re-starting openHAB (as @rossko57 has suggested a couple of times now too, when stating to re-start the MQTT binding), and also double check your leading / on your topic: it’s also unconventional.
Here’s it working for me:
Result in MQTT Explorer:
Changing Grablicht in openHAB Sitemap
Result in MQTT Explorer:
Now going the other way, publishing from MQTT Explorer:
Result in sitemap:
For completeness, here is the configuration that I used to test, as I use a separate broker file:
I will try a restart tomorrow. Restarting is always a mess with the homematic binding. I have then to restart the CCU2 a couple of times until all homematic items will work again.
But I see in the log that it reloads the file if I modify it.
20:44:24.894 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model ‘mqtt.things’
the log I showed 2h ago is everything that happens when I update the item state. Receiving Data is working fine, and never needed a restart.
removing the stateTopic has no effect
the / is part of the topic, to remove it i would need to disassemble my hardware an reflash the ESP.
That’s a shame. Seems mysterious, especially as it works for me.
Sorry to bang on about this, but I would personally fix this. See Best practiceson this page:
Never use a leading forward slash
A leading forward slash is permitted in MQTT. For example, /myhome/groundfloor/livingroom. However, the leading forward slash introduces an unnecessary topic level with a zero character at the front. The zero does not provide any benefit and often leads to confusion.
I still wonder whether it’s confusing one or other MQTT library in your chain.
You’re also on an old-ish version of openHAB, and the MQTT binding. Definitely upgrade as part of your troubleshooting!