Mosquitto + Openhab on Rpi zero almost there?

Noob alert

I’ve got Mosquitto server seemingly running fine on my Rpi zero. I can pub and sub from MQTT fx app on my mac and all seems to be working there.

I’ve got openhab + demo installed on same Rpi zero and demo loads in browser just fine. I altered the .items file to try to get one of the demo switches to communicate with the MQTT, but seems a no go. Here’s what I’ve got:

openhab.cfg: file

################################# MQTT Transport ######################################

mqtt:mymosquitto.url=tcp://192.168.0.17:1883

addons folder

pi@raspberrypi:/usr/share/openhab/addons $ ls
org.openhab.action.mqtt-1.8.1.jar org.openhab.binding.mqtt-1.8.1.jar org.openhab.persistence.exec-1.8.1.jar org.openhab.persistence.mqtt-1.8.1.jar README
org.openhab.binding.http-1.8.1.jar org.openhab.binding.ntp-1.8.1.jar org.openhab.persistence.logging-1.8.1.jar org.openhab.persistence.rrd4j-1.8.1.jar

demo.items file

Switch Light_C_Corridor_Ceiling “Ceiling” (gC, Lights) {mqtt="<[mymosquitto:openhab/garage/relay1:command:ON],>[mymosquitto:openhab/garage/relay1:command:OFF]"}

openhab log when use switch in demo

2016-02-26 20:52:25.455 [INFO ] [runtime.busevents ] - Light_C_Corridor_Ceiling received command ON
2016-02-26 20:52:27.801 [INFO ] [runtime.busevents ] - Light_C_Corridor_Ceiling received command OFF

mosquitto log when I publish from the MQTT fx app from my mac

1456548779: Received PUBLISH from 41ce2c94f49e4af1a6e8ce95d88b06e3 (d0, q0, r0, m0, ‘openhab/garage/relay1’, … (2 bytes))
1456548779: Sending PUBLISH to 41ce2c94f49e4af1a6e8ce95d88b06e3 (d0, q0, r0, m0, ‘openhab/garage/relay1’, … (2 bytes))
1456548819: Received PINGREQ from root.1456546975763
1456548819: Sending PINGRESP to root.1456546975763
1456548839: Received PINGREQ from 41ce2c94f49e4af1a6e8ce95d88b06e3
1456548839: Sending PINGRESP to 41ce2c94f49e4af1a6e8ce95d88b06e3

What am I missing to get openhab demo communicating with mosquitto? Can anyone help?

Hi,

I think your MQTT outbound binding item strings are incomplete and one is set to be inbound (<) when it should be outbound (>):

I think it should be:

Switch Light_C_Corridor_Ceiling "Ceiling" (gC, Lights) {mqtt=">[mymosquitto:openhab/garage/relay1:command:ON:1],>[mymosquitto:openhab/garage/relay1:command:OFF:0]"}

if you want to send a “1” when you switch the light on, and “0” when you want to switch the light off. Replace those strings with the messages you want to publish. The MQTT binding documentation has an example of outbound bindings here.

Also, if you want the switch to show the current state, add an inbound config to the binding string:

Switch Light_C_Corridor_Ceiling "Ceiling" (gC, Lights) {mqtt="<[mymosquitto:openhab/garage/relay1:state:MAP(onoff.map)],>[mymosquitto:openhab/garage/relay1:command:ON:1],>[mymosquitto:openhab/garage/relay1:command:OFF:0]"}

transform/onoff.map:

0=OFF
1=ON

Also, if you don’t need one or more of the exec, mqtt, loggging or rrd4j persistence services, uninstall those ones you aren’t using.

Amazing! It works now thanks so much Watou!

1 Like