[REQUEST] X10 (Home Automation Control) Script for XBMC
#16
asteron,

thanks for your input... i found some great examples and a mini-tutorial by alex aka alx5962 on the xbmc manual website.

so i started from scratch and rebuilt the script with the exact syntax he used. long story short, the buttons are working now, but i am still not exactly sure what was wrong with the original script although i will do a contrast and compare and report back here.

i plan to do some tweaking and enhancing over the next couple of days and will post back my final script if anyone else is interested in controlling x-10 devices via homeseer and xbmc.

thanks again to all and to all a good night.

buzzster
Reply
#17
i'm definitely interested in the script.

are you planning on having the ability for direct dim levels and such like my asp pages?
I'm not an expert but I play one at work.
Reply
#18
affini mentioned earlier something about making pages take an http post command. if you ever need to do that you should use the code here.

though i dont see why a page like that wouldnt take http get....
Reply
#19
(asteron @ dec. 25 2005,09:33 Wrote:affini mentioned earlier something about making pages take an http post command.  if you ever need to do that you should use the code here.

though i dont see why a page like that wouldnt take http get....
homeseer work better with post and not get. one reason is that get responses are cached and post is not. this is better for home automation device status for obvious reasons.

the homeseer web server is based on http/asp so if you send commands directly to the server there is no need for web pages.

this was my point. making web pages is unnecessary and a waste of time if you are using xbmc to trigger homesser.

buzzster,
when creating xbmc pages please avoid using requiring web pages for them to work. my package has all the gif images in it too so feel free to use them on the xbmc pages. i'd love to see you create some cool stuff using my images. maybe on a screen that mimics what my pages look like?
I'm not an expert but I play one at work.
Reply
#20
have been off and on (mostly off) today, but now that i am full of holiday cheer, wanted to get back to everyone - btw, thanks for the continued input.

before i start, i must reiterate - when it comes to programming, i am a major noob - especially with python.  so, i am just trying to find something that works and then build on it and i appreciate any and all specific coding help!!

that being said, i have posted the latest draft test script and supporting files at:
http://home.carolina.rr.com/scottandshea...viaasp.rar

if you want to see what it looks like when run, click here:
http://home.carolina.rr.com/scottandshea...hot000.jpg

once again i have to give credit to tartag for sending me the pmiii x-10 background that is included in the .rar file.

also please keep in mind this script is just getting started, but it works for the controls on the page (for those of you with homeseer, change to your codes/controls - i plan to make this more universal later but for now i am explicitly spelling everything out in the script) ....

a few comments:
right now, homeseer is controlled in the above script by .asp page calls? from the xbmc script.  based on comments here, i would like to do this control via http "post" commands, but have not been successful in getting this to work through a script yet.

on that note and this one:

Quote:posted by atheron on dec. 25 2005,11:33
--------------------------------------------------------------------------------
affini mentioned earlier something about making pages take an http post command.  if you ever need to do that you should use the code here.

asteron (or anyone), do you have the expertise to format affini's suggestion of:  

Quote:<form method='post'><input type='hidden' value='hs.execx10byname "kitchen espresso machine", "on", 100'></form>

into the python format shown on the website you found/suggested here?  (you seem to be at least a lightyear ahead of me on programming and my attempts to make this "http post command" work in a simple script command have been futile.)

a few other notes:
affini, it would be nice to mirror the format you posted on your asp pages, but it may take me a while to get there.  also, my first run at doing this probably won't have dimming, 1.) because i am to much of a noob to implement it yet and 2.) because i can't "do" that anymore since i have bought non-dimable energy saving compact flourescents (to offset the power draw of all my xboxes  :d )

for the first run, i am contemplating moving away from the buttons and just using the checkmarkcontrol in python and its built-in toggle functionality of glowing green for "on" and blacked out for "off".  once i get this working and figure out how to do the "post" command, i can move on to the more advanced stuff (although i want to keep the look consistent with the pmiii skin .... i think).

as usual all comments/suggestions/help are welcome .... my free time over the holidays unfortunately won't last forever!

thanks!
Reply
#21
looks to me like this...

post_multipart(host, selector, fields, files) translates to..

post_multipart(<server name>,,'hs.execx10byname "kitchen espresso machine", "on", 100',)

...i'm not sure what 'selector' is.
I'm not an expert but I play one at work.
Reply
#22
affini,

were you implying i should pass those parameters to that function and include all the statements under it.  if so, i am not sure what to do with some of the variables below it.

i think? the original author in the link given by atheron was trying to define a new function named "post_multiport" that would pass variables onto the statements indented from and immediately following the "def" statement.  i tried your suggestion for kicks and it did not recognize post_multiport as a command....

so, i tried to pick the commands that i think does the "post" of the url and i thought it to be the following 2 lines...

h = httplib.http(host)    
h.putrequest('post', selector)

so i put it in a script file (turns out http(host) does not want host to have an http://prefix on it) and actually ran it without getting any error, but i can't see that it is doing anything (i.e. my christmas lights don't turn on like they did with the .asp method)...  the whopping 3 line script is below:


Quote:import httplib, mimetypes
h = httplib.http("192.168.0.150:80")
h.putrequest('post', 'hs.execx10byname "universal christmas lights", "on", 100')

i knew it could not be that simple, so i'm still stumped on the "how to do a http post command" from python.

btw affini, how would i execute the http post command in windows?  i haven't tried it, but would assume you just put your originally mentioned command/suggestion in a .htm file and "launch" it with ie.

i think i am in over my head

:nuts:
Reply
#23
look for wrtkaidcommander on xbmcscripts.com for a way to use urllib to post, you first use urlencode to format and then urlopen to post.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#24
ohh didnt know that you could just use urllib... only knew about the httplib example. thanks this is much simpler

for affini's example it would look like
Quote:import urllib
params = urllib.urlencode({'hidden': 'hs.execx10byname "kitchen espresso machine", "on", 100'})
f = urllib.urlopen(server, params)
print f.read()
i think
Reply
#25
i tried this code:
Quote: if control == self.btnexpressoon:
params = urllib.urlencode({'hidden': 'hs.execx10byname "kitchen espresso machine", "on", 100'})
urllib.urlopen(http://192.168.1.11:80, params)
self.message('expresso on button pressed.')

i get an 'invalid syntax' on the urllib.urlopen line

any ideas?
I'm not an expert but I play one at work.
Reply
#26
put quotes around the url.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#27
still get a syntax error...

entire code:
Quote:import xbmc, xbmcgui, urllib

#get actioncodes from keymap.xml
action_previous_menu = 10

root = "f:\\xbmc\\media\\"
server = "192.168.1.11"; # will eventually use this variable instead of explicit definitions below

class myclass(xbmcgui.window):
def (self):

self.scalex = ( float(self.getwidth()) / float(720) )
self.scaley = ( float(self.getheight()) / float(480) )

self.addcontrol(xbmcgui.controlimage(0,0,1280,720, root + "background-x10.png"))
self.lbltitle = xbmcgui.controlfadelabel(int(75 * self.scalex),int(53 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font13", "0xffffffff")
self.addcontrol(self.lbltitle)
self.lbltitle.addlabel("xbmc home control center")

self.btnespressoon = xbmcgui.controlbutton(int(230*self.scalex), int(100*self.scaley), int(90*self.scalex), int(25*self.scaley), " expresso on")
self.btnespressooff = xbmcgui.controlbutton(int(230*self.scalex), int(132*self.scaley), int(90*self.scalex), int(25*self.scaley), " expresso off")

self.addcontrol(self.btnespressoon)
self.addcontrol(self.btnespressooff)

self.btnespressoon.controldown(self.btnespressooff)
self.btnespressooff.controlup(self.btnespressoon)

self.setfocus(self.btnespressoon)

def onaction(self, action):
if action == action_previous_menu:
self.close()

def oncontrol(self, control):
if control == self.btnexpressoon:
params = urllib.urlencode({'hidden': 'hs.execx10byname "kitchen espresso machine", "on", 100'})
urllib.urlopen("http://192.168.1.11:80/", params)
self.message('expresso on button pressed.')
elif control == self.btnexpressooff:
params = urllib.urlencode({'hidden': 'hs.execx10byname "kitchen espresso machine", "off", 0'})
urllib.urlopen("http://192.168.1.11:80/", params)
self.message('expresso off button pressed.')

def message(self, message):
dialog = xbmcgui.dialog()
dialog.ok("command testing dialog", message)

mydisplay = myclass()
mydisplay .domodal()
del mydisplay
I'm not an expert but I play one at work.
Reply
#28
asteron and nuka - thx for jumping in to help!

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.

since i know the rest of that python script is ok, i am just trying to focus on getting the post command to work, so i just tried this little script based on the earlier suggestions....

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

it still does not turn on the light, and i get the following output/error msg.

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

can anyone interpret this error?..... this has me wondering if homeseer can take the http post command. is there a way to test the post command locally on the pc?  i tried putting

Quote:<form method='post'><input type='hidden' value='hs.execx10byname "foyer table lamp", "on"'></form>
in an .htm file and calling it via ie on my local machine, but it did not work (just guessing here).

i know the 'hs.execx10byname' command and syntax works, because i plop it in my .asp page and runs it fine.
Reply
#29
you may need to post to a specific page, add a print params after the urlencode and see how it's formatted and add that to "[url]http://192.168.0.150:80?"[/url] minus the quotes and see what that does in ie.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#30
nuka,
i beleive you are correct about posting "to" an asp page. i totally forgot.


if i use you code... i get a syntax error with 'f='.

do i need to define a variable? i know nothing about python.

thanks for the help!
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