Zigbee Device Integration via IoT Hub into Mobile App
Zigbee — wireless protocol at 2.4 GHz (IEEE 802.15.4) with mesh topology. Devices relay signal through each other, giving good coverage without Wi-Fi. No direct Zigbee API in mobile apps — smartphones lack Zigbee radio. Always need a hub.
Hub Variants and Their APIs
Zigbee2MQTT — open-source bridge: Zigbee USB coordinator (SONOFF Zigbee 3.0, Conbee II, CC2652P) → MQTT broker. Most flexible for custom apps. Each device publishes state to topic zigbee2mqtt/{friendly_name}, accepts commands from zigbee2mqtt/{friendly_name}/set.
Motion sensor JSON state example (Aqara):
{
"battery": 85,
"occupancy": true,
"tamper": false,
"voltage": 2985,
"linkquality": 102
}
Zigbee2MQTT also provides REST API via zigbee2mqtt/bridge/request/device/options for configuration management — useful for app-based setup.
Home Assistant — if Zigbee2MQTT runs as HA addon, mobile app works via HA REST API or WebSocket API. Unified interface for all devices regardless of protocol. POST /api/services/light/turn_on with entity_id — instead of direct MQTT.
Philips Hue Bridge — supports only Philips Hue Zigbee devices. Closed ecosystem, but excellent REST API.
IKEA Hub — supports TRÅDFRI devices. Proprietary protocol over CoAP. Integration via reverse-engineering or Home Assistant.
Amazon Echo (4th gen) / SmartThings Hub / Aqara Hub — have built-in Zigbee coordinator. Each has different API.
Zigbee2MQTT as Mobile App Foundation
For custom mobile app Zigbee2MQTT is best choice. MQTT protocol simple, Zigbee2MQTT docs excellent, supports 3000+ devices.
Connect mobile client to MQTT broker (Mosquitto) via WebSocket (ws://broker-ip:9001). On Flutter — mqtt_client:
final client = MqttServerClient.withPort('192.168.1.100', 'mobile_app_client', 9001);
client.websocketProtocols = MqttClientConstants.protocolsSingleDefault;
await client.connect();
client.subscribe('zigbee2mqtt/+', MqttQos.atLeastOnce);
client.updates!.listen((messages) {
final topic = messages[0].topic;
final payload = MqttPublishPayload.bytesToStringAsString(
messages[0].payload.message
);
// parse JSON, update UI
});
Device command:
final builder = MqttClientPayloadBuilder();
builder.addString('{"state": "ON", "brightness": 200}');
client.publishMessage('zigbee2mqtt/living_room_light/set', MqttQos.atLeastOnce, builder.payload!);
Pairing New Devices from App
Zigbee2MQTT supports pairing mode via MQTT: zigbee2mqtt/bridge/request/permit_join with {"value": true, "time": 60} — 60 second window for new devices.
Mobile app starts pairing mode with button. Subscribes to zigbee2mqtt/bridge/event — on new device arrival: {"type": "device_joined", "data": {"friendly_name": "0x...", "ieee_address": "0x..."}}. Show user found device, offer naming and room assignment.
Rename: zigbee2mqtt/bridge/request/device/rename with {"from": "0x12345678", "to": "bedroom_sensor"}.
Device Network and Routing
Zigbee network self-organizes: routers (always-powered outlets, bulbs) relay signal for end devices (battery sensors). For diagnostics — zigbee2mqtt/bridge/request/networkmap with {"type": "raw", "routes": true}.
Visualize network in app: node and edge graph. On Flutter — graphview package or custom CustomPainter rendering. Nodes: coordinator, routers (green), end devices (gray). Edges: thickness proportional to LQI (Link Quality Indicator, 0–255).
Common Problems
Device dropout. Sensor stopped publishing. Zigbee2MQTT sets last_seen timestamp — check in app, warn if delay > N minutes. Usually battery depleted or device out of range.
Wi-Fi interference. Zigbee and Wi-Fi on 2.4 GHz. Wi-Fi channels 1, 6, 11 overlap with Zigbee channels 11–26. If unstable — check channel selection in Zigbee2MQTT (configuration.yaml, channel: 25).
Coordinator won't start. SONOFF Zigbee 3.0 USB Dongle Plus on some Linux requires explicit port in /dev/ttyUSB0 and user in dialout group. Docker — devices: ["/dev/ttyUSB0:/dev/ttyUSB0"].
Timeline
Zigbee2MQTT + MQTT client in app, basic device control — 2–3 weeks. Pairing from app, network visualization, diagnostics, automation — 5–8 weeks. Cost depends on device type count and additional features.







