Different zone settings for day and night?

Support and queries relating to all previous versions of ZoneMinder
Locked
btrotter
Posts: 57
Joined: Tue Jan 15, 2008 3:31 pm

Different zone settings for day and night?

Post by btrotter »

I see people mentioning using different Zone settings for day and night. I have dug through the settings, and cant figure out how they are doing it.
I have to set my cameras to be ultra-sensitive at night, mainly because they are cheap $50 cameras, and dont capture much otherwise. However, in the day, those same settings will capture even the slightest shift in a shadow.

How can I go about setting Zones with day/night values?

Thank you!
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

btrotter
Posts: 57
Joined: Tue Jan 15, 2008 3:31 pm

Post by btrotter »

Lee Sharp wrote:Hmm.... Where did you look? :wink:

http://www.zoneminder.com/wiki/index.ph ... or_week.3F
Obviously I didnt look there ;)

Thank you!
timcraig
Posts: 195
Joined: Mon Dec 10, 2007 5:53 pm
Location: San Jose, CA

Post by timcraig »

There is a way to change monitor states (record, monitor, modect, mocord) to at different times of the day. (http://www.zoneminder.com/wiki/index.ph ... or_week.3F)

However, there are no ways to make zone settings change at different times of the day. Phil mentioned he has a Zone Set feature that could do this in one of his source branches that he just needs to merge it back in to the trunk. I haven't seen this feature yet. Phil's probably busy working on MPEG4 capturing and vfl2 features.
Mopar93
Posts: 5
Joined: Thu Feb 12, 2009 9:36 pm

Post by Mopar93 »

I'm running on a Debian system using 1.23.3. Some of what I say here might be slightly different for your system, but here's how I accomplished having different zone settings for daytime and nighttime:

First I set up the run state I wanted for daytime and clicked on "Running" at the top of the zoneminder console. I entered "day" in the text box, clicked outside of the box to activate the "Save" button and then clicked on Save.

I repeated the above for my nighttime run state and called it "night".

Next I reloaded the "day" run state and set up the zones the way I wanted them for daytime. I then opened up a shell and logged in as root.

I manually entered the following commands:

zmpkg.pl stop
/etc/init.d/mysql stop

Those two commands stopped zoneminder and the mysql database server. Next I went into the mysql directory for zoneminder and copied the current zone settings.

cd /var/lib/mysql/zm
cp Zones.MYD Zones.MYD.day
cp Zones.MYI Zones.MYI.day

Next, make sure the new files have the correct owner and permissions:

chown mysql:mysql Zones.MYD.day
chown mysql:mysql Zones.MYI.day
chmod 660 Zones.MYD.day
chmod 660 Zones.MYI.day

Then I got the database and zoneminder running again with the nighttime run state:

/etc/init.d/mysql start
zmpkg.pl night

I then set up the zones how I wanted them for night time and then repeated the process again from the shell as root:

zmpkg.pl stop
/etc/init.d/mysql stop
cd /var/lib/mysql/zm
cp Zones.MYD Zones.MYD.night
cp Zones.MYI Zones.MYI.night
chown mysql:mysql Zones.MYD.night
chown mysql:mysql Zones.MYI.night
chmod 660 Zones.MYD.night
chmod 660 Zones.MYI.night

It's OK to restart the database and zoneminder now:

/etc/init.d/mysql start
zmpkg.pl night

Next, I made sure I was in the root directory where I will create two scripts:

cd /root

Here's how one script will look and I saved it with the name "zm-day":

#!/bin/bash
zmpkg.pl stop > /dev/null
/etc/init.d/mysql stop > /dev/null
cp /var/lib/mysql/zm/Zones.MYD.day /var/lib/mysql/zm/Zones.MYD
cp /var/lib/mysql/zm/Zones.MYI.day /var/lib/mysql/zm/Zones.MYI
/etc/init.d/mysql start > /dev/null
zmpkg.pl day > /dev/null

And here's the other script which I named "zm-night":

#!/bin/bash
zmpkg.pl stop > /dev/null
/etc/init.d/mysql stop > /dev/null
cp /var/lib/mysql/zm/Zones.MYD.night /var/lib/mysql/zm/Zones.MYD
cp /var/lib/mysql/zm/Zones.MYI.night /var/lib/mysql/zm/Zones.MYI
/etc/init.d/mysql start > /dev/null
zmpkg.pl night > /dev/null

Be sure to make these two scripts executable:

chmod 755 zm-day
chmod 755 zm-night

I can manually switch the runstate and the zone settings by running either script. However, it's much better to do it at automatically at dawn and dusk, so I set up a crontab for this. Enter the following command:

crontab -e

This brings up an editor and you can put the following two lines into it and then save and exit:

50 7 * * * /root/zm-day
15 18 * * * /root/zm-night

The first line will switch to the daytime settings at 7:50AM and the second line performs the switch to nighttime settings at 6:50PM. Maybe once a week, I will rerun "crontab -e" to adjust the times to compensate for when the sun rises and sets.

-Maurice
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

I has been using different setting for day and night for about a year now on zm 1.23 and older. During the night i set lower resolution on the cameras, black and white and modetect to all of them. On zones, i might change the zone on a camera that is exposed to lights that might set false alarms like light reflecting form a mirror and thinks like that.
The important thing is that Zones and Monitors table has to be saved at the same time for day and night.

Warning: I am not responsable for any damage to your system. I will explain what i do and how i do it so you can use this information to do a more elaborated and safer script. I am not a programmer and this scripts where made by copying from different sources. In fact, i do not undestand some of the command i used on this scripts. But after some trial and error, they work for me.

I added a directory called scripts under /var/www/html/zm/ and there i keep the scripts and the data from the database i copied for day and night state.

This is the script called savemon that saves both tables (Monitors and Zones)

Script -------savemon ----------
#!/bin/sh
echo "1Nombre $1"
if [ "$1" != "" ] ; then
mysqldump -h localhost -u root -p --tab=. zm Monitors
rm -f /var/www/html/zm/scripts/$1.Monitors
cp /var/www/html/zm/scripts/Monitors.txt /var/www/html/zm/scripts/$1.Monitors
rm -f /var/www/html/zm/scripts/Monitors.txt
rm -f /var/www/html/zm/scripts/Monitors.sql

mysqldump -h localhost -u root -p --tab=. zm Zones
rm -f /var/www/html/zm/scripts/$1.Zones
cp /var/www/html/zm/scripts/Zones.txt /var/www/html/zm/scripts/$1.Zones
rm -f /var/www/html/zm/scripts/Zones.txt
rm -f /var/www/html/zm/scripts/Zones.sql

else echo "Omitio el nombre del archivo al cual se debe copiar la informacion"
fi
------------------------------------------------------------
First i set the zm (Monitors and Zones) the way i want it to be during day time.
I run savemon on a console as root but first i cd /var/www/html/zm/scripts and the type for example ". savemon day". My database has user root and no password. So when a password is asked i simply hit enter.

Now i go back to zm and set it the way i want it to be at night time.
Run now ". savemon night".

To change from day to night i have a second script i called "change_state"
Script------ Change_state----------
#!/bin/sh
echo "1Nombre $1"
if [ -f "/var/www/html/zm/scripts/"$1.Monitors ]; then
/usr/lib/zm/bin/zmpkg.pl stop
sleep 3
rm -f /var/www/html/zm/scripts/Monitors
cp /var/www/html/zm/scripts/$1.Monitors /var/www/html/zm/scripts/Monitors
mysqlimport --replace --local zm "/var/www/html/zm/scripts/Monitors"
sleep 3
rm -f /var/www/html/zm/scripts/Zones
cp /var/www/html/zm/scripts/$1.Zones /var/www/html/zm/scripts/Zones
mysqlimport --replace --local zm "/var/www/html/zm/scripts/Zones"
sleep 3
/usr/lib/zm/bin/zmpkg.pl start
fi

-------------------------------------------------------------------
I use this script on the command line as root but mostly on a cron statement.
To change to night settings i would type as root on a console ". change_state night" and the already saved setting for night state would be used.

or ". change_state day" to use the setting for day time.

Remmenber, always as root and always cd to /var/www/html/zm/scripts
first.
Monitos and Zones tables are tightly related so i learned that is safer to save both tables even if the zones are the same during day and nigth states. I learned this the hard way because i had corrupt database once and had to reinstall Zoneminder.

Hope this will help someone and would appreciate any comment on how to make this script better
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Post by Paranoid »

Duplicate each of your zones and have one set named Day-XXX and the other named Night-XXX each with whatever sensitivity setting you want.
When you want to switch to day mode use a script to:

1. Update all "Day-" Zones to active in the database
2. Update all "Night-" Zones to inactive in the database.
3, Restart zoneminder.

Do the opposite for nighttime

Works for me.
Mopar93
Posts: 5
Joined: Thu Feb 12, 2009 9:36 pm

Post by Mopar93 »

Of course, now, here is the simplest method of all...

For any camera that you want multiple settings for such as daytime and nighttime, just create another monitor for that camera.

First, click on the function column of the desired camera monitor, and select "none" and check the disable box. This turns the monitor off.

Now go and set up another monitor for that camera and get it configured how you want it for the other mode that you would like. Let's say you are setting it up for nighttime now.

At this point, you have two monitors for the same camera, except one is disabled and one is working. Click on "Running" and give this run state a name such as "night".

Now, disable this newly created monitor and re-enable the other one. Make sure this monitor is set up for your daytime settings and then click "Running" and give this run state a name such as "day".

Now, you can simply switch between run states to change the settings for night and day. No need to fool around with the database.

A separate script isn't needed for this method either since it's a one line command to switch run states. Just set up your cron tab to call zmpkg.pl to switch run states at the desired times.

Another advantage to this is any events that are captured are stored separately for daytime and nighttime.

-Maurice
gola10
Posts: 150
Joined: Wed Nov 01, 2006 3:16 pm
Location: Panama

Post by gola10 »

Mopar93:
This idea of using different monitors look interesting. I will give it a try.
Mopar93
Posts: 5
Joined: Thu Feb 12, 2009 9:36 pm

Post by Mopar93 »

I tried my latest idea of creating extra monitors and found that I had to add some additional lines in the crontab to automate this.

I found out that the run state doesn't save the enable/disable flag. So, I used zmu to enable and disable the monitors. Here's the complete crontab entries for use with one camera being switched between two monitors:

50 7 * * * /usr/bin/zmu -m 2 -D -Uusername -Ppassword
50 7 * * * /root/zm-day
50 7 * * * /usr/bin/zmu -m 1 -E -Uusername -Ppassword
15 18 * * * /usr/bin/zmu -m 1 -D -Uusername -Ppassword
15 18 * * * /root/zm-night
15 18 * * * /usr/bin/zmu -m 2 -E -Uusername -Ppassword

An explanation:

Lines 1-3 are run at 7:50AM everyday. Lines 4-6 are run at 6:10PM everyday. Replace "username" and "password" with the correct values. If you aren't using authentication, then you can omit the -U and -P commands and also omit the username and password.

At 7:50AM, Line 1 will disable monitor #2. Line 2 will switch to the daytime run state which switches from monitor #2 to monitor #1. Then Line 3 will enable monitor #1.

At 6:10PM, Line 4 will disable monitor #1. Line 5 will switch to the nighttime run state which switches from monitor #1 to monitor #2. Then Line 3 will enable monitor #2.

Of course, you would insert the correct monitor numbers as needed. Also, if there is more than one camera involved, just add more lines to enable and disable the appropriate monitors.

-Maurice
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Post by Paranoid »

Mopar93,

There is no guarantee that your crontab entries will run in the order you have entered them in the crontab file. This means that the " /usr/bin/zmu -m 1 -E" entry might run before the "/usr/bin/zmu -m 1 -D" command and result in your monitor being disabled. You need to either encapsulate all 3 command in a single script or have them run at different times.

[edit]
Next time I'll read your post properly. You are disabling a different monitor than you are enabling so running order doesn't matter.
Last edited by Paranoid on Sat Feb 14, 2009 2:22 pm, edited 1 time in total.
Paranoid
Posts: 129
Joined: Thu Feb 05, 2009 10:40 pm

Post by Paranoid »

Assuming all your zones are duplicated with one set called "Day-XXX" and the other set called "Night-XXX", here's a little perl script I've written that will switch one set of zones off and the other set on via a crontab.

To switch from Day to Night on monitor 4 run:

./zm-modeswitch 4 Day Night

To switch from Night to Day on monitor 4 run:

./zm-modeswitch 4 Night Day

ZoneMinder is never enabled/disabled/stopped/started so there shouldn't be any interuption to any monitors.

There is nothing especially perl'ish in the script so converting to a shell script shouldn't be difficult.

Code: Select all

#!/usr/bin/perl -w
#
# This takes 3 arguments:
#    Monitor Id
#    Deactivate pattern
#    Activate pattern
#
# Any Zones that begin with the "Deactivate pattern" will
# be set to "Inactive" and any that begin with the "Activate
# pattern" will be set to Active. So if you have a set of
# nighttime zones called "Night-NW", "Night-N", "Night-NE"
# etc and daytime zones called "Day-NW", "Day-N", "Day-NE"
# etc on monitor "3" then the following command will disable
# the "Night" zones and enable the "Day" zones.
#
# ./zm-modeswitch 3 Night Day
#
#
use DBI;

$DBschema   = "zm";             # The ZoneMinder Schema
$DBuser     = "zm_admin";       # Database user
$DBpassword = "XXXXXX";         # Database password
$DBhostname = "localhost";      # Location of database
$ZMuser     = "admin";          # ZoneMinder user
$ZMpassword = "XXXXXX";         # ZoneMinder Password
$zmu        = "/usr/bin/zmu";   # Location of zmu app.

#
# Connect to the database
#
$dbh = DBI->connect("DBI:mysql:database=$DBschema;host=$DBhostname",$DBuser,$DBpassword)
       or die "Unable to connect to database $DBschema on $DBhostname";

#
# Get the arguments
#
if( @ARGV == 3 ) {
    $monitor   = shift @ARGV;
    $dectivate = shift @ARGV;
    $activate  = shift @ARGV;
} else {
    print("Invalid Arguments\n");
    exit(1);
}
$SQLmodeswitch = $dbh->prepare(q{
  update Zones set Type = ? where MonitorId = ? and Name like concat(?,"%")
});

$SQLmodeswitch->execute("Inactive",$monitor,$dectivate);
$SQLmodeswitch->execute("Active",$monitor,$activate);

system("$zmu -m $monitor -U $ZMuser -P $ZMpassword -L");

btrotter
Posts: 57
Joined: Tue Jan 15, 2008 3:31 pm

Post by btrotter »

Does this work in Ubuntu 10.04 LTS server?

I set all the settings on my cameras to a "nighttime" setting, then went and saved the Run State as "Night"
I then went back and changed all the settings back to a "daytime" setting and saved the Run State as "Day".

If I go to the run state and select either Day or Night setting, it never changes the values of the cameras.
btrotter
Posts: 57
Joined: Tue Jan 15, 2008 3:31 pm

Post by btrotter »

I just realized this was in the 1.23 forum. I am using 1.24.2. I will repost this to that forum.
SpikeyGG
Posts: 60
Joined: Mon Oct 15, 2012 12:02 am

Re:

Post by SpikeyGG »

Paranoid wrote:Assuming all your zones are duplicated with one set called "Day-XXX" and the other set called "Night-XXX", here's a little perl script I've written that will switch one set of zones off and the other set on via a crontab.

To switch from Day to Night on monitor 4 run:

./zm-modeswitch 4 Day Night

To switch from Night to Day on monitor 4 run:

./zm-modeswitch 4 Night Day

ZoneMinder is never enabled/disabled/stopped/started so there shouldn't be any interuption to any monitors.

There is nothing especially perl'ish in the script so converting to a shell script shouldn't be difficult.

Code: Select all

#!/usr/bin/perl -w
#
# This takes 3 arguments:
#    Monitor Id
#    Deactivate pattern
#    Activate pattern
#
# Any Zones that begin with the "Deactivate pattern" will
# be set to "Inactive" and any that begin with the "Activate
# pattern" will be set to Active. So if you have a set of
# nighttime zones called "Night-NW", "Night-N", "Night-NE"
# etc and daytime zones called "Day-NW", "Day-N", "Day-NE"
# etc on monitor "3" then the following command will disable
# the "Night" zones and enable the "Day" zones.
#
# ./zm-modeswitch 3 Night Day
#
#
use DBI;

$DBschema   = "zm";             # The ZoneMinder Schema
$DBuser     = "zm_admin";       # Database user
$DBpassword = "XXXXXX";         # Database password
$DBhostname = "localhost";      # Location of database
$ZMuser     = "admin";          # ZoneMinder user
$ZMpassword = "XXXXXX";         # ZoneMinder Password
$zmu        = "/usr/bin/zmu";   # Location of zmu app.

#
# Connect to the database
#
$dbh = DBI->connect("DBI:mysql:database=$DBschema;host=$DBhostname",$DBuser,$DBpassword)
       or die "Unable to connect to database $DBschema on $DBhostname";

#
# Get the arguments
#
if( @ARGV == 3 ) {
    $monitor   = shift @ARGV;
    $dectivate = shift @ARGV;
    $activate  = shift @ARGV;
} else {
    print("Invalid Arguments\n");
    exit(1);
}
$SQLmodeswitch = $dbh->prepare(q{
  update Zones set Type = ? where MonitorId = ? and Name like concat(?,"%")
});

$SQLmodeswitch->execute("Inactive",$monitor,$dectivate);
$SQLmodeswitch->execute("Active",$monitor,$activate);

system("$zmu -m $monitor -U $ZMuser -P $ZMpassword -L");

Paranoid, I just want to say THANK YOU for this script. It is EXACTLY what I was looking for. I was using a zmpkg.pl script to stop and start the camera I have but then I have no surveillance active during that time. With this script I can just narrow my alarm field so it doesn't trigger unnecessarily and still maintain some security. :)
Locked