Created
July 27, 2021 08:38
-
-
Save pedropombeiro/2db5b43051fb316c3aed476bc81f0514 to your computer and use it in GitHub Desktop.
Control the Levoit Air Purifier with Python script
This file contains hidden or 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
#!/usr/bin/env python3 | |
import os, sys | |
from pyvesync import VeSync # https://github.com/webdjoe/pyvesync# | |
manager = VeSync(os.environ['LEVOIT_ACCOUNT'], os.environ['LEVOIT_PASSWORD'], os.environ['LEVOIT_TIMEZONE']) | |
manager.login() | |
# Get/Update Devices from server - populate device lists | |
manager.update() | |
if len(sys.argv) == 1: | |
for fan in manager.fans: | |
fan.display() | |
exit(0) | |
cmd = sys.argv[1] | |
fan = manager.fans[0] | |
if cmd == 'up': | |
if fan.mode != 'manual': | |
fan.manual_mode() | |
fan.change_fan_speed(fan.speed+1) | |
elif cmd == 'down': | |
if fan.mode != 'manual': | |
fan.manual_mode() | |
fan.change_fan_speed(fan.speed-1) | |
elif cmd == 'off': | |
fan.turn_off() | |
elif cmd == 'on': | |
fan.turn_on() | |
elif cmd == 'manual': | |
fan.manual_mode() | |
elif cmd == 'sleep': | |
fan.sleep_mode() | |
elif cmd in ['1', '2', '3']: | |
fan.change_fan_speed(int(cmd)) | |
else: | |
print('Unexpected command!') | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a
.env.levoit
file containing: