Skip to content

Instantly share code, notes, and snippets.

@davidfg4
Created January 7, 2016 03:44
Show Gist options
  • Save davidfg4/c12fe20da7de5c8c31c0 to your computer and use it in GitHub Desktop.
Save davidfg4/c12fe20da7de5c8c31c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import time
import telnetlib
def inittn():
tn = telnetlib.Telnet("192.168.1.24", 23, 3)
tn.read_until("login:")
tn.write("lutron\r\n")
tn.read_until("password:")
tn.write("integration\r\n")
return tn
def closetn(tn):
time.sleep(1)
tn.close()
def setlight(id, value=75, fadetime=1):
tn = inittn()
tn.write("#OUTPUT,"+str(id)+",1,"+str(value)+","+str(fadetime)+"\r\n")
closetn(tn)
def pressbutton(panel, button, value=3):
tn = inittn()
tn.write("#DEVICE,"+str(panel)+","+str(button)+","+str(value)+"\r\n")
closetn(tn)
if __name__ == "__main__":
import cgi
import cgitb
cgitb.enable(display=0, logdir="/tmp")
print("Content-Type: text/html")
print("")
form = cgi.FieldStorage()
type = form.getfirst("type", "").upper()
id = form.getfirst("id", "").upper()
id2 = form.getfirst("id2", "").upper()
value = form.getfirst("value", "").upper()
button = form.getfirst("button", "").upper()
if (type == "DEVICE"):
pressbutton(id, id2)
print("button " + str(id) + " pressed")
elif (type == "OUTPUT"):
setlight(id, value)
print("light " + str(id) + " set to " + str(value))
else:
print("invalid command")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment