[REQUEST] X10 (Home Automation Control) Script for XBMC
#31
Quote:import urllib, socket
socket.setdefaulttimeout(5.0) #seconds
params = urllib.urlencode({'hidden': 'hs.execx10byname "foyer table lamp", "on"'})
f = urllib.urlopen("http://192.168.0.150:80", params)
print f.read()

i added the timeout and i don't get any syntax error.

is this software i can download and run as a test without the x10 hardware?
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#32
affini,

can you define the syntax error you are getting?  if it just says "syntax error" i am not getting the same thing.  make a new .py script with just the lines below and change it to your x10 specific device and see if you get the same error i am getting.  i get a consistent error on both the xbox (press white button after script executes to see debug info) and on my pc python shell window when i run it on the pc.

nuka,

i changed the script per your suggestion to see what 'params' looks like... here is the script in the first quote and the output in the 2nd quote.

script:
Quote:import urllib
params = urllib.urlencode({'hidden': 'hs.execx10byname "foyer table lamp", "on"'})
print params
f = urllib.urlopen("[url]http://192.168.0.150:80"[/url], params)
print f.read()

output:
Quote:>>>
hidden=hs.execx10byname+%22foyer+table+lamp%22%2c+%22on%22
<body> unknown post/put request, data is hidden=hs.execx10byname+%22foyer+table+lamp%22%2c+%22on%22</body>
>>>

where is the %22 and %2c stuff coming from?  more importantly, how do you get rid of it?
i tried to put this in the address bar in ie after the server address as you suggested and it doesn't work as expected.

