Home Automation with Node-RED and OpenHAB
Alarm Recording and Nightvision
The screenshot below shows the final UI that we are going to build using Node-RED and the Node-RED Dashboard. We want to be able to automatically activate the nightvision LEDs and start a 1min Recording on the internal SD card of your camera every time an alarm is triggered (Only to be used with cameras that have PIR Motion Detection). The use case is - you want to disable the IR nightvision LEDs during the night, which saves you electricity, makes your camera less intrusive and prevents the spider web problem (insects love the warm and illuminated front of your camera).
We already built a component that will store the camera login in a global variable (if you haven"t already, please import it into your Node-RED flow). Another component that we need is the Alarm Trigger component we build in the last project. This will be used to test our flow.
The new components are Node-RED Dashboard buttons and status text outputs to trigger a manual recording (we will set it to 60s - max. 15min) and to switch the IR nightvision on and off.
Be aware: that this flow uses the MQTT protocol to publish and subscribe to messages. This allows you to integrate the flow into other software platforms like the OpenHAB Home Automation. But you will have to install a MQTT Broker on your system to be able to use it. Those MQTT entry and endpoints can be replaced by Link Nodes, if you don"t only want to use the Node-RED dashboard to control your camera.
Alarm Recording
As you notice, the flow is using your camera"s Alarm Server to be notified when the alarm was triggered. You have to set up the alarm server to contact your Node-RED server with the following URL:
http://<IP Address>:1880/pushalarm/trigger/recording?nightvision=ON&recording=ON
Where <IP Address> is the address of your Node-RED server, e.g. 192.168.1.112. Your Node-RED flow is listening on /pushalarm/trigger/recording and will trigger the recording and IR activation whenever a GET request comes in.
Bonus :: OpenHAB Integration
Adding to the OpenHAB tutorial we are now going to consume the Node-RED flow in our OpenHAB 2 Basic UI.
Switch ManREC (MDGeneralControlGroup) {mqtt=">[mosquitto:openhab/alarm/manrec/trigger:command:ON:1],>[mosquitto:openhab/alarm/manrec/trigger:command:OFF:0]"}
String ManRECState "Recording [%s]" <camera> (MDGeneralControlGroup) {mqtt="<[mosquitto:openhab/alarm/manrec:state:JSONPATH($.manrec)]"}
Switch item=ManREC label="Manual Recording"
Text item=ManRECState