Hey everyone, I wanted to share my recent success with integrating the Unifi Video Motion API into my home automation setup. It’s been a fantastic journey, and I thought I’d walk through my process in case anyone else is looking to do something similar.
So, here’s the deal: I recently created a sensor that polls the Unifi Video API to detect motion on my cameras. This uses the REST platform, which I found to be pretty straightforward once I got the hang of it. I know some people use MQTT or check logs on the Unifi Video system, but I wanted to try something different. So far, it’s been working like a charm for the past few days!
Now, I’m still pretty new to Home Assistant and working with APIs in general, so I’m sure there are more efficient ways to do this. But hey, it works, and that’s what matters! I’d love to hear any suggestions or improvements others might have.
To get started, there are a couple of key pieces of information you’ll need. First off, your API key, which you can get from the Unifi Video user settings. Second, you’ll need the ID of your camera. I used Postman to get this by sending a POST request to http://unifi-video-ip:7080/api/2.0/login. The resulting JSON will have a section under cameraPermissions with your camera’s ID, which you’ll use in your code.
Here’s a quick look at my actual config for the motion sensor:
yaml
binary_sensor:
- platform: rest
resource: http://unifi-video-ip:7080/api/2.0/camera/5c29835792587293475e7?apiKey=asd0f9098sdf098sf09df
method: GET
authentication: digest
username: video-username
password: !secret video-password
name: ‘Camera Motion’
headers:
User-Agent: Home Assistant
Content-Type: application/json
device_class: motion
scan_interval: 1
value_template: >
{% if value_json.data.0.recordingIndicator == ‘MOTION_STARTED’ or value_json.data.0.recordingIndicator == ‘MOTION_INPROGRESS’ or value_json.data.0.recordingIndicator == ‘MOTION_DONE’ %}
{{‘ON’}}
{% else %}
{{‘OFF’}}
{% endif %}
I set the scan interval pretty high (every 1 second), but it doesn’t seem to be causing any issues so far. That said, if you’re polling multiple cameras, it might overload the NVR. I’m not entirely sure, so I’d love to hear others’ experiences with this.
This setup has really added a nice layer of automation to my home security. It’s been a great learning experience, and I’m excited to see how I can expand this further. If anyone has questions or wants to share their own API integrations, drop a comment below! Happy automating! ![]()