Last active
December 1, 2022 04:51
-
-
Save Ultrabenosaurus/5916101463f5d00732f901e7a3d8a2c2 to your computer and use it in GitHub Desktop.
A script to trigger IFTTT webhook applets from MotionEye software
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# | |
# MotionEye-IFTTT-Webhook.sh | |
# A script to trigger IFTTT webhook applets from MotionEye software | |
# | |
# author: Ultrabenosaurus | |
# license: BSD 3-Clause | |
# source: https://gist.github.com/Ultrabenosaurus/5916101463f5d00732f901e7a3d8a2c2 | |
# usage: sh /path/to/MotionEye-IFTTT-Webhook.sh Cam1 notify | |
# | |
# Don't forget to actually create a webhook applet for each event you want to trigger! | |
# https://ifttt.com/maker_webhooks | |
# | |
## | |
## Go to https://ifttt.com/maker_webhooks/settings for your key | |
IFTTT_KEY='KEY' | |
## Set port number here if the same for all cameras, otherwise do it in each case below | |
PORT='PORT' | |
ADDR="$(curl -4 icanhazip.com)" | |
#ADDR='my.ddns.com' | |
## Set whether to use HTTP or HTTPS for your camera feed | |
SSL='http' | |
## These are to be set in each case, to allow for hardcoding | |
URL= | |
TITLE= | |
## Add cases for each of your cameras | |
case $1 in | |
"Cam1") | |
URL="$SSL"'://'"$ADDR"':'"$PORT"'/' | |
TITLE="Cam1 - Camera Location" | |
;; | |
esac | |
## Set this in each case as below, leave blank here | |
EVENT= | |
## | |
# Create your cases as required. | |
# | |
# These will be used when calling the script, so it knows what to do, and correspond to "Event Name" parameter in the IFTTT webhook applet settings. | |
# | |
# The defaults are: | |
# notify - trigger motion_detected event, for push notifications | |
# start - trigger motion_start event, for toggling backlight intensity on Pi touchscreen and logging to Google Sheets | |
# stop - trigger motion_end event, for toggling backlight intensity on Pi touchscreen and logging to Google Sheets | |
## | |
case $2 in | |
"notify") | |
EVENT="motion_detected" | |
;; | |
"start") | |
EVENT="motion_start" | |
sudo rpi-backlight -b 65 | |
;; | |
"stop") | |
EVENT="motion_end" | |
sudo rpi-backlight -b 20 | |
;; | |
esac | |
## https://github.com/linusg/rpi-backlight | |
## Send the event data to IFTTT webhook to trigger a push notification | |
curl -X POST -H "Content-Type: application/json" -d '{"value1":"'"$(date +%Y-%m-%d)"' '"$(date +%H:%M:%S)"'","value2":"'"$TITLE"'","value3":"'"$URL"'"}' https://maker.ifttt.com/trigger/$EVENT/with/key/$IFTTT_KEY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment