Trigger notification as soon as alarm starts

Forum for questions and support relating to the 1.30.x releases only.
Locked
Dan12345
Posts: 6
Joined: Fri Sep 02, 2016 7:23 am

Trigger notification as soon as alarm starts

Post by Dan12345 »

Hi,

I'm trying to trigger a notification as soon as an alarm starts (i.e. immediately, and not once the event has finished).

So I set up a filter running in the background which has "monitor name equal to [name of monitor]". However this only fires when the event is finished. Is there a way I can trigger it immediately?

thanks,

Dan
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Trigger notification as soon as alarm starts

Post by asker »

Google for 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
Dan12345
Posts: 6
Joined: Fri Sep 02, 2016 7:23 am

Re: Trigger notification as soon as alarm starts

Post by Dan12345 »

brilliant - thank you!
Dan12345
Posts: 6
Joined: Fri Sep 02, 2016 7:23 am

Re: Trigger notification as soon as alarm starts

Post by Dan12345 »

On second thoughts - ouch - much too complicated for me. I just want to run a simple script when an alarm is received, and zmeventserver looks like overkill. Using swatch to monitor syslog seems a lot easier...
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Trigger notification as soon as alarm starts

Post by asker »

Sure. That seems reasonable for what you want too.
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
Dan12345
Posts: 6
Joined: Fri Sep 02, 2016 7:23 am

Re: Trigger notification as soon as alarm starts

Post by Dan12345 »

On third thoughts, even swatch is overkill - awk does the trick, run at reboot with cron:

tail -F /var/log/syslog | awk ‘/FireEscape.*alarm start/ { system("wget http://[openhab server]/CMD?CamFireEscape=ON -P /tmp") }'

(and that flicks a virtual switch in my openHAB setup to run notifications etc)
JTheDoc
Posts: 11
Joined: Sun Aug 28, 2016 8:08 pm

Re: Trigger notification as soon as alarm starts

Post by JTheDoc »

Hello Dan, you don't happen to know how to implement your method so I may run a simple .sh script? I'm attempting to have a PTZ camera look a certain direction when motion is detected on another camera.

The script I've got working perfectly fine, I believe putting the script in a folder that www-data has permissions for, and setting the .sh to executable should be enough, but I haven't been able to put this into practice, as filters don't work (Doesn't work, and would be too slow to respond), so having awk trail the logs for "alarm" should be enough for me. If you could help, I would be very grateful! Thank you, and I hope you've been getting along better with ZM much less awkwardly and stressful as I have!
Cheers,

Josh.
mangocats
Posts: 4
Joined: Sun Jul 26, 2020 1:13 pm

Re: Trigger notification as soon as alarm starts

Post by mangocats »

So, what I found that's pretty easy (IMO) is the docker container dlandon/Zoneminder - which comes with zmeventserver ready to turn on.

I used that, and wrote this script:

#!/bin/bash
# my_event_start.sh
# to be installed in dlandon/Zoneminder /var/lib/zmeventnotification/bin
# remember to chown www-data:www-data and chmod +x
# in ZM Options System OPT_USE_EVENTNOTIFICATION check and Save
# for urlencode
# sudo apt install gridsite-clients
#
# takes a zmeventnotification and relays it to my webserver

p1=$(urlencode "$1")
p2=$(urlencode "$2")
p3=$(urlencode "$3")
p4=$(urlencode "$4")
data="monitorID=$p2&cause=$p4&monitorName=$p3&event=$p1"

wget --method=POST http://192.168.1.2:34567/play?"${data}"

# tell zoneminder to not do anything else with this event
exit 1


The cause parameter has a value of "Motion zoneA,zoneB,zoneC" where the zones are the zones that the motion was detected in. If you don't have a webserver setup to handle POST requests, you can change the wget line to send $p4 to whatever you've got that will handle those events.

I hope this helps someone, took me long enough to untangle all the crazy complex options.

Now - what I'd really like are individual notifications as soon as motion is detected in the individual zones, instead of a single Event notification that gloms all the zones together, but other than scraping the tail of the log file, I haven't found anything for that, yet.
Locked