[REQUEST] X10 (Home Automation Control) Script for XBMC
#1
Lightbulb 
hey guys-

first post; have been lurking for some time and really appreciate the wealth of knowledge here in the forums. that said, i belive i have searched diligently on the topic to no aviail, so appologies if it has been covered. has anyone developed an x10 control script for xbmc? as i type this i realize that the inevidable question is, "where do you hook up the controler?" i use a cm11a and it is connected via rs232 on a redhat box. so the bigger question may be if anyone has built a script to control something hangning off an rs232?...

any thoughts are apreciated.

cheers,
-tartag
Reply
#2
if there was a script it would be at xbmcscripts.com but i dont think there is one. i don't know much about this but to set this up you would probably need two parts, a server running on the linux machine and a client to connect to it from xbmc written in python. there are other server/client script on xbmcscripts.com you could use as an example though like the emule control script and that mythtv one.

-ast
Reply
#3
thanks for the response asteron. to be honest, at a minimum i can get away with executing a script on the linux box. so maybe a broader question, is can i get python to do say: https://myserver.mydomain/cgi-bin/dosomething.pl?arg

thanks,
tartag
Reply
#4
Quote:import urllib
urllib.urlopen('https://myserver.mydomain/cgi-bin/dosomething.pl?arg')

if you are really interested in doing this python is not very difficult to understand if you look at the other scripts for examples. since it seems like you might know perl i think this python 2.3 quick reference might be useful. python is very similar to perl in most respects but i find it a lot more readable.



Reply
#5
great minds... anyway yeah i am using the freakhole script to get a general idea, i would call myself perl accomplished so i am happy to hack away 'til something breaks. i appreciate all the feedback and appreciate the link, can you think of another script that might be a better primer?

thanks again,
-tags
Reply
#6
you're right in that the problem is that you don't have anywhere to connect the cm11. arguable if you're running linux on the xbox then you could use a usb connected interface, but that would defeat the object wouldn't it?

i personally do what you have suggested at the end and am running homeseer on a pc to do the control and have some asp pages that i access from xbmc simple http requests.

i started putting more and more into the xbox python script and then realised that the logic just set better on the home controller box and simply called the page from xbmc.

so, in my case i have some "doit" pages on the homeseer box that does things like toggle or turn on / off lights, the python script simply calls the page with the appropriate url parameters like http://server/page.asp?action=off

really simple but it means that the same pages can be used by my konfabulator widgets to give simple distributed control.
Reply
#7
nikle:

exactly my approach, and call it with perl, i use heyu and xtend on the linux box and maintain the modules staus via flat files. i am calling those flat files back to xbmc to tell me what mods are on and off.

python has been fun and i now need to figure out how to parse those flat files into variables to be resused.

i love hearing how others are using this stuff.

cheers,
-tartag
Reply
#8
well, just to provide an update. with all the help in this forum the script is a success. i am happy to provide it to anyone if they are interested. that said, it will require some backend tools to be in place for it to function. if you are able to control your x10 modules via a command line, (homeseerer, heyu, etc.) this script will work for you. let me know and thanks for all the input.

cheers,
-tartag
Reply
#9
please post!!!

i use homeseer 1.7 and would love to try your script.
I'm not an expert but I play one at work.
Reply
#10
well  here ya go:

