Accessing Raspberry web server concurrently with OH2

Hi,

The key is understanding what you are trying to do via MQTT, and if there is a way of achieving it directly via OpenHAB without the need for external web access?

The core function of OpenHAB is to give a single interface (web, rule code, REST, etc) to different devices including via MQTT.

To turn a Sonoff Basic running Tasmota on or off via MQTT, I use a ‘standard’ ON/OFF button on a ‘standard’ OpenHAB sitemap.

With a little more rule code, I use the same ‘standard’ OpenHAB GUI to check if MQTT devices are reachable, query firmware, or even trigger firmware upgrades. The web GUI triggers code in a rule to send commands out via MQTT - all without a separate webserver.

The MQTT binding (bear in mind v1 is rather different from v2 in architecture), gives access to any MQTT topic by mapping it to an OpenHAB Thing with Channels, allowing you to then define native Items like a Switch, String or Item. You can then write abstracted rule code to act when MQTT publish sets a value, which the binding subscribes, to and changes the state of a corresponding OpenHAB Item.

The point of this mapping is to give an abstracted model of any device, be it linked via MQTT, Z-Wave, web sockets, etc. Using Python or a shell script with ‘mosquitto_sub’ is quicker and more direct - but doesn’t scale across many different device types and protocols.

For a quick hack, you can even create a Switch Item in OpenHAB and have it shell-out to a ‘mosquitto_pub’ command, but that completely ignores the power of OpenHAB bindings.

Raw access to MQTT is normally only needed for debug - such as a Raspbian command line or a client like: