Skip to content

Instantly share code, notes, and snippets.

/-

Created December 27, 2017 02:48
Show Gist options
  • Save anonymous/45ed9ae8bb834b3bdddf1430f151889c to your computer and use it in GitHub Desktop.
Save anonymous/45ed9ae8bb834b3bdddf1430f151889c to your computer and use it in GitHub Desktop.
#!/bin/bash
SCRIPT_PATH="./tplink-smartplug.py"
SCRIPT_PATH="./tplink-smartplug.sh"
PLUG_ADDR=$1
ACTION=$2
case $ACTION in
on)
echo "Turning On..."
${SCRIPT_PATH} -t ${PLUG_ADDR} -c on
exit $?
;;
off)
echo "Turning Off..."
${SCRIPT_PATH} -t ${PLUG_ADDR} -c off
exit $?
;;
sense)
relay_state=`${SCRIPT_PATH} -t ${PLUG_ADDR} -c info | sed 's/,/\n/g' | grep 'relay_state' | awk -F':' ' { print $2 } '`
if [ $relay_state -eq 1 ]
then
echo "On"
exit 0
elif [ $relay_state -eq 0 ]
echo "Off"
exit 1
else
echo "Unknown Error"
exit 1
fi
;;
*)
echo "Usage $0: {on|off|sense}"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment