Created
April 15, 2021 07:36
-
-
Save dirkjanfaber/1277b2a9091e41955537e841d281a73a to your computer and use it in GitHub Desktop.
Simple python script to control a tcw181b-cm
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
#!/usr/bin/python | |
import requests | |
import argparse | |
device="tcw181b-cm" | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-d', '--device', nargs=1, help='device (default: '+device+')') | |
parser.add_argument('-f', '--off', type=int, action='append', nargs=1, help='turn relay X off') | |
parser.add_argument('-n', '--on', type=int, action='append', nargs=1, help='turn relay X on') | |
parser.add_argument('-t', '--toggle', type=int, action='append', nargs=1, help='toggle port X') | |
parser.add_argument('-p', '--pulse', type=int, action='append', nargs=1, help='pulse port X') | |
parser.add_argument('-v', '--verbose', action='store_true', help='increase output verbosity' ) | |
args = parser.parse_args() | |
if args.device: | |
device=args.device[0] | |
cmd = 'http://'+str(device)+'/status.xml?' | |
if args.off: | |
for f in args.off: | |
cmd += 'r'+str(f[0])+'=0&' | |
if args.on: | |
for n in args.on: | |
cmd += 'r'+str(n[0])+'=1&' | |
if args.pulse: | |
for p in args.pulse: | |
cmd += 'pl'+str(p[0])+'=1&' | |
if args.toggle: | |
for t in args.toggle: | |
cmd += 'tg'+str(t[0])+'=1&' | |
# Remove last ampersand from the command | |
cmd = cmd[:-1] | |
if args.verbose: | |
print(cmd) | |
requests.get(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment