Can't send an MQTT command using a toggle switch on BasicUI

Hi, I’m using openHab 3.1.0, running on an official openHab docker image (OS = Linux). I have a simple use case: I would like turn an LED on my arduino on/off using a toggle switch on BasicUI. Communication protocol used is MQTT. I also have a mosquitto MQTT broker installed in my setup and I have already been able to publish temperature readouts to the OpenHab successfully.

My current implementation (not working) is the following (see the configuration at On/Off Switch – Google Drive)

  • I have configured a generic MQTT Thing
  • I have defined a channel to handle the on/off switch
  • I have defined a semantic model
  • Added this switch on BasicUI

Whenever I change the state of the switch on the BasicUI, nothing is published under the smartbox1_humidityPowerControl_cmd topic. I’m wondering whether I have missed any crucial steps in my configuration. Help me out. Thanks.

are you able to monitor what is published while operating the switch? use mqtt.fx as a client example. anyway, i would use a things and a irems file to define the channels. i have a lot on/off switches running with the right channel configuration.

There isn’t any PaperUI in OH3.

So first things first, let’s make sure whatever you are doing at the UI is doing what you expect.
Look in your events.log to see if your Item is getting ON/OFF commands. These are needed before you get to the MQTT part.

the following 3 entries were added to the events.log file after changing the state of the toggle button from ON to OFF through the UI:

2021-08-02 22:47:14.101 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'humidifierPowerControl_cmd' received command OFF
2021-08-02 22:47:14.103 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'humidifierPowerControl_cmd' predicted to become OFF
2021-08-02 22:47:14.104 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'humidifierPowerControl_cmd' changed from ON to OFF

If it’s not the PaperUI then I’m guessing it’s the BasicUI.

I am using a google chrome app called MQTT Lens for testing (publishing/subscribing) the mosquitto broker. And as said, I’m not seeing any published messages under the specified topic for the channel that is connected to the toggle switch on BasicUI.

It might be that my channel configuration is flawed, but I’m not sure what I’ve missed.

Good start, we have the command necessary to trigger a publish.
You might check that Item is linked to the MQTT channel you expect.

Maybe. Would you share it?

I have found the issue: I had defined an item called humidifierPowerControl_cmd which was linked to the channel of the corresponding thing, but somehow the thing’s model did a point that would correspond to the item.

The solution was to delete the item, add a point to the thing’s model by using “add a point from equipment” option, which created the point and the item. I also had to re-specify the item for the toggle switch on BasicUI, and that did the trick.

The following sceenshot shows that I am receiving the messages on client side (MQTT Lens):