Last active
December 21, 2015 22:47
-
-
Save broo0ose/27939661c60d13784e10 to your computer and use it in GitHub Desktop.
quick script to control energenie equipped raspberry pi from the command line.
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 | |
# needs python v3 for argparse | |
# needs energenie module from https://pythonhosted.org/energenie/ | |
from energenie import switch_on, switch_off | |
import argparse | |
parser = argparse.ArgumentParser() | |
# TOGGLE -u UNIT_NUMBER | |
parser = argparse.ArgumentParser(description='Energenie control from the command line ',epilog='must be run as root or with sudo') | |
# non optional, we have to have a state to send to the units | |
parser.add_argument("toggle", help="ON or OFF") | |
# optional, default is 0 which is all units | |
parser.add_argument("-u", "--unit", help="Unit number 1-4 or 0 (default) for all", default=0, type=int) | |
args = parser.parse_args() | |
# use str.upper to make it case insensitive. | |
if str.upper(args.toggle) == "ON": | |
switch_on(args.unit) | |
elif str.upper(args.toggle) == "OFF": | |
switch_off(args.unit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment