Difference between revisions of "ZMTrigger"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 24: Line 24:
  ss -ntulp
  ss -ntulp
Make sure no firewall is blocking it (port 6802).
Make sure no firewall is blocking it (port 6802).
iptables -L
or
nft list tables
nft list table <result of previous command>


==Usage==
==Usage==

Revision as of 14:39, 26 August 2024

/usr/bin/zmtrigger.pl (debian location) is an optional program for Zoneminder that listens on the network for commands. Read the perl script for more information. It is a telnet server.

It can be used in different ways.

1) it can be used is to overlay text information (e.g. temperature sensor) onto the video feed.

2) It can also be used as an external trigger / alarm source for cameras. By using an external alarm, you can avoid some of the problems inherent in ZM software modect - false alarms, and CPU usage. False alarms are commonly caused when the video feed has an ambient change come across it, e.g. weather events, wildlife, or the transition from daylight to night ir filter.

3) You can monitor which alarms are active or not at a given time. ZMTrigger reports when alarms are active, and when they are closed. This data can be queried by external programs.

Note that if you have a house, or single breaker, you might want to consider using X10 for Zoneminder. This will save you the need for ethernet wiring, or setting up wifi.

Configuration

Enable it first, by going into options, config, and checking Enable Triggers (OPT_TRIGGER).

Then restart ZM.

# /etc/init.d/zoneminder restart

Verify it is running with

ps auxw | grep zmtrigger
netstat -ntulp
or
ss -ntulp

Make sure no firewall is blocking it (port 6802).

iptables -L
or
nft list tables
nft list table <result of previous command>

Usage

Overlaying Text Data onto a Video Feed

After you have verified the script is running, test it is working.

Choose a monitor by monitor ID, say monitor 1, then add %Q to the monitors timestamp section.

The monitor must be in either modect, mocord, or nodect mode.

Open the video feed for monitor 1.

Then type in another terminal

telnet ipaddress 6802

in the telnet session type the following

1|show||||testingOSD

then press return.


Refer to Documentation for what this command means. A brief explanation for this is:

MonitorID # | Show text mode |||| text to put in.

You should immediately see testingOSD in place of the %Q you put in the timestamps section.

For more examples and scripts of ZMTrigger search the forums.

Note: You can also send this to telnet in a shell script via:

#!/bin/bash

# call script and pass monitor number
# e.g.
# "$ ./telnet_zmtrigger_test.sh 12"
# fields are:
# B<id>|B<action>|B<score>|B<cause>|B<text>|B<showtext>

IPADDRESSOFZMSRV=192.168.1.178

telnet $IPADDRESS 6802 <<EOF
$1|on+3|10|ZMTEST||
EOF

Example Setup

Here is a script that connects to an ipaddress which serves a sensor value. Wget is not as fast as possible, but this is simple and works quickly as a test.

#!/bin/bash
counter=1

while [$counter -le 10]
do
PRESSURE=`wget ipaddress -q -O -`
echo "1|show||||$PRESSURE" | telnet ipaddress 6802
sleep 4

#((counter++))
done

This text overlay can be used for any information, not just from the LAN. Maybe you want to overlay information from an online database or website.

Possible uses of text trigger

  • temperature
  • air pressure
  • humidity
  • sunset/sunrise time
  • which alarm activated
  • which person entered an electronically locked door
  • random quote / message
  • id of last camera alarm that went off on system
  • the name of the person buying something from the POS system
  • insert idea here

As an External Trigger

It is possible with minor effort, to communicate with ZMTrigger.pl at the Zoneminder Server IP Address, using a microcontroller and a device that does the actual triggering. Common options would be 8-bit microcontrollers such as the Arduino Uno, the ESP8266, or an ARM based SBC such as the Raspberry Pi, Beaglebone, and others.


Some benefits

  • Fully customizable
  • Less false positives
  • Less CPU usage
  • No zone configuration required


Some drawbacks

  • Some assembly required
  • Zone configuration isn't necessary, but you may have to install these, which is slow and requires fish tape, drywall saw, experience with installing an ethernet or electrical outlet, etc...

Types of Controllers

Uno
Arduino Uno DIP

This is up to you. If you have a wired ethernet connection available for the external sensor, then an Arduino Uno is a good choice. If you don't want to run ethernet, then an ESP8266 or Arduino w/wifi should do. An Arduino Uno will require a separate ethernet board. You can also connect an Arduino via USB, if the computer is within 15 feet.

Types of Sensors

You will need to decide which sensors to use. There are many options. This is what I've used.

PIR Sensors

PIR stands for Passive Infrared. These can be obtained from $4 and up online. Across auction sites from China for the cheapest, to hobbyist electronics stores for tested chinese products, and then for brand name sensors from electronics distributors like Digikey, Mouser, and Farnell. These sensors are useful, but have limitations.

  • Range is limited to 10-20 Feet. Sensitivity can be tuned.
  • Sunlight will cause false triggers. Direct OR indirect. Software or hardware may be able to mitigate this (TODO).
  • Works good in a hallway, or room where no outdoor sunlight will penetrate.

Overall, the PIR Sensors are good if you have the right environment. They are not feasible outside, but indoors, away from sunlight, they work well.

Microwave Sensors
HB100

Microwave sensors operate in the 5-24GHz radio bands. The 10 GHz sensors have a range of about 20-30 feet for a person, more for large vehicles (reflective metal objects). The 24GHz sensors have shorter range. There are a variety of these, from brand name, to cheap. The best sensor currently available at the lowest price is the HFS-DC06H.

  • Relatively short range for radio. Depends on RF frequency, but typically you get 5GHz = 10M, 10GHz = 5M, 24GHz = <3M
  • Some of these can interfere with each other (some do not, depends on model).
  • Detection of items depends on conductivity (large metal objects such as cars are detected from a larger distance than people. This is expected).
  • May work too well - Mice can set off alarms (not false, but essentially unwanted alarms)(sensitivity can usually be adjusted).

Why don't I make a radio sensor that goes longer than 10M?

It's been done. And if they are within the ISM bands they can be used without FCC testing and approval. More details here: make FMCW radars. Not easy but doable. The trick will be to make one that is practical enough but also not $100 each.

Ultrasonic Sensors

I do not use ultrasonic sensors, but maybe someone else has some experience they can chime in with here (no pun intended).

  • Uses high frequency sound, may disrupt animals.
Infrared Trip Sensors

It's easy to find infrared trip sensors (think a laser going from 10-50 feet across). These can be setup with a microcontroller, and if someone walks across the beam, you can activate the alarm. Some brands are Sick or Seco-larm Enforcer. If you need a real short IR (inches), off the shelf Arduino modules will work (ir photo beam detector). These can be purchased from distributors such as [1] and others online. Search the opto-electronics section (subject to change). Buy used if you are on a budget.

  • Requires a bit of installation, though works well, when installed.
  • Requires power at both ends of the laser.
  • More Immune to sun interference than PIR
  • One end must connect back to server somehow (ethernet/wifi/usb/X10)
  • Reasonably long distance. Some are up to 100M.
  • Possible to avoid if you step over them. Put these aiming at a device that moves such as a door or gate. You can also get larger sensors, which can be a 6-7 feet tall, and are used in elevators to detect people in the doorway (search "elevator door sensors").
  • These are all in the class of "photo electric sensors"
  • the single beam modules (that don't have a receiver) may require a reflective sticker (bike reflector) on the other side

An example sketch is included in the links at the bottom.

Inductive Sensors

There are products that, similar to capacitive sensors, (think a Theremin https://en.wikipedia.org/wiki/theremin) you can for example attach a wire to a doorknob (or any piece of metal), then when someone touches the other side of the doorknob, the alarm is set off. These can be purchased on eBay advertised as "120db Wireless Touch Sensor Security Alarm Loud Door Knob" or some variation thereof, with even a loud buzzer should room service try to enter your room (oops).

For security purposes, tracking contact on any piece of metal is easy.
Other Sensors

An infinite amount of devices could be used as triggers. House alarms use reed switches on windows and doors. If you have the capital, then there are many off the shelf products that can be purchased including expensive but powerful RF modect sensors.

Troubleshooting

tail -f  /var/log/zm/zmtrigger.log

Enable debug on it in the logs and set to 9. The logs that contain the /var/log/zm/ logs are the component logs in options.


MySQL server has gone away error

After following forum recommendations to use mysqltuner (see MySQL), mysqltuner told me to add wait_timeout=300 to my.cnf.

Unfortunately, ZMTrigger will disconnect every five minutes, if this is enabled. It appears that ZMTrigger will "Loading monitors" every five minutes, so you can't have a wait_timeout equal or lower than that. Otherwise the MySQL server will go away. If the wait timeout is higher, then ZMTrigger will "Loading monitors" without error.

This timeout error doesn't seem to adversely affect any other features of ZM so, a low wait_timeout may be acceptable if you don't use ZMTrigger.

The default wait timeout is 8 hours for MySQL. The solution seems to be add a wait_timeout >300, or use the default. Note that this might be fixed for ZM > 1.30.4 Reference:[2]

Notes

This means you could have multiple sensors, each triggering a different location. A reed switch on a window, a laser on a door, etc... When the alarm goes off, the video feed displays the alarm that was triggered.

See Also

  • Arduino Infrared Tripwire Sketch via ethernet: [3]
  • Arduino Sketch via USB [4]