Can someone post a good ZM-script example?

Forum for questions and support relating to the 1.29.x releases only.
Locked
flyvert
Posts: 19
Joined: Tue Mar 15, 2016 11:21 am

Can someone post a good ZM-script example?

Post by flyvert »

The script on the wiki FAQ (http://zoneminder.readthedocs.org/en/la ... s-an-alarm) leaves room for a number of improvements.

- Polling every monitor every second is not very elegant.
- Same alarm will give continuous triggering until idle.
- Current example seem platform specific (it won't run on Debian Jessie until some changes are made. Once worked around, there are further warnings about uninitialized variables in some internal function: "Use of uninitialized value $last_event_id in numeric ne (!=) at /usr/share/perl5/ZoneMinder/Memory.pm line 610.")


I would like to see a script example where:

- Some resource lean callback, WaitForAlarm(), etc function is made available.
- One callback, triggering, etc instead of continuous (I believe many would prefer a single callback per alarm to fire a custom script, etc.)


Have someone made this on his/her own and is willing to share some code, etc?
rockedge
Posts: 1198
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA

Re: Can someone post a good ZM-script example?

Post by rockedge »

Here is a script that monitors events via zmTrigger.pl This is modified to run some tests but it works and perhaps will inspire a direction to go to find what you seek.

Code: Select all

#!/bin/bash
#
# Turn lights on when ZM starts recording an event and turn off when ZM stops.
# Or do whatever such as trigger sirens, blink lights, text-to-speech, etc.
#
# Monitor output from zmtrigger.pl. When ZM starts recording an event
# zmtrigger.pl outputs a line like this where the first parameter is the
# camera number.
# 2|on|1300323788|298
#
# When ZM stops recording an event zmtrigger.pl outputs a line like this.
# 2|off|1300323801|298
#
# The following table shows the 5 sample ZM cameras and corresponding 
# X10 commands to control lights. mochad is used in this example to turn 
# lights on/off but heyu or br or any other command line program.
#
# Location Cam  Command
# Garage    1   pl b2
# Kitchen   2   pl b1
# Test      3
# Living    4   pl b1
# Front Dr  5   pl b1
# 
LIGHT[1]="pl A1"
LIGHT[2]="pl b1"
LIGHT[3]="pl b1"
LIGHT[4]="pl b1"
LIGHT[5]="pl b1"
LIGHT[6]="pl A6 "

# mochad listens on this host and port
#MOCHADHOST=192.168.1.254
#MOCHADPORT=1099

# zmtrigger.pl listens on this host and port
ZMHOST=192.168.0.9
#ZMHOST=localhost
ZMPORT=6802
CURL='/usr/bin/curl'
#RVMHTTP="http://localhost:8008/?house=A&unit=1&command=ON"
#OFFHTTP="http://localhost:8008/?house=A&unit=1&command=OFF"
RVMHTTP="http://192.168.0.9:8008/?house=A&unit=1&command=ON"
OFFHTTP="http://192.168.0.9:8008/?house=A&unit=1&command=OFF"
CURLARGS="-f -s -S -k"
# Connect TCP socket to ZoneMinder zmtrigger.pl
exec 6<>/dev/tcp/${ZMHOST}/${ZMPORT}

# Read ZM events from zmtrigger.pl
while read <&6
do
    # Show the line on standard output just for debugging.
    echo "${REPLY}" >&1
    case "${REPLY}" in
        *\|on\|*)
            CAM=${REPLY%%|*}        # extract camera number
            cmd=${LIGHT[${CAM}]}    # get the X10 command
            if [ "x${cmd}" != "x" ]
            then
#               echo "${cmd} on" >/dev/tcp/${MOCHADHOST}/${MOCHADPORT}
                echo "${cmd} on"
                raw="$($CURL $CURLARGS $RVMHTTP)"
                echo $raw
            fi
            ;;
        *\|off\|*)
            CAM=${REPLY%%|*}        # extract camera number
            cmd=${LIGHT[${CAM}]}    # get the X10 command
            if [ "x${cmd}" != "x" ]
            then
#                echo "${cmd} off" >/dev/tcp/${MOCHADHOST}/${MOCHADPORT}
                 echo "${cmd} off" 
                 raw="$($CURL $CURLARGS $RVMHTTP)"
                 echo $raw
            fi
            ;;
    esac
done
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Can someone post a good ZM-script example?

Post by asker »

If you are looking at doing something with events, also take a look at the event server - it taps into shared memory to report events, so it notifies as soon as the event occurs (nearly) https://github.com/pliablepixels/zmeventserver
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
flyvert
Posts: 19
Joined: Tue Mar 15, 2016 11:21 am

Re: Can someone post a good ZM-script example?

Post by flyvert »

rockedge wrote:Here is a script that monitors events via zmTrigger.pl This is modified to run some tests but it works and perhaps will inspire a direction to go to find what you seek.
Thanks. Exactly what I was asking for! :D
flyvert
Posts: 19
Joined: Tue Mar 15, 2016 11:21 am

Re: Can someone post a good ZM-script example?

Post by flyvert »

asker wrote:If you are looking at doing something with events, also take a look at the event server - it taps into shared memory to report events, so it notifies as soon as the event occurs (nearly) https://github.com/pliablepixels/zmeventserver
Thanks for the hint - will have a go at this at earliest opportunity.
Locked