to give you an idea, i use heyu which runs on  linux box, from the cmd line i can type: 'heyu turn a1 on' or 'heyu turn heyu dim 10'  so, i have a perl script running that takes the input from the xbmc script and makes a system call. (let me know if you need some help on the perl side. i can also do a 'heyu info' and get the status of the modules in the house. a second script makes that call and formats the html to return to the xbmc script... again this is my first python script so do let me know where i can improve it and if i can help ya get it runnning for homeseer.
Quote:import xml.dom.minidom
import urllib,urllib2 , re
import xbmc, xbmcgui
from string import split, replace, find


try: emulating = xbmcgui.emulating
except: emulating = false


# coded by tartag

action_previous_menu = 10



#target url for unix box runnning heyu script
rhurl = "http://192.168.0.19:8889/cgi-bin/xbmc.pl?";
rhurl2 = "http://192.168.0.19:8889/cgi-bin/quickstat.pl?";

root = "e:\\apps\\xbmc\\media\\"


#pre-define global lists

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

  if emulating: xbmcgui.window.(self)

       
self.scalex = ( float(self.getwidth())  / float(720) )
       self.scaley = ( float(self.getheight()) / float(480) )
       
       self.addcontrol(xbmcgui.controlimage(0,0,720,480, root + "background-x10.png"))
       
       self.addcontrol(xbmcgui.controlimage(int(100 * self.scalex),int(65 * self.scaley),int(670 * self.scalex),int(68 * self.scaley), root + "x10-topbar.gif"))
       
       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("xbox media center home control")
 
###family room    
       self.lblroom = xbmcgui.controlfadelabel(int(45 * self.scalex),int(100 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")
self.addcontrol(self.lblroom)
self.lblroom.addlabel("family room")
       
       self.famonbtn = xbmcgui.controlbutton(int(220 * self.scalex),int(100 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn on")
     
       self.famoffbtn = xbmcgui.controlbutton(int(320 * self.scalex),int(100 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn off")
     
      self.famdimbtn = xbmcgui.controlbutton(int(420 * self.scalex),int(100 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "dim")
 
###living room
self.lblroom = xbmcgui.controlfadelabel(int(45 * self.scalex),int(150 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")
self.addcontrol(self.lblroom)
self.lblroom.addlabel("living room")
       
       self.lvroomonbtn = xbmcgui.controlbutton(int(220 * self.scalex),int(150 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn on")
     
       self.lvroomoffbtn = xbmcgui.controlbutton(int(320 * self.scalex),int(150 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn off")

       self.lvroomdimbtn = xbmcgui.controlbutton(int(420 * self.scalex),int(150 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "dim")      
 
###front porch
self.lblroom = xbmcgui.controlfadelabel(int(45* self.scalex),int(200 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")
self.addcontrol(self.lblroom)
self.lblroom.addlabel("front porch ")
       
       self.fporchonbtn = xbmcgui.controlbutton(int(220 * self.scalex),int(200 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn on")
     
       self.fporchoffbtn = xbmcgui.controlbutton(int(320 * self.scalex),int(200 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn off")

       self.fporchdimbtn = xbmcgui.controlbutton(int(420 * self.scalex),int(200 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "dim")        
###back porch
self.lblroom = xbmcgui.controlfadelabel(int(45 * self.scalex),int(250 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")
self.addcontrol(self.lblroom)
self.lblroom.addlabel("back porch ")
       
       self.bporchonbtn = xbmcgui.controlbutton(int(220 * self.scalex),int(250 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn on")
     
       self.bporchoffbtn = xbmcgui.controlbutton(int(320 * self.scalex),int(250 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn off")

       self.bporchdimbtn = xbmcgui.controlbutton(int(420 * self.scalex),int(250 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "dim")        
###spa
self.lblroom = xbmcgui.controlfadelabel(int(45 * self.scalex),int(300 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")
self.addcontrol(self.lblroom)
self.lblroom.addlabel("spa tartag")
       
       self.spaonbtn = xbmcgui.controlbutton(int(220 * self.scalex),int(300 * self.scaley), int(80 * self.scalex), int(25* self.scaley), "turn on")
     
       self.spaoffbtn = xbmcgui.controlbutton(int(320 * self.scalex),int(300 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "turn off")  

       self.spadimbtn = xbmcgui.controlbutton(int(420 * self.scalex),int(300 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "dim")
               
       self.exitbtn = xbmcgui.controlbutton(int(56 * self.scalex),int(395 * self.scaley), int(80 * self.scalex), int(25 * self.scaley), "exit")
       
       self.lblstatus = xbmcgui.controlfadelabel(int(180 * self.scalex),int(390 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")

       self.lastact = xbmcgui.controlfadelabel(int(220 * self.scalex),int(353 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xffffffff")


self.statlabel = xbmcgui.controlfadelabel(int(535 * self.scalex),int(105 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font14", "0xff0000cc")
       self.addcontrol(self.statlabel)
self.statlabel.addlabel("current status:")

self.statlist = xbmcgui.controllist(int(500 * self.scalex),int(135 * self.scaley), int(500 * self.scalex), int(300 * self.scaley))


       self.addcontrol(self.statlist)        
       self.addcontrol(self.lastact)        
       self.addcontrol(self.famonbtn)
       self.addcontrol(self.famoffbtn)
       self.addcontrol(self.famdimbtn)
       self.addcontrol(self.spaonbtn)
       self.addcontrol(self.spaoffbtn)
       self.addcontrol(self.spadimbtn)
       self.addcontrol(self.fporchonbtn)
       self.addcontrol(self.fporchoffbtn)
       self.addcontrol(self.fporchdimbtn)
       self.addcontrol(self.bporchonbtn)
       self.addcontrol(self.bporchoffbtn)
       self.addcontrol(self.bporchdimbtn)
       self.addcontrol(self.lvroomonbtn)
       self.addcontrol(self.lvroomoffbtn)
       self.addcontrol(self.lvroomdimbtn)
       self.addcontrol(self.exitbtn)
       self.famonbtn.controldown(self.lvroomonbtn)
       self.famonbtn.controlleft(self.exitbtn)
       self.famonbtn.controlright(self.famoffbtn)
       self.famonbtn.controlup(self.spaonbtn)
       self.famoffbtn.controlup(self.spaoffbtn)
       self.famoffbtn.controlleft(self.famonbtn)
       self.famoffbtn.controldown(self.lvroomoffbtn)
       self.famoffbtn.controlright(self.famdimbtn)
       self.famdimbtn.controlleft(self.famoffbtn)
       self.famdimbtn.controlup(self.spadimbtn)
       self.famdimbtn.controldown(self.lvroomdimbtn)
       self.lvroomonbtn.controldown(self.fporchonbtn)
       self.lvroomonbtn.controlleft(self.exitbtn)
       self.lvroomonbtn.controlright(self.lvroomoffbtn)
       self.lvroomoffbtn.controldown(self.fporchoffbtn)
       self.lvroomoffbtn.controlleft(self.lvroomonbtn)
       self.lvroomonbtn.controlup(self.famonbtn)
       self.lvroomoffbtn.controlup(self.famoffbtn)
       self.lvroomoffbtn.controlright(self.lvroomdimbtn)
       self.lvroomdimbtn.controlleft(self.lvroomoffbtn)
       self.lvroomdimbtn.controlup(self.famdimbtn)
       self.lvroomdimbtn.controldown(self.fporchdimbtn)
       self.spaonbtn.controlup(self.bporchonbtn)
       self.spaonbtn.controlleft(self.exitbtn)
       self.spaonbtn.controldown(self.famonbtn)
       self.spaonbtn.controlright(self.spaoffbtn)
       self.spaoffbtn.controlup(self.bporchoffbtn)
       self.spaoffbtn.controldown(self.famoffbtn)
       self.spaoffbtn.controlleft(self.spaonbtn)
       self.spaoffbtn.controlright(self.spadimbtn)
       self.spadimbtn.controlup(self.bporchdimbtn)
       self.spadimbtn.controlleft(self.spaoffbtn)
       self.spadimbtn.controldown(self.famdimbtn)
       self.fporchonbtn.controlup(self.lvroomonbtn)
       self.fporchonbtn.controlleft(self.exitbtn)
       self.fporchonbtn.controlright(self.fporchoffbtn)
       self.fporchonbtn.controldown(self.bporchonbtn)
       self.fporchoffbtn.controlup(self.lvroomoffbtn)
       self.fporchoffbtn.controlleft(self.fporchonbtn)
       self.fporchoffbtn.controldown(self.bporchoffbtn)
       self.fporchoffbtn.controlright(self.fporchdimbtn)
       self.fporchdimbtn.controlup(self.lvroomdimbtn)
       self.fporchdimbtn.controlleft(self.fporchoffbtn)
       self.fporchdimbtn.controldown(self.bporchdimbtn)
       self.bporchonbtn.controlup(self.fporchonbtn)
       self.bporchonbtn.controlleft(self.exitbtn)
       self.bporchonbtn.controlright(self.bporchoffbtn)
       self.bporchonbtn.controldown(self.spaonbtn)
       self.bporchoffbtn.controlup(self.fporchoffbtn)
       self.bporchoffbtn.controldown(self.spaoffbtn)
       self.bporchoffbtn.controlleft(self.bporchonbtn)
       self.bporchoffbtn.controlright(self.bporchdimbtn)
       self.bporchdimbtn.controlleft(self.bporchoffbtn)
       self.bporchdimbtn.controlup(self.fporchdimbtn)
       self.bporchdimbtn.controldown(self.spadimbtn)
     
       self.exitbtn.controlright(self.famonbtn)
       self.exitbtn.controldown(self.spaoffbtn)
       self.exitbtn.controlup(self.famonbtn)
       self.setfocus(self.famonbtn)

       self.getrstatus()


   def onaction(self, action):
       if action == action_previous_menu:
self.close()
   
   def oncontrol(self, control):
       if control == self.famonbtn:
   labelaction = "turn family room on";
   curaction = "module=a6&action=on";
           self.setfocus(self.famonbtn)
           self.getrhome()
       if control == self.famdimbtn:
           curaction = "dim=dim&module=a6&action=10";
           labelaction = "dim family room";
   self.getrhome()
           self.setfocus(self.famdimbtn)
       if control == self.famoffbtn:
           curaction = "module=a6&action=off";
           labelaction = "turn family room off";
           self.getrhome()
           self.setfocus(self.famoffbtn)
           
       if control == self.lvroomonbtn:
           curaction = "module=a2&action=on";
           labelaction = "turn living room on";
           self.getrhome()
           self.setfocus(self.lvroomonbtn)
       if control == self.lvroomoffbtn:
           curaction = "module=a2&action=off";
           labelaction = "turn living room off";
           self.getrhome()
           self.setfocus(self.lvroomoffbtn)
       if control == self.lvroomdimbtn:
           curaction = "dim=dim&module=a2&action=10";
           labelaction = "dim living room";
           self.getrhome()
           self.setfocus(self.lvroomdimbtn)    
                 
       if control == self.spaonbtn:
           curaction = "module=a5&action=on";
           labelaction = "turn spa tartag on";
   self.getrhome()
           self.setfocus(self.spaonbtn)
       if control == self.spaoffbtn:
           curaction = "module=a5&action=off";
           labelaction = "turn spa tartag off";
           self.getrhome()
           self.setfocus(self.spaoffbtn)
       if control == self.spadimbtn:
           curaction = "dim=dim&module=a5&action=10";
           labelaction = "dim spa tartag";
           self.getrhome()
           self.setfocus(self.spadimbtn)
                       
       if control == self.fporchonbtn:
           curaction = "module=a1&action=on";
           labelaction = "turn front porch lights on";
           self.getrhome()
           self.setfocus(self.fporchonbtn)
       if control == self.fporchoffbtn:
           curaction = "module=a1&action=off";
           labelaction = "turn front porch lights off";
           self.getrhome()  
           self.setfocus(self.fporchoffbtn)
       if control == self.fporchdimbtn:
           curaction = "dim=dim&module=a1&action=10";
           labelaction = "dim front porch lights";
           self.getrhome()  
           self.setfocus(self.fporchdimbtn)            
           
       if control == self.bporchonbtn:
           curaction = "module=a4&action=on";
           labelaction = "turn back porch lights off";
           self.getrhome()
           self.setfocus(self.bporchonbtn)
       if control == self.bporchoffbtn:
           curaction = "module=a4&action=off";
           labelaction = "turn back porch lights off";
           self.getrhome()
           self.setfocus(self.bporchoffbtn)
       if control == self.bporchdimbtn:
           curaction = "dim=dim&module=a4&action=10";
           labelaction = "dim back porch lights";
           self.getrhome()
           self.setfocus(self.bporchdimbtn)
global curaction
       global labelaction    
       
if control == self.exitbtn:
   self.close()


   def getrhome(self):
global curaction
dialog = xbmcgui.dialog()
progress = xbmcgui.dialogprogress()
progress.create("rhome control", "taking action: " + str(labelaction))
progress.update(10)

try:
#open socket with page url
rh_sock = urllib.urlopen(rhurl + str(curaction))
progress.update(30)
#rh_html = rh_sock.read()
progress.update(60)
rh_sock.close()
progress.update(90)
progress.close()
self.getrstatus()
self.lastact.reset()
self.lastact.addlabel("last action: " + str(labelaction))

except:
progress.close()
dialog.ok("rhome control","could not complete action: " + str(labelaction))

   def getrstatus(self):
try:
#open socket with page url
self.statlist.reset()
rh_sock2 = urllib.urlopen(rhurl2)
rh_html = rh_sock2.read()
rh_sock2.close()
housestatusre = re.compile('<tr><td>(.*?)</td></tr>')
housestatus = housestatusre.findall(rh_html)
resultlist = []
for info in housestatus:
title = info
self.statlist.additem(str(title))
except:
progress.close()
dialog.ok("rhome control","could not complete action: " + str(labelaction))


display_main = rhouse_main()
display_main.domodal()

del display_main

not sure this indented appropriatly-- let me know if there is a better way to post a script.

cheers,
-tartag



Reply
#11
tartag...

sorry for the delay, i've been slammed.

anyway, i don't have a pc with python conected to the x10 pli (power line interface) so i don't think this will work for me.

i do have homeseer 1.7 so if you can help integrate this into homeseer i'm usre you'd get some usage by users.

here's some example asp/html pages i run on the homeseer pc to create a gui, display status, and send commands.

the first screenshot is the link to download the code.

my homeseer webpage
I'm not an expert but I play one at work.
Reply
#12
hi folks,

first time posting here in scripts, but have a keen interest in getting xbmc to control my x-10 devices as well.  

i am currently running homeseer 1.7 on a windows xp computer.  much thanks to tartag and affini for answering a couple of questions and getting me started on the right path.  however, as soon as i started down the path, i think i took a hard left!

i have decided that with my homeseer setup it would be easiest to do as nickle and affini have suggested previously.... which is... create some .asp pages on my winxp machine since homeseer has a built in webserver and have those .asp pages run by calling them from a python script in xbmc.

well, i was able to get the very basic concept working in xbmc with a simple script:
i.e. the 2 line script below runs a simple .asp page on my winxp computer and turns on the x-10 device (a lamp in this case) assigned to code b2.

import urllib
urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])


my problem comes when i tried to create a more complex script for xbmc that has different .asp pages run when various buttons are pressed in xbmc.

the script is shown below and the page looks good when i run the script in xbmc.  the buttons show up, i can highlight and move up and down, etc...., however, when i select a button, nothing happens (although xbmc makes a clicking sound like the button was pressed).  

i would expect the
urllib.urlopen("[url]http://192.168.0.150:80/scott/dosomething.asp"[/url]) "command" to be executed just like it did in the simple script, but my ignorance of python has gotten the best of me.

this is my first python proggy ever, so can someone please show me, why i get no action on a button press in my if / elif statements?   any help would be greatly appreciated!

p.s.  i know this script has alot of extras in it and can be made much more efficient.... just trying to get the basic concept working first before messing with it too much.

Quote:##***************script starts here ************
import xml.dom.minidom, urllib, xbmc, xbmcgui
import urllib2, urlparse, string, textwrap, os, image
import htmllib, formatter, stringio, re
import socket, time, sys, threading

from string import split, replace, find
from xbmcgui import dialogprogress as xbmcguidialogprogress, window as xbmcguiwindow, lock as xbmcguilock, controlimage as xbmcguicontrolimage, controllabel as xbmcguicontrollabel, controlbutton as xbmcguicontrolbutton, controlcheckmark as xbmcguicontrolcheckmark, unlock as xbmcguiunlock, controlimage as xbmcguicontrolimage, controllist as xbmcguicontrollist, dialog as xbmcguidialog


try: emulating = xbmcgui.emulating
except: emulating = false

action_move_left        =  1    
action_move_right       =  2
action_move_up          =  3
action_move_down        =  4
action_page_up          =  5 #left trigger
action_page_down        =  6 #right trigger
action_select_item      =  7 #a button
action_highlight_item   =  8
action_parent_dir       =  9 #b button
action_previous_menu    = 10 #back button
action_show_info        = 11
action_pause            = 12
action_stop             = 13
action_next_item        = 14
action_prev_item        = 15
action_xbutton = 18 #y button
action_whitebutton = 117

## change to true to show debug information on the script console (white button when you are in the scripts window in xbmc)
debug = true


######### the below expression calls the .asp page and turns housecode b01 on like it is supposed to ##########
########### why won't the same expression work when a button press is executed (see further down in script)Huh
urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])


root = "f:\\xbmc\\media\\"


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

if emulating: xbmcgui.window.(self)

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

       self.currentstate = none
       self.selecteddistributor = -1

     
      self.addcontrol(xbmcgui.controlimage(0,0,1280,720, root + "background-x10.png"))
     
      self.addcontrol(xbmcgui.controlimage(int(100 * self.scalex),int(65 * self.scaley),int(670 * self.scalex),int(68 * self.scaley), root + "x10-topbar.gif"))
     
       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")


       # add buttons
       self.btnchristmason = xbmcguicontrolbutton(int(60*self.scalex), int(100*self.scaley), int(140*self.scalex), int(30*self.scaley), "christmas on")
       self.btnchristmasoff = xbmcguicontrolbutton(int(60*self.scalex), int(132*self.scaley), int(140*self.scalex), int(30*self.scaley), "christmas off")
       self.btnstudyon = xbmcguicontrolbutton(int(60*self.scalex), int(164*self.scaley), int(140*self.scalex), int(30*self.scaley), "study on")
       self.btnstudyoff = xbmcguicontrolbutton(int(60*self.scalex), int(196*self.scaley), int(140*self.scalex), int(30*self.scaley), "study off")
       self.btnporchon = xbmcguicontrolbutton(int(60*self.scalex), int(228*self.scaley), int(140*self.scalex), int(30*self.scaley), "porch on")
       self.btnporchoff = xbmcguicontrolbutton(int(60*self.scalex), int(260*self.scaley), int(140*self.scalex), int(30*self.scaley), "porch off")
       self.btnfoyeron = xbmcguicontrolbutton(int(60*self.scalex), int(324*self.scaley), int(140*self.scalex), int(30*self.scaley), "foyer on")
       self.btnfoyeroff = xbmcguicontrolbutton(int(60*self.scalex), int(356*self.scaley), int(140*self.scalex), int(30*self.scaley), "foyer off")
       self.btnlivingroomon = xbmcguicontrolbutton(int(60*self.scalex), int(388*self.scaley), int(140*self.scalex), int(30*self.scaley), "living room on")
       self.btnlivingroomoff = xbmcguicontrolbutton(int(60*self.scalex), int(388*self.scaley), int(140*self.scalex), int(30*self.scaley), "living room off")

       self.checkdownload = xbmcguicontrolcheckmark(int(71*self.scalex), int(439*self.scaley), int(120*self.scalex), int(20*self.scaley), "toggle test1", checkwidth=20, checkheight=20, alignment=0)
       self.checksave = xbmcguicontrolcheckmark(int(191*self.scalex), int(439*self.scaley), int(100*self.scalex), int(20*self.scaley), "toggle test2", checkwidth=20, checkheight=20, alignment=0 )

       self.labelstatus = xbmcguicontrollabel(int(300*self.scalex), int(439*self.scaley), int(150*self.scalex), int(20*self.scaley), "saving data files..." )

       self.addcontrol(self.btnchristmason)
       self.addcontrol(self.btnchristmasoff)
       self.addcontrol(self.btnstudyon)
       self.addcontrol(self.btnstudyoff)
       self.addcontrol(self.btnporchon)
       self.addcontrol(self.btnporchoff)
       self.addcontrol(self.btnfoyeron)
       self.addcontrol(self.btnfoyeroff)
       self.addcontrol(self.btnlivingroomon)
       self.addcontrol(self.btnlivingroomoff)
       self.addcontrol(self.checkdownload)
       self.addcontrol(self.checksave)


       self.btnchristmason.controlup(self.checkdownload)
       self.btnchristmason.controldown(self.btnchristmasoff)
       self.btnchristmasoff.controlup(self.btnchristmason)
       self.btnchristmasoff.controldown(self.btnstudyon)
       self.btnstudyon.controlup(self.btnchristmasoff)
       self.btnstudyon.controldown(self.btnstudyoff)
       self.btnstudyoff.controlup(self.btnstudyon)
       self.btnstudyoff.controldown(self.btnporchon)
       self.btnporchon.controlup(self.btnstudyoff)
       self.btnporchon.controldown(self.btnporchoff)
       self.btnporchoff.controlup(self.btnporchon)
       self.btnporchoff.controldown(self.btnfoyeron)
       self.btnfoyeron.controlup(self.btnporchoff)
       self.btnfoyeron.controldown(self.btnfoyeroff)
       self.btnfoyeroff.controlup(self.btnfoyeron)
       self.btnfoyeroff.controldown(self.btnlivingroomon)
       self.btnlivingroomon.controlup(self.btnfoyeroff)
       self.btnlivingroomon.controldown(self.checkdownload)
       self.checkdownload.controlup(self.btnlivingroomon)
       self.checkdownload.controldown(self.btnchristmason)
       self.checkdownload.controlright(self.checksave)
       self.checksave.controlup(self.btnlivingroomon)
       self.checksave.controldown(self.btnchristmason)
       self.checksave.controlleft(self.checkdownload)

     
       self.setfocus(self.btnchristmason)


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


       def oncontrol(self, control):
               if control == self.btnchristmason:
                        printdebug('christmas on button pressed.')
                        urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
               elif control == self.btnchristmasoff:
                       printdebug('chrismtas off button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b01off.asp"[/url])
               elif control == self.btnstudyon:
                       printdebug('study on button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])
               elif control == self.btnstudyoff:
                       printdebug('study off button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b02off.asp"[/url])
               elif control == self.btnporchon:
                       printdebug('porch on button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b03on.asp"[/url])
               elif control == self.btnporchoff:
                       printdebug('porch off button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b03off.asp"[/url])
               elif control == self.btnfoyeron:
                       printdebug('foyer on button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b04on.asp"[/url])
               elif control == self.btnfoyeroff:
                       printdebug('foyer off button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b04off.asp"[/url])
               elif control == self.btnlivingroomon:
                       printdebug('living room on button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b05on.asp"[/url])
               elif control == self.btnlivingroomoff:
                       printdebug('living room off button pressed.')
                       urllib.urlopen("[url]http://192.168.0.150:80/scott/b05off.asp"[/url])

               elif control == self.checksave:
                       printdebug('save checkbox pressed.')
                       if self.checksave.getselected():
                               self.checksave.setselected(true)
                               urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
               elif control == self.checkdownload:
                       printdebug('download checkbox pressed.')
                       if self.checkdownload.getselected():
                               self.checkdownload.setselected(true)
                               urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])  


#                       tried open socket with page url, but this did not work
# rh_sock = urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
# rh_html = rh_sock.read()
# rh_sock.close()                


display_main = rhouse_main()
display_main.domodal()

del display_main
##*****************end of script***********

edit:  i put the script code that did not work in quotes to make it easier to read.  see notes in later post(s) - a similar but different script is now working, but not sure why .... more to come....



Reply
#13
i don't know any python but what you need to do is figure out how to send an asp command like below from python code...

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

forget making your own asp pages unless you are using a browser. for that matter just mod the pages i posted. they work very well and not bad to look at either.
I'm not an expert but I play one at work.
Reply
#14
affini,

thanks for your response. i actually have the asp pages already built and working, but i will have to look into the command you suggestioned as well. either will work as long as i can figure out why i am not getting any action on a button push event in the python script.

hoping someone with some python scripting knowledge can point out why the buttons aren't working in my previous post.

please help !!!

merry christmas!

buzzster
Reply
#15
hi buzzster.
do you have that printdebug function defined anywhere? i don't see it but it should just be
Quote:def printdebug(str):
if debug:
print str
also it's weird that your constructor isnt named , does it work like that? it's probably ok.

you also always want to call close() on the returned object from urlopen. also be careful of typos... an undefined name will cause the python engine to crash without necessarily bringing down the gui (the program will seem unresponsive and you need to reset). hope that helps!

-ast

edit ok when i type underscore,underscore,init,underscore,underscore the forum strips it for some crazy reason so i guess your constructor is fine



Reply

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