Skip to content

Discriminate in Actions Script 'ON Motion' from 'On Triggered'

edited April 2020 in Home automation
Guarding a dwelling perimeter, I'm running motion detection on two cameras, one camera triggers the other on detected motion and vice versa. The camera that detects motion runs an Actions script to trigger Home Automation (using an XTension alarm Unit) that motion is detected and triggers via the camera setting its adjacent camera(s).

Unfortunately, the camera that is triggered by an other one's motion, also runs the same Actions script, as if it itself has detected motion. Therefore, two Home Automation alarm Units trigger and I'm not able to tell which camera was motion triggered.

(In XTension one can block unit ON scripts for a set amount of time. My first attempt was to let camera one ON script block camera two ON script for a while, as triggers during blockage are skipped, not delayed. Action reporting is so fast however that blocking occurs only áfter the second camera has triggered the second unit. Thus I can't prevent motion triggering being reported by both cameras.)

Complicating factor may be that the second camera is already triggered by the first camera and then itself detects motion. In that case, I like to signal that motion as motion detection (and extend the recording time of the first camera by triggering it).

How can I discriminate in an Actions Script the 'Trigged By Motion' from the 'Triggering By Other Camera'?

Comments

  • BenBen
    edited April 2020
    It is possible to determine the trigger reason within the triggered AppleScript, as described in the Preferences -> Cameras -> Actions section of the user manual:

    "Three parameters are passed to these scripts:

    The camera number
    The camera name
    The reason for the trigger, which is a comma-separated list of the following reasons: Motion,Audio,Script,CameraEvent,WebEvent,OtherCamera,Manual,Human,Vehicle"

    Here's how you would test for a certain trigger type in your script:

    on run args
        set reason to item 3 of args

        if reason contains "Motion" then
            --Do something for motion trigger
        else if reason contains "OtherCamera" then
            --Do something else for other cam trigger
        end if
    end run
  • Marvellous!
    It was the "on run args" construction that I was after, and how to fish the reasons from the pond of text.

    Just what the doctor ordered.

    Thanks Ben.
  • edited April 2020
    So I've been unsuccesfull so started running the following script, which upon detected motion creates a file on the desktop.

    on run args
    set reasonValue to 0
    set reason to item 3 of args
    set cmdstring to "echo " & reason & " > " & "/Users/me/Desktop/catcommand.txt"
    do shell script cmdstring
    end run

    The file is indeed created, but to my great surprise it contains this single line:

    Motion,Audio,Script,CameraEvent,WebEvent,OtherCamera,Manual,Human,Vehicle

    I don't see how that can be on a Motion Detection Actions ?

  • Sorry about this, it's a bug. It's fixed in the latest beta version of SecuritySpy (currently 5.2.3b4). Please confirm that it works as expected in the beta.
  • Thanks Ben, that seems to solve it. Now there are two nicely separated event series: one on Motion, the other on OtherCamera trigger.
  • @eljonco, would you mind sharing the code you use when running cmdstring please? I'm curious to see how you process the reason string. Thanks
  • @paul2020, it is as simple as Ben suggested above. After you have downloaded the version in which the bug is fixed, or the beta mentioned.
    if reason contains "Motion" then
    --Do something for motion trigger
    else if reason contains "OtherCamera" then
    --Do something else for other cam trigger
    end if
    Or do I misinterpret your question?
Sign In or Register to comment.