Blog Post:

Zoneminder Network Triggering

Zoneminder Network TriggeringI will be surprised if anyone actually reads this but I was surprised by the popularity of my previous Bluetooth posts, so here goes. Home automation is one of my hobbies and I currently use Zoneminder to manage my security cameras around my house (6 so far and #7 will be running if I get to Fry’s today). I have for a while wanted to be able to have events on my other home automation systems trigger recordings on my ZoneMinder security DVR system via the Zoneminder network triggering capability but I could never get it to work consistently until now. It appears the recent 1.26 release of Zoneminder solved the instability I was having with the external trigger mechanism which inspired me to finally get it working. So now any device that can make a TCP connection to my server on the right port can now start and stop recordings over the network

Zoneminder comes with a Perl script, zmtrigger.pl, located in /usr/bin on my Ubuntu server. Zmtrigger enables external applications / devices to trigger recording events in ZoneMinder. Zmtrigger as currently written allows applications / devices to interface over a TCP socket, Unix pipe, file system, or serial port. I chose to disable serial port and file system triggers because they were generating errors for me and causing the script to crash. This was as simple as adding a couple of # characters at the beginning of lines 57 and 58 to disable those methods:

Once I modified the zmtrigger.pl script, I could simply restart ZoneMinder to get access to the network triggers. If you want to test your modified zmtrigger.pl without a restart, just start it running with a shell command: sudo /usr/bin/zmtrigger.pl &. From a command prompt I could just use telnet to test the trigger mechanism. Note that it is listening on port 6802 (unless you changed the port in zmtrigger.pl) so the telnet command looks like:

telnet zoneminder_server_ip 6802

You will see a connection refused message if it fails (wrong IP, wrong port, plumbing not correct) but you will see something like this in your terminal if it succeeds :

hostname:~ username$ telnet xxxx.local 6802
Trying 192.xxx.xxx.xxx...
Connected to xxxx.local.
Escape character is '^]'.

The command syntax is pretty simple but I did not find it well documented anywhere. There are snippets documented here and here. You send it all ascii commands to tell it which camera to do what to and what to record in the zoneminder database for reason it was triggered.

Assuming you have a working camera set up and it is camera #1, the command “1|on+10|123|textstring1|textstring2|textstring3” should generate a response like:

hostname:~ username$ telnet xxxx.local 6802
Trying 192.xxx.xxx.xxx...
Connected to xxx.local.
Escape character is '^]'.
1|on+10|123|textstring1|textstring2|textstring3
1|on|1388246497|2
1|off|1388246509|2

There should be a 10 second pause between the 1|on line and the 1|off line because we told it to record for 10 seconds (“on+10”). Note that the vertical bars between the command fields are the pipe character, shift+backslash on my Apple keyboard. If you get the expected response, you should have a new event recorded on zoneminder for that camera:
Screen Shot 2013-12-28 at 10.14.24 AM
Note also that the recorded event is not precisely 10 seconds long. In my experience is always a second or more longer than requested.

The command syntax is as follows:
monitor#|action|priority|Cause|text|showtext where

  • monitor is the number of the zoneminder
  • action is “on” to turn on recording, “off” to turn off recording, “on+5” to record for 5 seconds
  • priority is a number between 0 and 255 (one unsigned byte). This is totally arbitrary and can be used to rank events importance in the event viewer
  • Cause is a text field you can use for any purpose. Since it is delimited with the pipe character it can use spaces with being escaped with quotes.
  • text is a freeform notes field you can put any notes in. You can access it from the event viewer by clicking on the Cause field and you can add and save notes too
  • I am not sure what the final text field is supposed to do. I have never been able to figure out the use of it. I think it is supposed to overlay text on the image but no luck. Maybe I need to read the perl script

One thing I learned the hard way, updates to Zoneminder (at least through the personal package archive I am using to get the latest 1.26 version) will overwrite your zmtrigger.pl script and erase your changes. So if event recording suddenly stops working, double check that your mods are intact on that script.

Well my original intent was to cover how to integrate events on the Vera with this Zoneminder network trigger system but this post is long enough. Hopefully this helps someone tinkering with Zoneminder to be able to trigger recordings over a network connection.

4 Responses

  1. I’m interested in your progress (someone actually read your post! 🙂

    I have a Vera Edge and a single foscam 9831w that I’ve been tinkering around with, and I’m trying to figure out if I want to buy more foscams, buy another brand or model of camera, if I can integrate multiple brands of video cameras into a single DVR/monitoring platform – or if I want to try to do that in Vera, etc.

    Would appreciate any thoughts you have about quality indoor or outdoor PTZ camera models, but I’m also interested to hear more about how you integrate scripted events with Zoneminder. I’ve been thinking about setting up Zoneminder for my DVR, but my biggest hesitation is compatibility with events and scenes in Vera.

    Anyways thanks for your post, looking forward to reading more about your setup.

    1. Greetings, appreciate the interest. I’ll answer as best I can.
      Integrating cameras with Vera: I only integrated the Panasonic PTZ cameras with Vera. I tried to integrate my other cameras but never got it to work. Vera is not really a good security DVR system in itself but it is a great trigger for a DVR system. The majority of my cameras are simple USB cameras attached to Linux boxes. The Linux boxes for the most part were already there doing other tasks (i.e. my router running openWRT or a mythTV front end or my garage sprinkler controller). So I don’t have a lot of experience with various commercial cameras but I have found the Zoneminder wiki and forum to be very helpful.

      Vera is a lot of fun and a good product that does the difficult job of balancing ease of use with powerful flexibility. Not perfect but a very good system.

      Since you are actually interested, I’ll write up the Vera integration post soon. It is pretty simple, just a short snippet of code in the LUUP section of a scene. Here’s a quick cut and paste from my Vera interface:
      local socket = require(“socket”)
      host = “192.168.2.109”
      local tcp = assert(socket.tcp())
      if( tcp ~= “nil” and tcp ~= nill) then
      tcp:settimeout(1)
      tcp:connect(host, 6802)
      tcp:send(“1|on+10|255|Trigger_from_LUA|text1|text2”)
      tcp:close()
      end

      That snippet sends a properly formatted TCP/IP packet from Vera to Zoneminder.

      Gotta get some paying work done, I’ll update soon.

  2. Thank you for sharing this. “zmtrigger.pl” is not very well documented on the ZoneMinder Wiki. You helped me to get my motion detector signal to start recording.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get in Touch

If you have a product design that you would like to discuss, a technical problem in need of a solution, or if you just wish you could add more capabilities to your existing engineering team, please contact us.