-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple script to synchronize time and read values from sensors
It also allows to set units to Celsius or Fahrenheit
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!python | ||
|
||
import argparse | ||
import lywsd02 | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('action', help='Action to perform, either: sync - synchronize time with this machine, read - read current values from device, setc/setf - set temperature unit on display to Celsius/Fahrenheit', choices=['sync', 'read', 'setc', 'setf']) | ||
parser.add_argument('mac', help='MAC address of LYWSD02 device', nargs='+') | ||
args = parser.parse_args() | ||
|
||
for mac in args.mac: | ||
try: | ||
client = lywsd02.Lywsd02Client(mac) | ||
if args.action == 'sync': | ||
print('Synchronizing time of {}'.format(mac)) | ||
client.time = datetime.datetime.now() | ||
elif args.action == 'read': | ||
print('Fetching data from {}'.format(mac)) | ||
data = client.data | ||
print('Temperature: {}°C'.format(data.temperature)) | ||
print('Humidity: {}%'.format(data.humidity)) | ||
print('Battery: {}%'.format(client.battery)) | ||
print() | ||
elif args.action == 'setc': | ||
client.units = 'C' | ||
elif args.action == 'setf': | ||
client.units = 'F' | ||
except Exception as e: | ||
print(e) |
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