Zoneminder intergration

739 views
Skip to first unread message

Nathan Stratton

unread,
Aug 10, 2015, 11:29:03 AM8/10/15
to openhab
I found in the Wiki scripts that let Zoneminder push alarms to OpenHab. However I have found that using cameras to detect motion is not that great. Bugs flying buy trigger alarms etc. What I would like to do is flip this. I have real motion detectors and would like to trigger ZoneMinder alarms so Zoneminder will record based on OpenHab alarms rather then video motion.

Anyone doing something like this?

><>
nathan stratton | vp technology | broadsoft, inc | +1-240-404-6580 | www.broadsoft.com

Daniel Whittred

unread,
Aug 11, 2015, 1:12:20 AM8/11/15
to openhab
Hey Nathan,

i have done something similar for a remote web camera I built. I have the remote camera ftp to my server and upload a new image every half hour, and the trigger an alarm on zoneminder so that it reads in the new image. This basically just uses zoneminder as an archiving tool for timelapse photography.

Below are my notes when i first started looking at, but from memory, you first get zoneminder to enable external triggers (and create a listening tcp socket). From there you can send a string to that socket that enables and disables the alarm. 

Anyway, the notes below and links to the forums should get you started.

-Dan

The below is an excerpt from an arduino forum thread:

On Zonemineder:
On ZM is necessary to enable the external trigger; it is possible to start recording on external event using serial comunication, network comunication or file in a folder "comunication" (ZM check for a file in a specific folder); I have chosen the networdk comunication.
 
1 Enable external trigger:
Edit the file zmtrigger.pl
Check for the some comunication system row definition and comment the not used (put # at the start of the lines):
[cut]
my @connections;
push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan1", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) );
#push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan2", channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>ZM_PATH_SOCKS.'/zmtrigger.sock' ), mode=>"rw" ) );
#push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan3", channel=>ZoneMinder::Trigger::Channel::File->new( path=>'/tmp/zmtrigger.out' ), mode=>"w" ) );
#push( @connections, ZoneMinder::Trigger::Connection->new( name=>"Chan4", channel=>ZoneMinder::Trigger::Channel::Serial->new( path=>'/dev/ttyS0' ), mode=>"rw" ) );
[cut]
 
This procedure enable ZM to listen on udp port 6082 for external command.... (in case you can change this port...)
From the web interface of ZM:
2 Take a camera, put "Nodect" for function type (instead of motion detection, recording,...)
3 In the ZM options (System Page/TAB) put the check on "OPT_TRIGGERS" (enable zm to check for external triggers)
 
Ok, zm configuration is finish!; now on arduino...
Is necessary to create a program that connect ZM on port 6802 (UPD using ethernet) and send the command...
Command format:
6|on+60|255|Arduino alarm
 
Synstax:
6 is the ID (in the database of ZM), you can find it on the web interface of ZM moving the mouse on the camera (in the link you can see the ID; eg: ...../index.php?view=watch&mid=6)
on+60 Start recording and stop it after 60 seconds
255 the amount of the point for the motion detection (fixed to 255; is the top)
Arduino allarm comment of the alarm
All parameters must be separate with pipe char (|)
 
another eg
6|on
Start to recording without end (is necessary to send the command 6|off for stop the recording)
 
Send this type of command for each camera needed (changing the ID of the camera)
 
At the moment I cant send a sample of the code of arduino... but using the sample in the ide is very simple to implement; in my case a pin of the arduino is conneceted to a switch, when I close it, ZM start to recording...
 
Pasted from <http://forum.arduino.cc/index.php?topic=88331.0;wap2

Another example is:
#!/bin/bash
echo Content-type: text/plain
echo "$1|on+10|255|AMotion" >/dev/tcp/localhost/6802
 
Pasted from <http://www.zoneminder.com/forums/viewtopic.php?f=21&t=19540

 Also there is a way to use a query string to force an alarm:
I have some cameras that are on 3G modems and I have limited data traffic so I would like to only record on external events (zmtrigger or forceAlarm url)
 
Code:
index.php?view=request&request=alarm&id=1&command=forceAlarm
which works fine with "Nodect" but I see that ZM always stream from the camera, and I would like ZM to only start stream from the camera when i trigger event or when i open the monitor. 
 
If I switch the mode to "None" for the camera i see that ZM stop stream from the camera but then i would need to switch this mode all the time and i would rather see that i can just open the montor to get live feed.
 
Is this possible?
 
Pasted from <http://www.zoneminder.com/forums/viewtopic.php?f=29&t=21623&p=82132&hilit=zmtrigger#p82132

Nathan Stratton

unread,
Aug 11, 2015, 12:07:46 PM8/11/15
to ope...@googlegroups.com
On Tue, Aug 11, 2015 at 1:12 AM, Daniel Whittred <djwh...@gmail.com> wrote:
Hey Nathan,

i have done something similar for a remote web camera I built. I have the remote camera ftp to my server and upload a new image every half hour, and the trigger an alarm on zoneminder so that it reads in the new image. This basically just uses zoneminder as an archiving tool for timelapse photography.

Below are my notes when i first started looking at, but from memory, you first get zoneminder to enable external triggers (and create a listening tcp socket). From there you can send a string to that socket that enables and disables the alarm. 

Anyway, the notes below and links to the forums should get you started.

Thanks! I was going down the TCP method, it was working, but I did not like the hack of using a dimmer and map for the strings. I did not know you could set alarms over http, this works much better!


So now I have items to control my cameras, next what I need is something that triggers it. Such that when motion is detected the camera turns on and a 30 second timer is started to turn off the camera. If there is any new motion while the timer is running it is reset to 30 seconds. 

Any idea how to do that in a rule?

Nathan Stratton

unread,
Aug 11, 2015, 3:14:39 PM8/11/15
to ope...@googlegroups.com
Ended up going with the rule below. I will have many motion sensors and cameras so I am sure there is a way to do it better, but its what I have now. :)

