Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settime.sh script #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,13 @@ Reading out the WAN link status on an Archer C9 in default configuration shows t
Reply Data: Version 02 Type 03 Status 00 Length 00000018 ID 0001 Subtype 0e
Decrypted: wan_ph_link 1 0
```

## settime.sh

Especially when you disconnect your Smartplug from the Cloud, the time is not set. Without time set you can't use several functions in the Kasa App, like countdown, shedules or get proper total energy consumption.

With this script you can set the time.

It has to be placed in the same folder as the tplink_smartplug.py

Usage: `./settime.sh <IP1 of your Smartplug> <IP2 of your Smartplug2> <IP3 of your Smartplug2>` and so on
24 changes: 24 additions & 0 deletions settime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [ $# -eq 0 ]
then
echo "Usage: settime.sh IP1 IP2 ..."
exit 1
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Set Timezone
# {"time":{"set_timezone":{"year":2016,"month":1,"mday":1,"hour":10,"min":10,"sec":10,"index":42}}}

for i in "$@"
do
jahr=$(date +"%Y")
monat=$(date +"%m")
tag=$(date +"%d")
stunde=$(date +"%-H")
minute=$(date +"%-M")
sekunde=$(date +"%-S")
echo $DIR/tplink_smartplug.py -t $i -j "{\"time\":{\"set_timezone\":{\"year\":$jahr,\"month\":$monat,\"mday\":$tag,\"hour\":$stunde,\"min\":$minute,\"sec\":$sekunde,\"index\":42}}}"
$DIR/tplink_smartplug.py -t $i -j "{\"time\":{\"set_timezone\":{\"year\":$jahr,\"month\":$monat,\"mday\":$tag,\"hour\":$stunde,\"min\":$minute,\"sec\":$sekunde,\"index\":42}}}"
done
12 changes: 12 additions & 0 deletions settimeByMAC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ $# -ne 1 ]
then
echo "Usage: settime.sh <MAC>"
echo "Important: Contact must have been made, so that MAC address is in arp table"
exit 1
fi

IP=$(arp -n | grep -i $1 | grep -oP '^[^\s]+')

$DIR/settime.sh $IP