Action When Trigger Stops
Hey there,
I'm using a Hubitat hub to control various bits of home automation equipment and it has a "Maker API" which allows devices to be controlled via simple HTTP requests. I can see that SecuritySpy would be able to interact with the hub using AppleScript to call curl and there are some very useful example scripts in there for relays. Excellent!
However, one issue I can't seem to overcome is what happens when a motion trigger ceases. The use case is simple; when motion is detected on a camera, fire out a HTTP request to turn on a light. When motion ceases, wait a few minutes, then turn the light off. I can get close by using a single script to fire out the ON command, sit in a delay for a 180 seconds and then fire the OFF command. However, this ALWAYS turns off the light after 180 seconds, regardless of whether motion is continuing.
What would be great is a means to turn ON the light when there's a trigger, then to reset a 180 second counter every time that trigger occurs. This way multiple triggers don't lead to multiple HTTP requests and multiple delay instances, all counting down their 180 seconds to fire out their OFF requests. Once motion has stopped there are no more counter resets, so it counts down to 0 and then fires a single OFF request.
Is there a cool function of SecuritySpy I'm missing here that would help, or should I investigate handling this purely through scripting? It feels like a potential feature if it's not already there... ;)
Cheers!
Comments
-
oooo
-
Hello, resurrecting this old thread. I’m curious about this same scenario and am wondering if there are any new developments. I looked through the manual again and didn’t see anything that might apply. Thanks.
-
Sorry that this original post never got a reply! There's not a perfect built-in way to do this, however if you have Motion Capture recording happening in parallel with Actions, then you can piggy back on this to achieve the functionality you want. The key is that SecuritySpy has a function whereby it can call a specific AppleScript whenever a movie file is completed. In this script, if you check against the camera number, and verify that it's a motion-capture file, then you know that motion has finished for the particular event in question.
What you need to do is create a script using Script Editor and save it with the name "ProcessCapturedFile" in the ~/SecuritySpy folder (i.e. the SecuritySpy folder within your Home folder). It must have the file extension ".scpt" (this is added by Script Editor by default).
If this script exists, SecuritySpy will invoke it whenever a captured file has finished, and will pass in the camera number, camera name, and file path as parameters. Here's an example script that demonstrates how to get these parameters:
on run args set cameraNum to item 1 of args set cameraName to item 2 of args set filePath to item 3 of args end run
If you turn your light on in the script that is invoked as an Action, and then turn it off in the ProcessCapturedFile script, you will get the behaviour you want. But again, this requires that Motion Capture is enabled, and runs at the same time (i.e. with the same schedule) as Actions.
