Python + URL Params

Moderator: Telldus

Post Reply
lew_for
Posts: 3
Joined: Fri Mar 17, 2023 9:45 am

Python + URL Params

Post by lew_for »

So I have finally got a web interface setup, and I can visit example.com/cgi-bin/on.py and it will turn my socket on, I don't know much python though, so I was wondering if it would be possible to control the power/device via the URL?

This is the code I am currently using:

Code: Select all

print "Content-Type: text/html"
print
print '<title>Power - ON</title>'
print "<h1>Fan - <font color=green>On</font></h1>"
print 'Please click <a href="/index.html">here</a> to go back.'


from tellcore.telldus import TelldusCore

core = TelldusCore()

devices = core.devices()
for device in devices:
    if device.name == "Switch":
        device.turn_on()
I assume I would need to create one Python script to control the power (On and Off, for other devices too), and create some variables. How would I do this for on/off?

My goal, would be to have it so I can type in example.com/cgi-bin/power.py?id=1;power=0

Or something similar, which obviously would turn off the device that has the ID '1'.

Is this possible? I'm sure it shouldn't be too difficult, from what knowledge I have from other programming languages, I'm just not too sure how to do it in Python, and I couldn't really understand what I found on Google.
erijo
Posts: 22
Joined: Fri Mar 17, 2023 9:45 am

Re: Python + URL Params

Post by erijo »

I have a very rough web interface that I hacked togheter last year. Attaching it here if you'd like to try it out. Install flask and then just run tdweb.py. There is no security at all, so don't run it on a public server.
Attachments
tdweb.tar.gz
(2.59 KiB) Downloaded 310 times
Python wrapper for Telldus Core: tellcore-py
Python wrapper for Telldus Live: tellive-py
Post Reply