Ubiquiti Unifi Video (G3/UVC/NVR) : Motion sensor, and recordings

It’d be great to be able to use the Ubiquiti Unifi G3 cameras as motion sensors as well. There is an API endpoint to get the last recording, which includes timestamps, e.g.:

https://my-nvr-instance:7080/api/2.0/recording?cause[]=motionRecording&startTime=1543097000000&sortBy=startTime&sort=desc

Will return something like:

{
  "data": [
    {
      "eventType": "motionRecording",
      "startTime": 1543097377388,
      "endTime": 1543097395360,
      "cameras": [
        "deadbeef"
      ],
      "locked": false,
      "inProgress": false,
      "markedForDeletion": false,
      "meta": {...},
      "_id": "..."
    },
   .....
  ],
  "meta": {...}
}

Querying this API at regular intervals could yield:

  • whether a motion event is happening now on a device (based on inProgress flag of each camera)
  • the last recorded motion event (based on the endTime from the latest entry of each camera)
  • a list of recordings from each camera

I’d be happy to try to develop this feature if someone would mentor me through the process of contributing.

I haven’t integrated the recording as yet, but I made a script to talk to Home Assistant via MQTT to show motion. Here it is, https://github.com/cheloautomation/Home-Assistant/tree/master/scripts/unifi-camera-motion hope it some how helps you.

1 Like

Would it be possible have a python3 version of your script? And even better use it directly in HASS in the python_script folder

Since I am also after a similar feature for my G3, I am wondering if any of you could explain what the “state” attribute means, for my g3-device.

<template state camera.palantir=idle; access_token=abc, model_name=UVC G3, brand=Ubiquiti, motion_detection=True, friendly_name=palantir, entity_picture=/api/camera_proxy/camera.palantir?token=xyz, supported_features=0 @ 2019-10-27T16:15:54.920668+01:00>

When does the state change?