Motion and smart detect setup #30
Replies: 3 comments 7 replies
-
Hey, thanks! Great idea! So, I've been scouring the internet to see if I can find any documentation about Protect endpoints, but I only managed to find the ones that are listed in the README as of now, which are:
It appears to be possible to retrieve data about events as well? |
Beta Was this translation helpful? Give feedback.
-
Alright you're connected to this websocket That's the starting point. I have found a few very useful things coming from that websocket. If you get a message that passes this JS test: if (msg.payload.action.action == "add" && msg.payload.payload.type == "smartDetectZone") Then you are working with a smart detection! The important bit of the smart detection is in the same payload, located at That little guy is the unique string for the smart detect event. You will use it again later! Some time later you will get a new message which will pass the following test. This is the "end" of your smart detect event. The if (msg.payload.action.action == "update" && "end" in msg.payload.payload) From there you can find the thumbnail using a unifi http request pointed at this I'm using the image preview node red contrib to view these thumbnails. Also saving them to my pi locally just for dev purposes. Eventually I might build something else from this. |
Beta Was this translation helpful? Give feedback.
-
And what if you want to watch motion alerts instead of smart detection?! We can do that, too! Watching that same endpoint Run the output of if (!("cameras" in msg.payload)) {
return;
}
msg.payload.cameras.forEach(element => {
// let myWarning = {
// id: element.id,
// name: element.name
// }
flow.set(element.id, element.name);
// node.warn(myWarning);
})
msg.payload.sensors.forEach(element => {
// let myWarning = {
// id: element.id,
// name: element.name
// }
flow.set(element.id, element.name);
// node.warn(myWarning);
})
return; That will set flow variables which have the "friendly name" for each of your cameras! It's very helpful for the next part. Now we run the output of updates websocket through this JS function: if (!("payload" in msg)) {
return;
}
if (!("payload" in msg.payload)) {
return;
}
// if (msg.payload.action.id != "60b6ab840105c10387000471") {
// return;
// }
// if (msg.payload.action.action == "add") {
// return msg;
// }
if ("isMotionDetected" in msg.payload.payload) {
let newMsg = {};
newMsg.topic = flow.get(msg.payload.action.id);
newMsg.payload = {
"MotionDetected": msg.payload.payload.isMotionDetected
}
return newMsg;
}
return; That will output messages like {
"topic": "Family",
"payload": {
"MotionDetected": true
},
"_msgid": "fa186f0a53b2a0c8"
} And the same format but |
Beta Was this translation helpful? Give feedback.
-
@franklinvv - let's start a discussion here about endpoints! I'll be happy to share and get you running there.
Beta Was this translation helpful? Give feedback.
All reactions