Use security cameras to trigger lights

#1

Want to get the motion status from your security cameras in Xeoma to display in Home Assistant? Or do you just want to convert HTTP Requests into MQTT messages? I'll show you the neat way that I accomplished this using Node-RED

Xeoma is a great security camera program that I highly recommend if you need security camera software running on a headless server and accessed via a lot of clients on different devices (mobile and desktop) from anywhere anytime (without the cloud). It is very flexible and lets you set up HTTP Request Modules that can send out a request whenever motion is detected for a camera.

The only problem with that is I want it to send out MQTT messages. In order to achieve this I use Node-RED (If you haven't checked it out and are into home automation I highly recommend it). It's super easy. All you need to do is setup Node-RED and import this flow I created that converts HTTP Requests into MQTT messages:

[{"id":"c23bb9c9.d6c358","type":"http in","z":"ff717302.0c688","name":"","url":"/xeoma_to_mqtt","method":"post","upload":false,"swaggerDoc":"","x":360,"y":1380,"wires":[["976d6b19.5b14b8"]]},{"id":"4bfdb53e.76e1bc","type":"http response","z":"ff717302.0c688","name":"HTTP OK 200","statusCode":"200","headers":{},"x":860,"y":1420,"wires":[]},{"id":"dd5bd9c2.ef3c48","type":"mqtt out","z":"ff717302.0c688","name":"","topic":"","qos":"2","retain":"true","broker":"5a59e251.9e1d4c","x":830,"y":1360,"wires":[]},{"id":"976d6b19.5b14b8","type":"function","z":"ff717302.0c688","name":"Format Msg","func":"// snippet from https://github.com/skylord123/xeoma-mqtt\n\nvar ch_prefix = 'cameras/';\nmsg.topic = (typeof msg.req.body.channel !== 'undefined' ? ch_prefix + msg.req.body.channel : null);\nmsg.payload = (typeof msg.req.body.msg !== 'undefined' ? msg.req.body.msg : null);\n\nif(!msg.topic || !msg.payload) {\n    return [null, msg];\n}\n\nnode.status({\n    fill: msg.payload == \"1\" ? \"green\" : \"red\",\n    shape: \"dot\",\n    text: msg.topic\n});\n\nreturn [msg, null];","outputs":2,"noerr":0,"x":590,"y":1380,"wires":[["dd5bd9c2.ef3c48","4bfdb53e.76e1bc"],["2cc21314.ddaaec"]]},{"id":"2cc21314.ddaaec","type":"http response","z":"ff717302.0c688","name":"HTTP Error 500","statusCode":"500","headers":{},"x":860,"y":1460,"wires":[]},{"id":"cf1132aa.b3117","type":"comment","z":"ff717302.0c688","name":"Turn Xeoma HTTP Request into a MQTT message","info":"Snippet from https://github.com/skylord123/xeoma-mqtt","x":590,"y":1300,"wires":[]},{"id":"5a59e251.9e1d4c","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]

Import the above snippet and then modify the variables in the function block and MQTT block to match what channel prefix you want to use. The function block just uses JavaScript so it is super easy to understand (If you do need help feel free to comment).

Once that is created if all you are doing is just turning HTTP Requests into MQTT messages then you are done. If you want to get it setup in Xeoma then keep reading..

Now we need to setup the HTTP Request Modules in Xeoma and get them using our newly created Node-RED flow. In order to do this create two HTTP Request Modules after the Motion Module that you want to track. It will look something like this:

Now open up one of the motion modules and set it up like this (Of course changing the IP address, authentication details, and channel name):

Once you have that setup open the second HTTP Request Module you created and do exactly the same as before except change the msg under parameters from a "1" to a "0" and the "Send" drop-down from "when event started" to "when event ended". I recommend testing everything is working at this point with a MQTT client such as this one.

If all is well then you can go ahead and set it up in Home Assistant as a binary sensor. Once that is done all you got to do is setup an automation that triggers your lights when motion is detected. I will be covering more on that in a later article (I will link it here once it is done).


This is a companion discussion topic for the original entry at http://skylar.tech/send-motion-events-over-mqtt-from-xeoma/
0 Likes