2.7 KiB · text History d69022d
# mr-bridge — forward all local MQTT topics to a remote broker.
#   include = ["include/mr-bridge.toml"]   (pairs with mosquitto + zigbee2mqtt)
#
# Rationale: z2m insists on talking to the local broker, so instead of pointing
# z2m at the remote, we run mr-bridge (https://github.com/neiam/mr-bridge) to
# relay everything localhost -> remote. One-directional "#" rule = every topic.
#
# >>> EDIT the [far] host below to your remote daemon before publishing. <<<

[[files]]
path = "/etc/mr-bridge/config.toml"
mode = "0644"
content = """
# Loop prevention: drop the echo of a forwarded message within this window, so we
# can bridge the whole z2m tree both ways with a single "wherever" rule without a
# storm. Must be the first key, before the [near]/[far]/[[rules]] tables.
dedup_window_secs = 10

# Local broker (the mosquitto this box runs).
# max_packet_size lifts rumqttc's 10 KiB default so large z2m retained payloads
# (bridge/definitions, bridge/devices) can pass; 5 MiB here.
[near]
host = "localhost"
port = 1883
max_packet_size = 5242880

# Remote daemon — CHANGE host (and add username/password if it needs auth).
[far]
host = "172.16.13.58"
port = 1883
max_packet_size = 5242880
# username = "bridge"
# password = "..."

# Full Zigbee2MQTT tree, bidirectional in ONE rule: state flows out, commands
# (+set / +get, bridge/request, nested friendly-names) flow back. Safe now that
# echo suppression (dedup_window_secs above) drops the loop "wherever" would
# otherwise cause.
[[rules]]
topic = "zigbee2mqttfront/#"
direction = "wherever"
qos = 1

# If z2m has Home Assistant MQTT discovery enabled (homeassistant: true), forward
# its discovery topics to HA too. One-way; harmless no-op if you don't use it.
[[rules]]
topic = "homeassistant/#"
direction = "near_to_far"
qos = 1
"""

[[files]]
path = "/etc/containers/systemd/mr-bridge.container"
mode = "0644"
content = """
[Unit]
Description=mr-bridge (MQTT bridge to remote broker)
Wants=network-online.target
After=network-online.target mosquitto.service

[Container]
Image=ghcr.io/neiam/mr-bridge:latest
# host networking so "localhost" in [near] resolves to this box's mosquitto.
Network=host
Volume=/etc/mr-bridge/config.toml:/etc/mr-bridge/config.toml:ro,Z
# The image's default command is --help; override it to run with our config.
Exec=--config /etc/mr-bridge/config.toml
Environment=RUST_LOG=info
AutoUpdate=registry

[Service]
Restart=always

[Install]
WantedBy=multi-user.target default.target
"""

[[services]]
name = "mr-bridge.service"
enabled = true
# "restarted" so edits to config.toml (far host, rules) are actually applied on
# the next publish — a "started" service is left running with its old config.
state = "restarted"