Forwarding mi gateway multicasts from remote locations

Actually, this article is the memory for myself. Article describes notes on setting up network infrastructure with remote xiaomi mi gateways, so the openhab will still receive multicasts with sensors updates also from remote endpoints.

Network setup

If you are reading this article, you know, that xiaomi smart home gateway after some firmware update no longer provides REST interface for updates. Instead, it provides updates purely in local network using multicast to group 224.0.0.50 and port 9898. This means, that all updates are isolated now to local network only, and prevents one instance of openhab from controlling different sites.

Keeping in mind multicast idea, the only option to get those updates is to join openhab to remote sites via some VPN supporting L2 layer. Good example of free vpn supporting L2 — OpenVPN.

Once we get smart gateway multicast on openhab box, next challenge would be to join multiple sources on a single network interface.

As OpenHab does not support multicast listening on multiple interfaces, and 224.0.0.50 group can’t be routed using igmpproxy, pimd or smcroute — the workable choice is to configure Bridge Networking on opehab server, combining local ethernet (eth0) together with VPN interface (tap0)

Now a bit of “configuration” meat.

Openhab Server — Bridge Networking

Note, in some systems, like Raspbian necessary package might not be installed. Check additionally.

Let’s configure bridge on openhab box. Note, that eth0, which corresponds to your physical network card does not obtain ip address and instead delegates that task to bridge.

Remote site — OpenVPN server

Ideally, if you have router that already supports L2 OpenVPN. Routers supporting custom firmware (Padavan, Openwrt, Tomato — for sure), Microtics and so on.

If for any reason you don’t have such router, this means you would need to place one more box on remote site (possible — the similar raspberry pi) and install OpenVPN there.

Openhab Server — Openvpn Client

Assuming openvpn client is installed on openhab box, let’s configure channel to remote smarthome site.

On up we join interface to bridge, on down — drop.

up.sh

down.sh

Openhab Server — Validating setup

If you configured everything properly, you should see broadcasts from multiple smart home gateways using tcpdump

Openhab Server — Persisting configuration changes

I am running home automation on simple Raspberry PI 3. It has one drawback — for 24/7 work thermals are not good even with passive cooling. SD card potentially might die quite soon, hardware — depends on plate cooling quality.

Thus I prefer to configure openhab via file configuration, with set of deployment batches, that provision openhab server with updates. All configuration changes are stored in a private git repository.

Additionally, ansible plays are used for initial box configuration (zsh shell, docker daemon, prometheus exporters, openvpn configuration and so on)

This allows me to easy recover openhab state in case of sudden failure.

Some code snippets can be found at https://github.com/Voronenko/openhab-remote-xiaomi

Tips and tricks

Design patterns — set of ideas how to properly implement typical things

VS Code extension I find really helpful to code smart home configuration as a code

Software engineer, with project management background. Founder @ softasap.com — cool automation for the people :) — have a problem that needs to be solved?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store