MQTT Camera for Node-RED

Activate Nightvision when PIR detects Motion

All IP cameras tend to run their IR LEDs all night to enable software-based motion detection. This causes a couple of problems besides the electric bill increase. There are cameras that have "invisible" IR LEDs usually working at 940nm - invisible to the human eye. But the reach of this wavelength, especially outdoors, is fairly limited. This is why most cameras employ night vision LEDs with a peak emission around 850nm. This emission is usually wide enough to reach into the higher limit of wavelengths that our eye registers (around 700nm) - meaning those LEDs project a red light that is visible over large distances.

Another disadvantage of having those LEDs on all night is the heat they generate. The high temperatures and the quick cooldown every morning, when the LEDs are switched off, reduces the lifetime of the electronics inside your camera.

And last but not least the IR light attracts insects that keep flying in front of your camera triggering false alerts during the night. And once you have flying insects you quickly end up with spider webs in front of your camera that can cause false alerts day and night.

The solution is the use of the internal passive-infrared sensor (PIR) to detect moving objects, who's temperature differs from the background. Once detected the PIR should trigger the INSTAR HTTP alarmserver to contact a webhook in Node-RED. And then have Node-RED activate the IR-LEDs for the time of the alarm recording.

Modules Used

This time I don't need any special nodes. The setup is almost identical to the setup above. Only that I use the regular delay node now instead of the Stoptimer2. Once the webhook is contacted an MQTT node updates the IR-LED topic to switch on nightvision. Also triggered is a delay node with a fixed delay time - in my case 15s - and another MQTT node after that, that deactivates the IR LEDs after the alarm recording on my camera stopped.

Node-RED Flow

PIR-nightvision-switch

[{"id":"62094242.6f4ecc","type":"http in","z":"f6bbaaa5.59a388","name":"IR LEDs","url":"/activate-ir/","method":"get","upload":false,"swaggerDoc":"","x":70,"y":700,"wires":[["d4a6f269.edf48","f8572f74.0be2b","afa82724.e4ad18"]]},{"id":"d4a6f269.edf48","type":"template","z":"f6bbaaa5.59a388","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h2>Hallo von Node-RED</h2>\n    </body>\n</html>","x":211,"y":659,"wires":[["b41b8605.b4bf08"]]},{"id":"b41b8605.b4bf08","type":"http response","z":"f6bbaaa5.59a388","name":"","x":331,"y":659,"wires":[]},{"id":"afa82724.e4ad18","type":"delay","z":"f6bbaaa5.59a388","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":203,"y":745,"wires":[["7c176d7a.621094"]]},{"id":"f8572f74.0be2b","type":"change","z":"f6bbaaa5.59a388","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"auto\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":197,"y":700,"wires":[["c6b4ea6.2d0cf18"]]},{"id":"c6b4ea6.2d0cf18","type":"mqtt out","z":"f6bbaaa5.59a388","name":"features/nightvision/autoled","topic":"instar/000389888811/features/nightvision/autoled","qos":"1","retain":"false","broker":"9e4e460d.640f18","x":383,"y":700,"wires":[]},{"id":"695cd52b.796fdc","type":"mqtt out","z":"f6bbaaa5.59a388","name":"features/nightvision/autoled","topic":"instar/000389888811/features/nightvision/autoled","qos":"1","retain":"false","broker":"9e4e460d.640f18","x":522,"y":745,"wires":[]},{"id":"7c176d7a.621094","type":"change","z":"f6bbaaa5.59a388","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"close\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":332,"y":745,"wires":[["695cd52b.796fdc"]]},{"id":"9e4e460d.640f18","type":"mqtt-broker","z":"","name":"IN-9010FHD","broker":"192.168.2.165","port":"8883","tls":"ccad131e.c9943","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ccad131e.c9943","type":"tls-config","z":"","name":"9010pcert.pem","cert":"","key":"","ca":"","certname":"9010pcert.pem","keyname":"","caname":"","servername":"","verifyservercert":true}]

* this flow is written for a camera with the MQTT ID 000389888811. Search&replace all instances of this with your cameras ID before importing

The INSTAR MQTT topic for switching the IR LEDs from deactivated to automatic is:

  • features/features/nightvision/autoled

The webhook can be contacted under [Node-RED IP]:[Node-RED Port]/activate-ir/

1 Like