MQTT/openHAB - Resolution

A project log for Home Automation - Garage Door Opener

Extract best practices from existing garage door projects. Build version that suites my needs; eventually integrate into other HA efforts.

luffmanbluffmanb 05/01/2016 at 01:560 Comments

So just what was the problem w/ my openHAB-MQTT integration? Turns out, I was just too tired and too tied into the project at the time to see the problem; needed time away from it to clear my head, slow down, read a bit closer, and think it through. In short, I had made mistakes in the openhab.cfg file and in my syntax in the item/sitemap files.

Troubleshooting - Confirm mosquitto is working correctly

I searched Google for openhab and mqtt problems, and use this forum post to confirm my Mosquitto installing was working as expected:

On openhab.local

mosquitto_sub -h localhost -v -t "\$SYS/#"

mosquitto_sub -h localhost -v -t test/topic &
mosquitto_pub -h localhost -t test/topic -m "hello"
On gdoPi.local
mosquitto_pub -h openhab.local -t test/topic -m "hello from gdo"
If you see message from gdoPi show up on openhab, its mosquitto is working just fine. Can also check that it works both ways by having gdoPi subscribe to a message topic, and then have openhab publish to said topic. The key thing to notice here is that the -h sets which host is acting as broker; so both need to be pointing to same one. For my setup, I want openhab.local to be broker.

Troubleshooting - Correct openHAB configurations

Now that I was confident mosquitto was working correctly, I moved onto openHAB's MQTT binding. The big thing here was rereading openHAB wiki closely on MQTT binding, openHAB Items syntax and openHAB sitemaps syntax. Then use one of their examples and see if the message comes across on mosquitto CLI as seen above.

Configurations on openhab.local:


/* MQTT - Garage Door Opener RPi */
Switch relay {mqtt=">[mosquitto:/house/garage/gdoPi/doorRelay:command:ON:1],>[mosquitto:/house/garage/gdoPi/doorRelay:command:OFF:0]"}
sitemap nest label="My House"
  Frame label="Garage Door Opener" {
	Switch item=relay label="Open/Close Garage Door" 

Testing & Debugging on openhab.local:

In new terminal window, execute:

tail -f /var/log/openhab/openhab.log

In another new terminal window, execute:

tail -f /var/log/openhab/events.log

In original terminal window, execute:

mosquitto_sub -h localhost -v -t /myhouse/#
Now in browser, go to http://openhab.local:8080/ Click on your switch a few times and watch what happens. Errors/Warnings/Info about what openHAB is doing and experiencing will be recorded in openhab.log. Event messages coming across the openHAB Event Bus will be recorded in events.log. We've already done the mosquitto thing, but this will tell us what we should expect to parse on the other RPi when ready.

Confirm gdoPi.local can see events also:

mosquitto_sub -h openhab.local -v -t /myhouse/#

If all this is working, then openHAB is talking MQTT and both Pi's can sub/pub as well. Now just build up the code on gdoPi w/ relay and camera.