Skip to content

Instantly share code, notes, and snippets.

@Dan1jel
Last active October 3, 2023 09:19
Show Gist options
  • Save Dan1jel/8cac149d54184410a6640fc8f69c655a to your computer and use it in GitHub Desktop.
Save Dan1jel/8cac149d54184410a6640fc8f69c655a to your computer and use it in GitHub Desktop.
IFTTT using Curl to control Arlo cameras when home (via wifi) or not.
// Define three values
let Samsung = MakerWebhooks.event.Value1;
let Pixel = MakerWebhooks.event.Value2;
let NoDevice = MakerWebhooks.event.Value3;
let DateNow = MakerWebhooks.event.OccurredAt;
let searchWord = "ARMED";
let msg = DateNow + ", " + Samsung + " & " + Pixel + ".";
let msg2 = NoDevice;
// If no one is home, skip disarm Arlo.
if (NoDevice.indexOf(searchWord) != -1 ) {
Arlo.disarm.skip();
IfNotifications.sendNotification.setMessage(msg2)
} else {
// If someone is home, skip arm Arlo.
Arlo.arm.skip();
IfNotifications.sendNotification.skip();//IfNotifications.sendNotification.setMessage(msg);
}
#!/usr/bin/env bash
# Set the IP address of the WiFi device to check.
SAMSUNG_IP_ADDRESS="192.168.87.205" # 205.
PIXEL_IP_ADDRESS="192.168.87.57" # 57.
# Set the initial device status to "not connected".
SAMSUNG_STATUS="not connected"
PIXEL_STATUS="not connected"
# Diffrent text colors.
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Set Arlo variable.
ARLO_NIGHT="false"
# IFTTT Private key.
IFTTT_KEY="https://maker.ifttt.com/trigger/YOUR_WEBHOOK/with/key/YOUR_KEY"
# Time & date outside loop.
STIME="$(date +"%H:%M")"
SDATE="$(date +"%Y-%m-%d")"
# Start script in ARMED mode to ensure Arlo is activated.
echo -e "$SDATE - $STIME > ${GREEN}WiFi_arlo.sh started.${NC}"
curl -s -X POST -H "Content-Type: application/json" -d "{\"value3\":\"$STIME : Arlo is ARMED (Startup script).\"}" "$IFTTT_KEY" >/dev/null
sleep 5
# Loop starts here.
while true; do
# Time & date inside loop.
STIME="$(date +"%H:%M")"
SDATE="$(date +"%Y-%m-%d")"
# If clock is between 22:00 -> 05:00, activate Arlo cameras.
if [[ "$STIME" > "22:00" ]] || [[ "$STIME" < "05:00" ]]; then
if [ "$ARLO_NIGHT" = "false" ];then
curl -s -X POST -H "Content-Type: application/json" -d "{\"value3\":\"$STIME : Arlo is ARMED (NightMode).\"}" "$IFTTT_KEY" >/dev/null
echo -e "$SDATE - $STIME > ${YELLOW}Arlo is ARMED (NightMode).${NC}"
ARLO_NIGHT="true"
fi
else
# Check if Samsung device is connected.
if ping -c 2 $SAMSUNG_IP_ADDRESS >/dev/null; then
SAMSUNG_NEW_STATUS="connected"
else
SAMSUNG_NEW_STATUS="not connected"
fi
# Check if Pixel device is connected.
if ping -c 2 $PIXEL_IP_ADDRESS >/dev/null; then
PIXEL_NEW_STATUS="connected"
else
PIXEL_NEW_STATUS="not connected"
fi
# Checking device status.
if [ "$SAMSUNG_STATUS" != "$SAMSUNG_NEW_STATUS" ] || [ "$PIXEL_STATUS" != "$PIXEL_NEW_STATUS" ]; then
# Check if no device is connected.
if [ "$SAMSUNG_NEW_STATUS" = "not connected" ] && [ "$PIXEL_NEW_STATUS" = "not connected" ]; then
echo -e "$SDATE - $STIME > ${RED}Arlo is ARMED (No device connected).${NC}"
curl -s -X POST -H "Content-Type: application/json" -d "{\"value3\":\"$STIME : Arlo is ARMED (No device connected).\"}" "$IFTTT_KEY" >/dev/null
# Notify if Samsung & Pixel is connected.
elif [ "$SAMSUNG_NEW_STATUS" = "connected" ] && [ "$PIXEL_NEW_STATUS" = "connected" ]; then
echo "$SDATE - $STIME > Samsung & Pixel is connected."
curl -s -X POST -H "Content-Type: application/json" -d "{\"value1\":\"Samsung is $SAMSUNG_NEW_STATUS\",\"value2\":\"Pixel is $PIXEL_NEW_STATUS\"}" "$IFTTT_KEY" >/dev/null
# Notify if only Samsung is connected.
elif [ "$SAMSUNG_NEW_STATUS" = "connected" ]; then
echo "$SDATE - $STIME > Samsung is $SAMSUNG_NEW_STATUS."
curl -s -X POST -H "Content-Type: application/json" -d "{\"value1\":\"Samsung is $SAMSUNG_NEW_STATUS\"}" "$IFTTT_KEY" >/dev/null
# Notify if only Pixel is connected.
elif [ "$PIXEL_NEW_STATUS" = "connected" ]; then
echo "$SDATE - $STIME > Pixel is $PIXEL_NEW_STATUS."
curl -s -X POST -H "Content-Type: application/json" -d "{\"value2\":\"Pixel is $PIXEL_NEW_STATUS\"}" "$IFTTT_KEY" >/dev/null
fi
# Update the device status variable.
SAMSUNG_STATUS="$SAMSUNG_NEW_STATUS"
PIXEL_STATUS="$PIXEL_NEW_STATUSS"
ARLO_NIGHT="false"
fi
# echo "Script is not allowed to run at this time or on this day."
fi
# Wait for 55 seconds before checking again.
sleep 55
# End of loop/script
done
@Dan1jel
Copy link
Author

Dan1jel commented Oct 3, 2023

Ive been playing wiht this for a while now and it took some time to get this to work. i put this up if someone else also looks for this and might need a guidence. Let me know if there is an issue / need of approvment.

i have this script running in a TMUX window, on my Raspberry pi server at home that is always on/running.

i created this script/solution because Arlo have "ON or OFF", nothing between. and i want the script to enable the cameras when we leave or disable the cameras when we are home, so it dont send a notification all the time when someone is home but do not have the Arlo app.
I also wanted to activate the cameras after 22:00 in the night even if we are home or not.

this solved the "issue" for me and like i said, if someone needed to see or understand the code, thats why i made it public but removed all the essensial stuff.

signal-2023-10-03-105826_002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment