I am about to setup a lab environment for openhab learning, development and staging. The configuration consists of 3 Raspberry Pi3B+ with Raspbian Stretch.
RPi1: General Purpose System
RPi2: Print server and Mosquitto-Broker
RPi3: Openhab 2.4
Now I struggle to implement a simple switch, that shall be switched by MQTT-messages. Some help would be appreciated.
I’ve already installed Mosquitto on all three Raspis. I’ve tested the Broker functionality of RPi2 successfully: Messages can be published by RPi1 to Broker RPi2 and can be subsribed by RPi3 from Broker RPi2. Everything works neatly.
Now it comes to Openhab:
I’ve installed the MQTT binding and created a thing…
The openhab.log shows, that thing and item are installed and the MQTT bridge has established a client session at the broker (the broker protocoll confirmed that). In the Papier-UI the things are online - everything looks fine, so far.
My expectation was, that openhab now is listening on inbound MQTT-Messages and I can controll my new MQTT-Switch from RPi1 by pubishing:
mosquitto_pub -h 192.168.12.1 -t W88Lab/MqSw1/set -m ON
Unfortuately nada. The switch in my sitemap remains OFF.
Honestly, I just gave it up to declare the MQTT stuff in things and items files. I’ve done that in Papier-UI, of course with proper topics (W88Lab/MqSw1/state and W88Lab/MqSw1/set). I am not happy with that, yet, because I like much more the concept of having all the stuff in a file. But for now I’ve got the job done - or almost done, because there is one issue I don’t understand:
I defined a switch item from the channel with the two topics:
State Topic: W88Lab/MqSw1/state
Command Topic: W88Lab/MqSw1/set
As supposed, if I publish -t W88Lab/MqSw1/state - m ON / OFF, the switch changes its state.
If I toggle the switch in Paper-UI (Command), Openhab publishes -t W88Lab/MqSw1/set -m ON / OFF.
I expected, that the command topic will also be published, when I change the state by MQTT. But it doesn’t.
By “install mosquitto” did you mean that you set up and configured the daemon, or just that you installed the OS packages so you would have the tools installed? Having the tools is handy but having extra daemons running can be confusing.
Excuse me for being unprecise. I’ve installed the mosquitto package on all three servers but I actually use RPi1 and RPi3 as mosquitto clients while RPi2 is configured as broker (runs as demon). And of course I use the -h option in every publish or subscribe command in order to not getting confused.