-
-
Save anonymous/45ed9ae8bb834b3bdddf1430f151889c to your computer and use it in GitHub Desktop.
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 | |
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