Skip to content

Commit

Permalink
Fix motion detection userscripts (EliasKotlyar#500)
Browse files Browse the repository at this point in the history
* Correct detection scripts so they can run multiple scripts

* Add some documentation around motion detection scripts
  • Loading branch information
Dopeyr authored and jmtatsch committed Jun 21, 2018
1 parent 7fd3049 commit 062860f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ After install, you can use this [android application](https://play.google.com/st

[Zoneminder](/integration/zoneminder/zoneminder.md)

## Other features

### Motion detection

It is possible to run your own scripts on motion detection. See [here](/integration/custom/motiondetection.md)

## Contributions:

Expand Down
8 changes: 4 additions & 4 deletions firmware_mod/scripts/detectionOff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ if [ "$publish_mqtt_message" = true ] ; then
fi

# Run any user scripts.
if [ -f /system/sdcard/config/userscripts/motiondetection/* ]; then
for i in /system/sdcard/config/userscripts/motiondetection/*; do
for i in /system/sdcard/config/userscripts/motiondetection/*; do
if [ -x $i ]; then
echo "Running: $i off"
$i off
done
fi
fi
done
8 changes: 4 additions & 4 deletions firmware_mod/scripts/detectionOn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ if [ "$sendemail" = true ] ; then
fi

# Run any user scripts.
if [ -f /system/sdcard/config/userscripts/motiondetection/* ]; then
for i in /system/sdcard/config/userscripts/motiondetection/*; do
for i in /system/sdcard/config/userscripts/motiondetection/*; do
if [ -x $i ]; then
echo "Running: $i on"
$i on
done
fi
fi
done
34 changes: 34 additions & 0 deletions integration/custom/motiondetection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Motion detection scripts

It is possible to run your own scripts on motion detection by adding your executable script (e.g. `.sh`)
to `config/userscripts/motiondetection`

When motion is detected, the first argument to the script will be `on` and when motion detection
ends it will receive `off`.

For example, to send an email containing snapshots on a certain condition, for example
only when the house is empty, you can check an external service (e.g. openhab)
before triggering the email.

-- sendEmail.sh --

```$sh
#!/bin/sh
if [ "$1" == "on" ]; then
source /system/sdcard/config/motion.conf
source /system/sdcard/scripts/common_functions.sh
# Check external service to see it anyone present.
presence=$(curl http://openhab/rest/items/PresenceAtHome/state 2>/dev/null)
if [ "$presence" == "OFF" ] ; then
# No-one is meant to be here, but motion detected. Send email.
/system/sdcard/scripts/sendPictureMail.sh &
fi
fi
```

The files should be copied manually, e.g. using ftp.

0 comments on commit 062860f

Please sign in to comment.