Skip to content

Commit

Permalink
Update tuyasmartplug.sh
Browse files Browse the repository at this point in the history
1. Added an option to grep to always process the debug file as an ASCII file.
2. Made the status option work as a sensing system command for PSU Control.
3. Added a sync command to the off option.
  • Loading branch information
bvrielink authored Mar 11, 2022
1 parent 4403cf9 commit ed15b8f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tuyasmartplug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
######################################################################
#
# Script : tuyasmartplug.sh
# Git project : https://github.com/bvrielink/tuyasmartplug.sh
# Description : Script to turn on or off a Tuya Smartplug from the
# command line via an API call to the OctoPrint plugin.
# For the status option to work you need to enable
# debug logging in the Tuya Smartplug plugin.
# Arguments : on|off|status
# Author : Barry Vrielink
# Created : 20201202
# Version : 0.2
# Created : 20220311
# Version : 0.3
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
Expand All @@ -34,6 +35,8 @@ case $ACTION in
;;
off)
echo "Turning Tuya Smartplug off..."
sync
sleep 3
${CURL_EXE} -s -H "Content-Type: application/json" -H "X-Api-Key: ${API_KEY}" -X POST -d '{ "command":"turnOff", "label":"'"${PLUGIN_LABEL}"'" }' http://${SERVER_NAME}/api/plugin/tuyasmartplug &
exit
;;
Expand All @@ -45,13 +48,15 @@ case $ACTION in
echo "Debug file not found! Enable debug logging in the plugin."
exit 1
fi
STATUS=`grep "DEBUG: Status:" ${DEBUG_FILE} | tail -1`
STATUS=`grep -a "DEBUG: Status:" ${DEBUG_FILE} | tail -1`
case $STATUS in
*True*)
echo "Tuya Smartplug is turned ON."
exit 0
;;
*False*)
echo "Tuya Smartplug is turned OFF."
exit 1
;;
*)
echo "Tuya Smartplug status is UNKNOWN."
Expand Down

0 comments on commit ed15b8f

Please sign in to comment.