Feature request: integrate Mqtt broker in my.openhab

Hi all,

I’m using mqtt for presence detection and have the broker running on my local server with an open port in the firewall which I don’t like from a security point of view. Therefore my idea… Can’t we integrate the mqtt broker into my.openhab and push the location via the openhab app?

Or what alternatives do you use? ( I found a lot of the public brokers quiet unreliable)

1 Like

If the location is pushed by my.openhab, there is no need for the MQTT broker in the first place. MQTT for location is only really needed because that is how Mqqitutde works.

There is a location channel in IFTTT that you can use in combination with the openHAB channel which should get you at least some geofencing through my.openhab without exposing a port on the internet.

Personally I abandoned location tracking for a couple of reasons. I had other more reliable ways to detect when someone is home which is really the only reason I was doing it in the first place, and my wife found it a bit creepy that we could track each other’s movements like that (ignoring the whole issue of the phone company, Google, and all sorts of other strangers can do the same).

Security wise if you take some prudent steps (e.g. enable TLS, get a trusted cert for the server, or create a self signed cert, run mosquitto (or what ever your broker choice is) in a limited way (limited user, chroot, container, etc) it is not extra risky to open the port in your router.

Also note that mosquitto can be setup to have two listeners; I have my external one on port 8883, which is open on my firewall, but on this listener mosquitto is set up to require validation via a certificate, (OwnTracks uses that method to contribute location data, for example). Then I have a second listener enabled on port 1883, but it’s not opened to the outside world on the firewall, so it can only be accessed via a localhost address (which is fine as my mosquitto broker is running on the same LAN as OpenHAB)

Hi,

I like this idea of integrating those two service.
I also found it a bit strange that my.openhab already knows the connection to my home network but i need to setup my router’s firewall and some dyndns to allow e.g. owntracks to to connect to it.

Anyone active at this idea?

@rlkoshak: I didn’t gout your point, could you be more clear about your idea of IFTTT and how it could be used for geofencing and presence detection please?

Being an MQTT Broker is really outside the scope of what OH does and adding it would potentially be as big of a job as OH is itself. While being an MQTT client is dead simple, the brokers are complex and challenging to write. OH would never be as reliable, complete, or as good of a broker as using a special purpose broker like mosquitto. So even if OH included an MQTT broker, I personally would never recommend using it.

They are completely separate services. My.openhab knows the connection to your openHAB instance only. It basically provides a proxy ONLY for your instance’s REST API. It can not communicate directly with anything outside of openHAB or for that matter anything within openHAB that is not exposed through the REST API.

Both the MQTT broker and Owntracks are external to openHAB and written by third parties. There is no way and no reason for my.openhab to expose those services too. It would be technically difficult, a nightmare for security, and outside the scope of openHAB and my.openhab’s purpose. (IMHO)

The IF app enables both the Android Location and iOS Location channels which can trigger when you enter or exit an area (i.e. geofence) for the If. The Then That can then go to an openHAB channel to update one of your Items which you expose through my.openhab by adding it to the myopenhab.persist file. For presence detection you just need to set up a geofence around your house.

You could also use the the Android Device or iOS Device channels with the “Connects/Disconnects to/from a specific WiFi network” If to Then That update a presence Item exposed by my.openhab when you get home and your device connects to your home wifi.

Thanks for the infos. Think I got your idea.
But then I’m missing a generic way to connect some app like owntrack etc. to items on my openhab installation, e.g through my.openhab.org?
Currently only ios/android apps an IFTTT support connectivity to my.openhab?

Got that. But what about some webviews which load data from other sources
(e.g. webcams or thelike) that won’t be possible then?

Thanks for that. It works for me.

I don’t think there is such a thing as a generic way. THE way to connect something that talks MQTT to openHAB is through an MQTT broker. MQTT is how owntracks talks so that is how you must connect it to openHAB. There is no way to connect MQTT through my.openhab.

There are third party hosted MQTT brokers which you can point owntracks and openHAB to if you don’t want to host your own broker, but their security is often not well configured plus you have no control over your data as it traverses the broker.

Any channel that in IFTTT that can be put on the “IF” side of the equation can be used to update openHAB Items. The only IFTTT channels that support geofencing are the Android and iOS channels.

People have had mixed results access webviews through my.openhab. But most seem to get it to work to some degree. I don’t have enough experience with them to know in which circumstances they do or don’t work as I don’t really use them on my sitemap.

One thing to remember is that webviews access data over HTTP, REST works over HTTP, and my.openhab works as an HTTP proxy between your openHAB instance and your devices. Even if it can work with webviews bears no relation to whether it can or should proxy other protocols like MQTT.

Webcam streams do work. I have one on my sitemap using ffmpeg to stream an MPEG stream from the camera and the Video tag on the sitemap. This works through my.openhab. But again, this works through the HTTP protocol.