c2de5ba85b
The Pine64 BLZ fork's zigbee2mqtt image crashes on start because
Bridge.start() calls firstCoordinatorEndpoint().deviceIeeeAddress
before the onMQTTMessage listener is registered. The BLZ coordinator
does not register its endpoint (the coordinator is the dongle itself,
no ZDO loopback), so firstCoordinatorEndpoint() returns undefined.
The crash happens in publishInfo() BEFORE onMQTTMessage is wired up,
which means every bridge MQTT request (permit_join, device rename,
group ops, etc.) silently no-ops — even though the message is
received.
Add infra/zigbee2mqtt/scripts/blz-bridge-patch.js that applies two
surgical fixes (idempotent):
1. Optional chain on the .deviceIeeeAddress access so the missing
endpoint doesn't throw.
2. Move onMQTTMessage registration BEFORE publishInfo/devices/
groups/definitions, and wrap each publish in try/catch so
Bridge.start() completes even if a single publish fails.
Add 'just z2m-patch-bridge' to apply the patch on the live container
after fresh image pulls.
infra/
Full stack configuration as deployed on the RPi 3B+ at 192.168.81.147.
Layout on host
/root/
├── compose.yaml → infra/compose.yaml
├── mosquitto/config/mosquitto.conf → infra/mosquitto/config/mosquitto.conf
├── zigbee2mqtt/ → infra/zigbee2mqtt/
│ ├── configuration.yaml # device pairings + friendly names + groups
│ ├── coordinator_backup.json # zigbee network key + pan id (recovery)
│ └── state.json # per-device persisted state (ON/OFF, etc.)
└── nodered/ → bind-mount for nodered container's /data
├── flows.json → generated from ../flows/zigbee-monitor.yaml
├── settings.js → infra/nodered/settings.js
└── start.sh → infra/nodered/start.sh (patches Dashboard SPA)
Rebuild procedure from a fresh host
- Install Docker,
docker compose. - Clone this repo,
cd infra. mkdir -p mosquitto/data mosquitto/log(empty dirs for the volume mounts).docker compose up -d.- Pair zigbee devices (IEEE addresses in
zigbee2mqtt/configuration.yamlwill be wrong; re-pair or use the existingcoordinator_backup.jsonto rejoin the same network). just deployfrom the repo root to push the Node-RED flow.
Files that drift at runtime
nodered/flows.json— managed by the generator, do not hand-edit.nodered/node_modules/@flowfuse/node-red-dashboard/dist/index.html— patched bystart.shat every container start; survives reboots, lost ondocker compose down -v.mosquitto/data/— broker persistence, transient.zigbee2mqtt/database.db— sqlite, transient (regenerated fromconfiguration.yaml+coordinator_backup.json).zigbee2mqtt/state.json— committed so device ON/OFF state survives full rebuilds.