I am building an alarm system in node-red with multiple cameras in Unifi Protect. When a camera detects a person, I want to have a notification on my phone (iOS) with a snapshot of the detection, and when I click on the notification I want to see the video of the recorded event which triggered the notification.
I have the notification working with the snapshot, but I am struggling to get a link to the video. The cameras are all set to record only on motion, not continually.
The Unifi Protect documentation seems to imply that I should be able to create a link to a media-source with the video in question. I believe such a link probably should look something like this:
media-source://unifiprotect/606e5cff028cea02870003e9:browse:6228bd440089b2138701174a:smart:recent:1
I derived the link above from what the Unifi Protect integration creates inside the Media tab in the HA GUI, and I’ve tried various combinations including links that look more like what the Unifi Protect documentation states such as {nvr_id}:event:{event_id}
, all to no avail.
I am including the link as the msg.video variable in the node-red function node below which builds the json for the notification to my phone.
let nvr_id = "25c342debc987901fd51b73c30234c49"
let image_url = `/api/unifiprotect/thumbnail/${nvr_id}/${msg.event_id}`
msg.payload =
{
"data":
{
"message": msg.deviceName,
"data":
{
"time-sensitive": 1,
"image": image_url,
"url": msg.video
}
}
}
return msg;
I have had inconsistent success using the method:
/api/unifiprotect/video/{nvr_id}/{camera_id}/{start}/{end}
I believe primarily because I cannot find a programmatic way to get the end time for the video (and possibly the start time is not always correct either). By “inconsistent”, I mean more than half of the time the link is a 404. (Actually, I’m surprised it’s not pretty much always a 404).
I have looked at the blueprint from AngellusMortis but I have not actually installed it (maybe I need to try that).
I also found this helpful post from clin248 to extract the nvr_id, event_id and other necessary information.
If anyone has further tips what to try please let me know!