Perimeter Detection Actions


I am trying find the Python API code for actions in case of Perimeter breaches. I see different codes in your community. Can you please tell me what is the difference between the code lines below?

1- what is the difference between
zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False)
zkSetPerimeterEventAction(ctx, 0, ZK_PERIMETER_EVENT_ACTION_NOTIFY)

2- What is the difference between
zkWaitForPerimeterEvent(ctx, 1000);

I need a piece of code that I can notify when a breach happens. Thank you!

For each question, each does the same thing, but for different languages: the first is Python and the second is C.

A simple example in Python for perimeter detection would be:

import zymkey

zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False)

while True:
      perim_status_str = ""
      idx = 0
      plst = zymkey.client.get_perimeter_detect_info()
      for p in plst:
         if p:
            perim_status_str += " perim%d timestamp = %d" % (plst.index(p), p)
      print("Perimeter event detected!" + perim_status_str)
   except zymkey.exceptions.ZymkeyTimeoutError:
      print("Nothing going on")

1 Like

Thanks for the response.

I have a few questions left:
1- I bought a microUSB extension cable and wire black is connected to white and yellow is connected green. I am using your code for detecting perimeter breaches when one of these loops breaks. Basically, when a wire gets detached from another. In this case where is the notification sent to? can we set it to send an email as a notification?

2- is Set_tap_sensitivity related to get_accelerometer_data ()? I don’t see much difference in the result when I set sensitivity to 100 or 0. Do you have a sample code for setting sensitivity and detecting accelerometer data? I use the code below:

zymkey.client.set_tap_sensitivity(‘all’, 1.0)

3- What is the string after “object at” in the result below?
Zymkey.module.Zymkey.ZymkeyAccelAxisData object at 0x750c30070?

I leave my raspberry pi on the ground without touching it and all these numbers in X, Y, Z keep changing. Aren’t they supposed to stay the same when Zymkey is stable and steady?
Is there a function to send notification when accelerometer data changes or a tap is detected?

4- Where should I tap on Zymkey? Does zymkey.client.get_accelerometer_data() show result of tapping too?

Any response to my questions? I have a hard time finding any examples or documentation about Accelerometer detection.

  1. As shown in the previous example, if you are configuring the perimeter detect channels in notify mode, you can detect when a perimeter breach has occurred. Your software can then send an email.
  2. By default, zymkey has the tap detection turned off (sensitivity=0). If you set it to 100, it will be very sensitive and at 50 it will be less sensitive. Your example is setting the sensitivity to 1, so the setting will not be sensitive (i.e. it will take a big shock to make the detection trip).
  3. The return values from zymkey.client.get_accelerometer_data() do not return simple integers, but structures. You will need to pull the values out of the structure. Here is an example which waits for a tap event for up to one second, then prints out the accelerometer data:
import zymkey
from datetime import date
from datetime import time
from datetime import datetime
import time

while True:
      print("Tap detected!")
   a = [ None ] * 3
   a[0], a[1], a[2] = zymkey.client.get_accelerometer_data()
   now =
   print("Raw accel data (%s %s):" % (, datetime.time(now)))
   clear = False
   for i in range(len(a)):
      print("   g = %f, td = %d" % (a[i].g_force, a[i].tap_dir))
  1. You can tap anywhere that will cause the sensor to trip. The above API shows the latched tap direction for the last tap event.

Hi Scott,

Thanks for the response. One more question, how do I translate the timestamps returned by get_perimeter_detect_info()?
when I run the code below:
plst = zymkey.client.get_perimeter_detect_info()
perim_status_str += " perim%d timestamp = %d" % (plst.index§, p)

I get perim[1] timestamp = 1587689951. What does this sting stand for? Is there a way to translate it to date and time?