I have a zoneminder system that sends motion data to node red via MQTT. Currently I parse that data with a function node. A while back I read that using function nodes isn't very efficient. What I'm looking to do is create a node that detects a person in a specific zone. Here is an example of the object:
Also show us the Function you are using. Copy/paste the text from the function node please. Then we will be able to see what you need.
The overheads of using a function are not large so unless you are running it thousands of times a second (or dozens of times a second on a Pi Zero) then I would not worry about it.
@zenofmud there is a key in the JSON object called "detection" also a key called "confidences"
Here is the function:
var stuff = msg.payload;
if (stuff.detection.confidences > 0.60){
var myname = stuff.name
var splitname = myname.split(":");
if(splitname[2] == "person"){
var contentstr = "The " + splitname[0] + " camera has indicated a person moving within it's field of view. The Id is: " + stuff.eventid + " https://zimmhomecam.net/zm/index.php?view=image&eid=" + stuff.eventid + "&fid=snapshot&width=600&username=****&password=***"
view=image&eid=9666&fid=objdetect&width=600&username=******&password=xxx****
msg.payload = {
type: "message",
title: "Camera system motion",
chatId: Mychatid,
content: contentstr,
}
}
}
return msg;
Eventually I'd like to add variables to change the confidence required to send a message, for now though I'm trying to get it a little more "dialed"
1)What version of NR and node.js are you running? (you can find this in the startup log)
2) notice all the items underlined. That is because those items have not been defined.
3) where is Mychatid coming from?
4) what are you attempting to do with the new = ... line?
5)What do you want the end result of the function node (or replacement) to look like?
@zenofmud thanks for looking into this. I changed a couple pieces of the code for security purposes. So line 13 where it lists "Mychatid" would actually be the chat id for telegram. On line 7 I substituted the asterisks for my actual user name and password, again for security purposes. As far as the 4th question I don't see a line containing "new =". As far as you question 5, that's really my question. Is there a better way to send messages based on if the JSON payload from Zoneminder has detected a person within a certain percentile?
Assuming you have it working with code in a function node, why would you change? Maybe it would be possible to break up things and use a number of standard nodes in line, but why? If you do not run into any performance issues and the notification is fast enough, I would not change.
With the code you have full control of what is happening. I assume, it looks that way, you also grab and send an image as attachement. With the code you are preparing the message that is sent to, I guess, a Telegram node. I do pretty much the same in my setups, works fine and good enough.