Inspired by this post , I have developed a python script (and dockerized it) to poll motion detection events from Unifi Video NVR attached cameras.
When a new “lastRecordingId” is detected (and recording is not still in progress), the related video is downloaded, a gif is generated and sent to an MQTT topic.
This project is not based on Unifi Video video directories changes like the inspiring project, but on undocumented NVR APIs.
Check out the README file on the github page.
Hope someone will find it useful.
Check out also my similar project for Synology cameras.
This looks really cool, going to try it soon. However, the documentation is a bit difficult to understand. Could you expand on making it more easy to follow for beginners?
For example, I’m not sure how to use this exactly. Once the Docker image is running, what is the next step?
How do you get the JSON based config file passed in on the command line from Docker?
Do the gifs get “posted” to MQTT with the local URL or something? How do you automatically send the gifs to your phone via a notify action in Home Assistant?
Would be really helpful if the steps were more clearly laid out and easier to follow. I definitely want to give your script a try @fabtesta, hopefully you can help out.
You can place your config json in “unifi-nvr-api-motion-mqtt-gifs” folder relative to compose file.
Gifs are save under “ffmpeg_working_folder” configured path. The name of the gif is published to camera configured topic.
Now you should setup a sensor in home-assistant to detect gif name changes.
- platform: mqtt
name: "Sample Camera Gif"
state_topic: "cameras/gifs/sample"
Now it’s up to your automation to send the gif where you need to.
Example: telegram bot
- alias: "Telegram - Camera Motion - Gif"
trigger:
- platform: state
entity_id: sensor.sample_camera_gif
action:
- service: telegram_bot.send_document
data_template:
message: 'Sample Camera Motion'
target:
- !secret telegram_chat_id
file: /camera_gifs/{{ states.sensor.sample_camera_gif.state }}
caption: 'Sample Camera Motion'
Remember that the path “/camera_gifs/{{ states.sensor.sample_camera_gif.state }}” is the same of first container gifs bind mount, so the HA container container must include the same volume:
hass:
container_name: hass
....
volumes:
- ./config:/config
- /tmp/gifs:/camera_gifs <---- SAME SOURCE FOLDER OF FIRST CONTAINER
....
Finally don’t forget to whitelist the bind mounted directory to HA instance in your configuration.yml (homeassistant section)
Yes you can, but has some latency because of the api polling delay, video download and gif creation.
It’s much easier to watch unifi nvr log files to detect immediately the motion events.
There are some bash scripts around.