import org.openhab.core.library.types.*
import org.openhab.core.library.items.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

var Integer timeOut = 30
var Timer Shed_Motion_03_Timer = null
var Timer Shed_Motion_01_Timer = null

rule "Shed_Motion_01 Sensor Trip"
        when
        Item Shed_Motion_01 received update
        then
        {
        logInfo("Motion", "Shed_Motion_01 sensor changed state")
        if(Shed_Motion_01.state == OPEN)
            {
            if (Shed_Motion_01_Timer == null )
                {
                // create timer
                logInfo("Motion", "creating Shed_Motion_01 timer: " + timeOut + " sec")
                Shed_Motion_01_Timer = createTimer( now.plusSeconds(timeOut) )
                    [
                        logInfo("Motion", "timer Shed_Motion_01 expired, switching off ")
                        sendCommand(Camera_03,OFF)
                        Shed_Motion_01_Timer=null
                    ]
                sendCommand(Camera_03, ON)
                }
            else
                {
                logInfo("Motion", "rescheduling Shed_Motion_01 timer:" + timeOut + " sec" )
                Shed_Motion_01_Timer.reschedule(now.plusSeconds(timeOut))
                }
            }
        }
    end

rule "Shed_Motion_03 Sensor Trip"
        when
        Item Shed_Motion_03 received update
        then
        {
        logInfo("Motion", "Shed_Motion_03 sensor changed state")
        if(Shed_Motion_03.state == OPEN)
            {
            if (Shed_Motion_03_Timer == null )
                {
                // create timer
                logInfo("Motion", "creating Shed_Motion_03 timer: " + timeOut + " sec")
                Shed_Motion_03_Timer = createTimer( now.plusSeconds(timeOut) )
                    [
                        logInfo("Motion", "timer Shed_Motion_03 expired, switching off ")
                        sendcommand(Camera_02, OFF)
                        sendcommand(Camera_01, OFF)
                        Shed_Motion_03_Timer=null
                    ]
                sendCommand(Camera_02, ON)
                sendCommand(Camera_01, ON)
                }
            else
                {
                logInfo("Motion", "rescheduling Shed_Motion_03 timer:" + timeOut + " sec" )
                Shed_Motion_03_Timer.reschedule(now.plusSeconds(timeOut))
                }
            }
        }
    end



><>
nathan stratton | vp technology | broadsoft, inc | +1-240-404-6580 | www.broadsoft.com

Reply all
Reply to author
Forward
0 new messages