as far as trying homeseer without having any x10 hardware, you can download a trial (http://www.homeseer.com) and set it up to do some local pc manipulation, but it is a relatively big program that you probably don't want to crud up your os with...

if you pm me, i can give you access to see what the default homeseer webpage looks like.

like i had said earlier, i can make a simple call to an .asp page and get the x-10 event to run, we are just trying to do it though the http post command which homeseer can supposedly accept.


thanks.
Reply
#33
you probably have to post to that asp page. what does the address look like for the call to the asp page?

the %22 and %2c stuff are converting quotes and commas so the address is accepted.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#34
the call to an asp page is very simple.

the following 2 line script
Quote:import urllib
urllib.urlopen("[url]http://192.168.0.150:80/scott/foyertablelampon.asp"[/url])

turns on a light in my house, via script in the foyertablelampon.asp file that is shown below.

Quote:<%@ language=vbscript %>
<html>
<head>
</head>
<body>
<%hs.execx10byname "foyer table lamp", "on"%>
</body>
</html>

the problem with this is that i have to create a separate .asp page for every command for every x10 device (light, appliance, etc..)

i know there is an easier way to do this, and was hoping the dynamic creation/execution via the post command would be the answer.
Reply
#35
ok, i read this whole thread and understand a little better of what your trying to do.

it's hard to say exactly where you need to post to.

on the router there is command.asp, do you have a main asp file that would have something similar to this.

Quote:<form method="post" action="apply.cgi" id="cform">
<input type="hidden" name="submit_button" value="command">
<input type="hidden" name="submit_type" value="start">
<input type="hidden" name="change_action" value="gozila_cgi">
<input type="hidden" name="action" value="apply">

this translates into how to form the urlencode command.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#36
you may be able to create your own if your familiar with asp.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#37
nuka,
the source code of my kitchen asp is this...

Quote:<meta http-equiv="cleartype">


<link rel="stylesheet" href="/hact/hact.css">

<html><head>
</head>
<body>
<table width="280">
   <td width="100%" colspan="2">
   <table width="100%">
     <tr>
<center><td class=area>kitchen</td></center>
     </tr>
   </table>
   </td>

<!-- row 1 -->

 <tr>

   <td width="50%">
   <table width="100%">
     <tr>
  <td class=device>espresso</td>
  <td class=textfromstatus> off</td>
  <td class=statuscommandbutton><form method='post' style="margin:0"><input src=\icons\devices\coffee-off.gif type='image' align='absmiddle' width=16 height=16 title='on'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen espresso machine", "on", 100' name='commandimage'></form></td>
     </tr>
   </table>
   </td>
   
   <!-- blank set -->
   <td width="50%">
   <table width="100%">
     <tr>
  <td></td>
  <td></td>
  <td></td>
     </tr>
   </table>
   </td>
 </tr>

<!-- row 2 -->

 <tr>
   <td width="100%" colspan="2">
   <table width="100%">
     <tr>
<td class=device>lights</td>
  <td class=dimbarcontrol><table border=0 cellspacing=0><tr>
<td><form method='post' style="margin:0"><input src=/icons/devices/dims0.gif type='image' align='absmiddle' width=16 height=16 title='off'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "off", 100' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim10.gif type='image' align='absmiddle' width=16 height=16 title='10%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 10' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim20.gif type='image' align='absmiddle' width=16 height=16 title='20%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 20' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim30.gif type='image' align='absmiddle' width=16 height=16 title='30%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 30' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim40.gif type='image' align='absmiddle' width=16 height=16 title='40%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 40' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim50.gif type='image' align='absmiddle' width=16 height=16 title='50%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 50' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim60.gif type='image' align='absmiddle' width=16 height=16 title='60%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 60' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim70.gif type='image' align='absmiddle' width=16 height=16 title='70%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 70' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim80.gif type='image' align='absmiddle' width=16 height=16 title='80%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 80' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim90.gif type='image' align='absmiddle' width=16 height=16 title='90%'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "dimab", 90' name='commandimage'></form></td>
<td><form method='post' style="margin:0"><input src=/icons/devices/dim100.gif type='image' align='absmiddle' width=16 height=16 title='on'><input type='hidden' value='image' name='action'><input type='hidden' value='hs.execx10byname "kitchen lights", "on", 100' name='commandimage'></form></td>
</tr></table>
</td>
     </tr>
   </table>
   </td>
 </tr>
</table>
</body>
</html>



I'm not an expert but I play one at work.
Reply
#38
buzzster and affini,

we may be making this harder than it has to be.

try each of these in ie and see if you get anything. also the :80 shouldn't be necessary as 80 is the default for http. you need to have 'foyer table lamp' as a device name.

Quote:http://192.168.0.150:80/hs.execx10byname+%22foyer+table+lamp%22%2c+%22on%22

http://192.168.0.150:80?hs.execx10byname+%22foyer+table+lamp%22%2c+%22on%22



For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#39
nuka,

unfortunately, i got a badurl for both of those examples.

i don't really know what the post function does, but was/am hopeful it would be able to insert the body into the .asp file that i had posted just earlier.

given the feedback we received from the print params statement, it looks like if we could get it to pass regular spaces/commas instead of the %22 stuff and also specify a generic but specific target.asp file, it may work?

we basically just want to dynamically change the command that is in between <body> and </body> of the .asp lines i posted and then call/run a universal.asp page (we already know how to call/run the .asp page).

is there an easy way to do this, not using post, or would that not be efficient.


thanks!
Reply
#40
when you run your foyertablelampon.asp, does the address bar change? or does it just stay

Quote:http://192.168.0.150:80/scott/foyertablelampon.asp


what i'm looking for is the exact address line sent to the webserver. something like i posted.

as for your asp, you could write the script out to a text file easy enough, then you'd have to upload it to the server and then execute it.

if the webserver supports post then it would be easier to just do what we're trying here, post the commands directly, but i can't tell how that's formatted from your scripts.

i'm pretty sure this won't work, but, i looked at affini's script. affini maybe add kitchen.asp just after the ip and see if that works for you.

Quote:import urllib, socket
socket.setdefaulttimeout(5.0) #seconds
params = urllib.urlencode({'action': "image", 'commandimage': 'hs.execx10byname "foyer table lamp", "on"'})
print params
f = urllib.urlopen("http://192.168.0.150/", params)
print f.read()
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#41
my code looks like this but it does not work...

Quote: elif control == self.btnexpressooff:
params = urllib.urlencode({'hidden': 'hs.execx10byname "kitchen espresso machine", "off", 100'})
urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp", params)
self.message('expresso off button pressed.')


i get a syntax error every time.

there must be someone on the forums that knows python for posting form data?
I'm not an expert but I play one at work.
Reply
#42
(buzzster @ dec. 26 2005,11:39 Wrote:affini,

i am no python expert, but i wonder if it could be the fact that you don't have a couple lines indented near the end of your script?  the 9th and 10th lines from the bottom by my count.

...... other part of post deleted
affini,

did you miss my earlier response?

alignment seems to be very important in python... try moving the last 2 lines you posted of your script excerpt over to align with the "p" in params above them.


nuka,

to answer your last question...when i run foyertablelampon.asp, the address bar does not change.

i will respond to the rest of your question a little later in that i have some guests over at the moment.
Reply
#43
(buzzster @ dec. 26 2005,20:53 Wrote:[quote=buzzster,dec. 26 2005,11:39]affini,
alignment seems to be very important in python... try moving the last 2 lines you posted of your script excerpt over to align with the "p" in params above them.
the indents looks fine in ultraedit but it is not when using notepad... strange!

so the screen now works... ah, but the commands do not :verysad:



I'm not an expert but I play one at work.
Reply
#44
i may be making some progress... kinda?

i simplified my .py to only 2 lines...
Quote:import urllib
urllib.urlopen('http://192.168.1.11', urllib.urlencode({'control_device': 'kitchen lights=off'}))

error on xbmc log...
Quote:file "q:\python\python23.zlib\urllib.py", line 78, in urlopen
file "q:\python\python23.zlib\urllib.py", line 183, in open
file "q:\python\python23.zlib\urllib.py", line 297, in open_http
file "q:\python\python23.zlib\httplib.py", line 712, in endheaders
file "q:\python\python23.zlib\httplib.py", line 597, in _send_output
file "q:\python\python23.zlib\httplib.py", line 564, in send
file "q:\python\python23.zlib\httplib.py", line 548, in connect
ioerror
:
[errno socket error] (10060, 'operation timed out')


i've taken the commands i'm using from working http & asp pages.

here's actual code from an html page i'm using for the same device i'm trying in my .py...
Quote:<form method="post">
<td nowrap class="tableroweven">
<a name="bm83274"></a>
<input type="hidden" name="bookmark" value="83274">
<input type="hidden" name="ref_page" value="stat">
<input type="hidden" name="control_device" value="kitchen lights">
<input class="formbutton" type="submit" name="action_on" value="on">
<input class="formbutton" type="submit" name="action_off" value="off">
<select class="formdropdown" name="selectdim" size="1"
onchange="submitform(this)">
<option selected value="0">0%</option>
<option value="10">10%</option>
<option value="20">20%</option>
<option value="30">30%</option>
<option value="40">40%</option>
<option value="50">50%</option>
<option value="60">60%</option>
<option value="70">70%</option>
<option value="80">80%</option>
<option value="90">90%</option>
<option value="100">100%</option>
</select>
</td></form>



I'm not an expert but I play one at work.
Reply
#45
anyone still working on this besides me?
I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
[REQUEST] X10 (Home Automation Control) Script for XBMC0