Page 1 of 1

Another Schedule Question

Posted: Tue Nov 14, 2017 2:06 pm
by lselinger
I've seen a few methods for scheduling however I haven't stumbled on a potential method for scheduling active/inactive zones. Bear with me lol I was just wondering if it would be possible to cron or create schedule that would activate or deactivate certain zones associated with a monitor. As an example I have the front of my house carved up in zones (Yard, Street, Tree, etc) I have 2 deactivated zones for trees that move a lot and 3 active zones I want to independently maintain for different reasons, mostly tuning the zones for proper movement etc.

One of my zones in the front is right in the light path for some decoration lights and it is on a timer. What I'd like to do is have this zone deactivate a few minutes before the lights turn on so I don't get false positives while the lights are on and moving, and then re-activate the zone when the lights shut off.

Is there any mechanism in place that can do this or are there any plans to build a scheduling mechanism into ZM? I know I can write one/a wrapper in either PHP or Perl and just issue MySQL commands to alter the state and have it kicked off by a cron job:

Code: Select all

UPDATE Zones SET Type='Inactive' WHERE Name LIKE '%Yard%';
...or whatever. I just figured if there's something already written or incorporated I'll use what's baked in rather than maintaining a side chink of code lol :D


Re: Another Schedule Question

Posted: Sat Nov 18, 2017 10:35 pm
by lselinger
So ... I'm going to go with "no"? lol ... I guess I'll write something when I have some free cycles :D (shameless bump)

Re: Another Schedule Question

Posted: Sat Nov 18, 2017 11:46 pm
by montagdude
Depending on how many different permutations of zones you want to have, you could just duplicate the monitor but set the zones differently. Then use run states to enable/disable them at different times of the day. This is what I'm doing with one of mine to change motion detection sensitivity for day and night.

Re: Another Schedule Question

Posted: Mon Nov 20, 2017 8:03 pm
by lselinger
This isn't a horrible idea except for the number of zones I have on the monitor lol ... I did test (just in case) to see if the run state maintains any of the deeper config options associated with the zones however it does not :( I could have created a new state and just deactivated that zone and reactivated once the lights shut off.

Either way thanks for the suggestion. For now I'm going to write a small script that just disables and enables that zone when needed and keep the monitor as is.

Re: Another Schedule Question

Posted: Thu Nov 23, 2017 8:15 am
by kennbr34
I'd be curious to see what you come up with. I use ZoneMinder with one single monitor that is a 4 channel DVR so everything I do is by zone only and not by monitor. Would really help me out to do something similar.

Re: Another Schedule Question

Posted: Fri Nov 24, 2017 2:07 pm
by lselinger
EDIT: fixed a typo lol

I'll eventually write a full blown wrapper/script ... for now I'm calling this from cron to disable the zone at 6:00 PM and enable it again at 9:00. It currently only takes 1 argument that is either 'active' or 'inactive' but I'll eventually use options so you can pass more variables without hard coding. I'm sure there's a way cleaner way to slap this together :P

Code: Select all


use strict;
use warnings;
use DBI;
use Getopt::Long;
use Data::Dumper;

my $dsn = "DBI:mysql:zm";

# Set your own user name and password to your DB. 
# Also keep this in a locked down place wih limited access and chmod 700
my $username = 'CHANGEME';
my $password = 'CHANGEME';
my $type = undef; 

# Change this to your zone name. Check your DB for what zones you have
# defined. Eventually I'll make this more granular. I didn't use the 
# full name either I just used wild cards, put your value between the %'s
my $zone = "%CHANGEME%";

my $state = $ARGV[0];

if (!$state) {
        printf "Need an option: [active/inactive]\n";

if ($state eq 'inactive') { 
        $type = 'Inactive';
} else {
        if ($state eq 'active') {
                $type = 'Active';

my $dbh  = DBI->connect($dsn,$username,$password);
print "Changing $zone to $state\n";

my $sth = $dbh->prepare("UPDATE Zones SET Type='$type' WHERE Name LIKE '$zone'");


I'm assuming familiarity with cron whoever for posterity:

Code: Select all

59 17 * * * /PATH/TO/ inactive 2>&1
01 21 * * * /PATH/TO/ active 2>&1
So I deactivate the zone 1 minute before my lights turn on, and then activate it one minute after they shut off.

Re: Another Schedule Question

Posted: Tue Nov 28, 2017 6:58 pm
by lselinger
If there's any interest, I revamped my code a little and posted the new version HERE

Re: Another Schedule Question

Posted: Wed Nov 29, 2017 9:37 pm
by rockedge
could one do this with the API by changing Zone[Type]=Active to a non-active state? This is an interesting function with the script you wrote and it made me wonder if it was possible as well.

from the docs... ... ate-a-zone
Create a Zone

Code: Select all

curl -XPOST http://server/zm/api/zones.json -d "Zone[Name]=Jason-Newsted \
&Zone[MonitorId]=3 \
&Zone[Type]=Active \
&Zone[Units]=Percent \
&Zone[NumCoords]=4 \
&Zone[Coords]=0,0 639,0 639,479 0,479 \
&Zone[AlarmRGB]=16711680 \
&Zone[CheckMethod]=Blobs \
&Zone[MinPixelThreshold]=25 \
&Zone[MaxPixelThreshold]= \
&Zone[MinAlarmPixels]=9216 \
&Zone[MaxAlarmPixels]= \
&Zone[FilterX]=3 \
&Zone[FilterY]=3 \
&Zone[MinFilterPixels]=9216 \
&Zone[MaxFilterPixels]=230400 \
&Zone[MinBlobPixels]=6144 \
&Zone[MaxBlobPixels]= \
&Zone[MinBlobs]=1 \
&Zone[MaxBlobs]= \

Re: Another Schedule Question

Posted: Wed Dec 13, 2017 6:09 pm
by lselinger
Now you've got me thinking lol ... as long as changing it non active doesn't alter the existing other attributes I think this would also be a possibility. I noticed when I did it from the web gui it would alter (from cache or default maybe?) some of the other settings. Potentially using the API may be a cleaner method.