When MQTT vs HTTP vs ONVIF
-
ONVIF Thing — best on LAN with stable Ethernet to the camera; UDP/RTP on weak Wi-Fi often stutters without local transcoding.
-
HTTP binding — poll bridge REST for play URL refresh; workable but couples stream lifecycle to poll interval.
-
MQTT binding — preferred for alarms and status pushed from your cloud callback bridge; video URL can be a String Item updated by a separate HTTP or scripted poll.
We use cloud OpenAPI on a backend (token + sign), MQTT for events, HTTP only to fetch a fresh HLS URL into an Item every 8 minutes.
MQTT Thing
// things/mqtt.things
Bridge mqtt:broker:home "Home MQTT" [ host="192.168.1.10", port=1883 ] {
Thing topic camera_alarms "Camera alarms" {
Channels:
Type string : motion_alarm [ stateTopic="camera/alarm/DEVICE_ID", transformation="JSONPATH", transformationPattern="$.type" ]
Type string : raw_payload [ stateTopic="camera/alarm/DEVICE_ID" ]
Type contact : online [ stateTopic="camera/status/DEVICE_ID", on="online", off="offline" ]
}
}
Items
// items/camera.items
String Camera_MotionType "Motion type" { channel="mqtt:topic:camera_alarms:motion_alarm" }
String Camera_RawAlarm "Last alarm JSON" { channel="mqtt:topic:camera_alarms:raw_payload" }
Contact Camera_Online "Camera online" { channel="mqtt:topic:camera_alarms:online" }
String Camera_LiveUrl "Live HLS URL"
Refresh URL via scripted HTTP (execute periodically or on button):
// scripts/refresh_live.js — run from rule or cron trigger
var url = "http://bridge.local/live?device=DEVICE_ID&stream=sub";
var response = HTTP.sendHttpGetRequest(url);
events.sendCommand("Camera_LiveUrl", response);
Rule — motion triggers light (JavaScript)
// rules/camera_motion.js
rules.JSRule({
name: "Porch motion from MQTT",
triggers: [
triggers.ItemStateUpdateTrigger("Camera_MotionType")
],
execute: (event) => {
if (event.itemState.toString() !== "motion") return;
if (items.get("Camera_Online").state !== "ONLINE") return;
actions.sendCommand("Porch_Light", "ON");
}
});
(Compare: HA calls these “entities”; openHAB uses Items linked to Channels on Things.)
Pitfall: Thing ONLINE vs Item NULL
MQTT Thing can show ONLINE while Items stay NULL until the first message arrives—rules firing on startup may see UNDEF. Gate motion rules on Camera_Online and wait for initial payload. JSONPATH on alarm JSON fails silently if the vendor adds fields; log Camera_RawAlarm when debugging weak-network false offline bursts.
For video, cap bitrate at the bridge (FFmpeg -b:v 800k) before exposing RTSP to openHAB’s RTSP binding if HLS in a WebView isn’t your path.
Weak-network note
Sub-stream + shorter client buffer beats upscaling after stall. Debounce offline MQTT status 90s—we stopped flapping porch lights during brief uplink drops.