OH3 + MQTT - Simple example

I read the blog post on oh3 + mqtt here
I’m having problem to repeat the instructions and publish a message on/off switch message.
test1:
The blog demonstrates the publishing of the message via a third party utility MQTT Explorer that is “connected to our broker to see the messages”
I installed “MQTT Explorer” using the link that is provided in the blog, but I don’t know how to connect it to the broker.
I tried connecting it as follows:


Can somehone show how to connect “MQTT Explorer” to the broker?

test2:
I check that the mqtt broker connects/disconnects ok by doing:

OH3 -> Thing -> MQTT Broker -> Enable/Disable

The log file for mosquitto indeed shows the changes:

sudo tail -f /var/log/mosquitto/mosquitto.log
...
1618101031: New connection from 127.0.0.1 on port 1883.
1618101031: New client connected from 127.0.0.1 as 93f20a0a-05e5-437f-8c90-9d0ced74de18 (p2, c1, k60).
1618101056: Client 93f20a0a-05e5-437f-8c90-9d0ced74de18 disconnected.

But when I change the state of the switch
OH3 -> Items -> Test Switch 001 -> On/Off

The mosquitto log file does not show any change:

sudo tail -f /var/log/mosquitto/mosquitto.log
# Nothing is specified

I made sure that the MQTT broker Identifier (mqtt:broker:8ab964979f) is the one that is used in the rules, e.g.

actions.get("mqtt","mqtt:broker:8ab964979f").publishMQTT("testswitch001","ON")

I only have the MQTT binding.
Do I have to add e.g. ecmascript / Javascript binding?

The attached snapshots show:

  • the setting for the MQTT Broker Thing

You need to use the ip address of the computer you installed the broker on not localhost or 127.0.0.1

Here is an explanation to use tasmota specifically

What devices are you trying to connect?

In my case, everything, i.e mosquito, oh3, the item (virtual switch), and MQTT-Explorer are all running on the same computer. Even in this case I cannot use ‘localhost’?

Ok, there were some problems in my settings:

  • I did not connect MQTT-Explorer to my MQTT-broker
  • I did not subscribe to the topic (e.g. testswitch001)

I changed my settings as follows:

  • changed from localhost to actual IP (e.g. 192.168.1.75) (I don’t know if this matters when everything is on the same machine)
  • I clicked Advanced and subscribed to topic testswitch001 (see attached snapshot)
  • I clicked Connect to actually connect to 192.168.1.75 (see attached snapshot)

After doing these changes when I change the switch between On/Off states in oh3, the states update accordingly in MQTT-explorer, as expected (see attached snapshots).
Thanks!


Cool you got it working.

I subscribe to everything like this

image

@denominator thanks for your help.
Now that I have MQTT working, I want to exercise simple send notification to an Android phone.
I placed a separate question here.
Have you used mqtt with push notifications?
Thanks

I use the telegram binding to ask questions.

Like

You have gone out and left the aircon on do you want me to turn it off? YES/NO

NO

Ok I will leave it on

I use telegram for other things

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.