Trigger Recordings through a MQTT Topics in Node-RED

Q: The WebUI as well as the smartphone app allows me to trigger a video recording onto the internal SD card. Is it possible to trigger this recording with a smarthome system through the MQTT interface?

A: Yes! The recording is controlled by two MQTT topics - one to start a 15s, 30s, 45s or 60s recording and the other to stop it prematurely, if needed:

  • task/video/rec/start: payload message {"val":"15"},{"val":"30"},{"val":"45"},{"val":"60"}
  • task/video/rec/stop: payload message {"val":"1"}

Update: Of course you do not need Node-Red to use the MQTT API. You can find a guide on how to trigger the video recording using the MQTT Explorer on our Forum. This can be done with any MQTT client that is able to connect to the same MQTT Broker as your camera.

Here is an example how to integrate this function into Node-RED. The entire Node-RED Flow can be imported from the JSON code below:

Auto-Refreshing MQTT Topics in Node-RED

Auto-Refreshing MQTT Topics in Node-RED

Alternatively, you can also use the planned recording. Make sure that the schedule is enabled but the recording remains disabled. Now use the following command to enable 1 or disable 0 the recording when needed.

  • task/video/planrec/enable: payload message {"val":"1"}, {"val":"0"}

The recording will end when you disable it - you do not have to provide a max. duration like with the manual recording above. But the recording will be divided into several files if the max length is exceeded. You can set the length of the video files from the webUI or use the following MQTT command topic to set it dynamically:

  • task/video/planrec/length: payload message up to {"val":"600"}

Auto-Refreshing MQTT Topics in Node-RED

Node-RED Flow

UPDATE: An extended example can be downloaded from Github:

Github Repository

Note that the example below uses a the camera MQTT broker on IP address 192.168.2.115 and the is configured with the MQTT prefix and client ID of cameras/115/. Please replace those according to your setup:

[
    {
        "id": "e38003f441ebe758",
        "type": "tab",
        "label": "Recording",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "8739c3f13d21f8c8",
        "type": "mqtt out",
        "z": "e38003f441ebe758",
        "name": "task/video/rec/start",
        "topic": "",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c9bd856c466f9b0",
        "x": 350,
        "y": 40,
        "wires": []
    },
    {
        "id": "6f2456fbbab22c65",
        "type": "function",
        "z": "e38003f441ebe758",
        "name": "topic",
        "func": "const command = 'task/video/rec/start';\nconst prefix = 'cameras/115/';\n\nmsg.topic = prefix + command;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 190,
        "y": 40,
        "wires": [
            [
                "8739c3f13d21f8c8"
            ]
        ]
    },
    {
        "id": "030ecf3a64bd5f6c",
        "type": "mqtt out",
        "z": "e38003f441ebe758",
        "name": "task/video/rec/stop",
        "topic": "",
        "qos": "1",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c9bd856c466f9b0",
        "x": 370,
        "y": 100,
        "wires": []
    },
    {
        "id": "0f73a30e35c79b4f",
        "type": "function",
        "z": "e38003f441ebe758",
        "name": "topic",
        "func": "const command = 'task/video/rec/stop';\nconst prefix = 'cameras/115/';\n\nmsg.topic = prefix + command;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 210,
        "y": 100,
        "wires": [
            [
                "030ecf3a64bd5f6c"
            ]
        ]
    },
    {
        "id": "c4edc7fd9949a938",
        "type": "ui_button",
        "z": "e38003f441ebe758",
        "name": "",
        "group": "a0240f14e128be2a",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Stop Rec ",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"val\":\"1\"}",
        "payloadType": "json",
        "topic": "payload",
        "topicType": "msg",
        "x": 80,
        "y": 100,
        "wires": [
            [
                "0f73a30e35c79b4f"
            ]
        ]
    },
    {
        "id": "29faba26eada713d",
        "type": "ui_button",
        "z": "e38003f441ebe758",
        "name": "",
        "group": "09317789e191eb54",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Rec ",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"val\":\"15\"}",
        "payloadType": "json",
        "topic": "payload",
        "topicType": "msg",
        "x": 70,
        "y": 40,
        "wires": [
            [
                "6f2456fbbab22c65"
            ]
        ]
    },
    {
        "id": "8c9bd856c466f9b0",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.2.115",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "5",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "a0240f14e128be2a",
        "type": "ui_group",
        "name": "Stop Recording",
        "tab": "8bc4b79cc7336533",
        "order": 4,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "09317789e191eb54",
        "type": "ui_group",
        "name": "Trigger Recording",
        "tab": "8bc4b79cc7336533",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "8bc4b79cc7336533",
        "type": "ui_tab",
        "name": "Video Recording",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]