Categories: Uncategorized

ISY Python Script for controlling media lights via xbmc

Here is a simple python script to use the REST code in the ISY (http://universal-devices.com) to control devices that are linked. I’m designing this script to be used inside a script for xbmc. here’s the first part of it. I recommend using scenes for the devicedim, deviceoff, and deviceon array, however you can use the individual devices as well in the array.


import urllib2
import urllib
import sys

devicedim = ['41941']
deviceoff = ['48839']
deviceon = ['62270']
username = 'admin'
password = 'admin'

topurl = 'http://isy'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, topurl, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
	
if sys.argv[1] == 'playing':
	for devicex in deviceoff:
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DOF'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
	for devicex in devicedim:
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DON/64'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
elif sys.argv[1] == 'stopped':
	for devicex in deviceon:
		print (devicex)
		theurl = 'http://isy/rest/nodes/' + devicex + '/cmd/DON'
		#normalize the URL
		theurl = urllib.quote(theurl, safe="%/:=&?~#+!$,;'@()*[]")
		print (theurl)
		pagehandle = urllib2.urlopen(theurl)
else:
	print 'no state given'

Usage:

isy-medialights.py playing|stopped
TomLasswell

Share
Published by
TomLasswell

Recent Posts

Autotask: PowerShell: Enable Client Portal for all users

This is a quick one, it's been forever since I've posted here. After moving back…

2 years ago

PowerShell :: Get Exchange Mailboxes Over XXGB

Simple command turned crazy. I ended up coming up with this due to the fact…

4 years ago

PowerShell: ConnectWise Documents API, Uploading a document or attachment to a ticket

Phew, this one took a minute to figure out. ConnectWise has a form based documents…

6 years ago

PowerShell: ConnectWise REST API Query Contacts by Email Address

I've found myself at a new job, recreating many of the processes that I spent…

6 years ago

First post in a long time — changing hosting providers

Wow, it's been a while since I've done a real post on this site. I've…

7 years ago

Powershell: AutoTask – Get Picklist Values

When using AutoTask's API it's required to lookup a various amount of picklist values that…

10 years ago