Launch indigohost from within python script

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
nlagaros
Posts: 1646
Joined: Mon Dec 20, 2010 2:16 pm

Launch indigohost from within python script

Post by nlagaros »

I'm just a beginner with python and am not up to creating a plugin just yet. I would like to access Indigo from within an existing python script I have so I can write to variables and turn devices on and off. Is there an easy way to launch indigohost and execute a command?
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Launch indigohost from within python script

Post by matt (support) »

We are in the process of adding an option to the Execute Action UI so that you can execute an Indigo python script (embedded or via a file) in addition to AppleScript. Once that is done it will be easy, but until then it is only possible via a plugin or the interactive shell.
Image
nlagaros
Posts: 1646
Joined: Mon Dec 20, 2010 2:16 pm

Re: Launch indigohost from within python script

Post by nlagaros »

Don't think that would work for this particular application. I have an always running server app that I would never launch from within Indigo - unless I went the plugin route. Guess I will have to investigate plugins. I have scripts that I use for the Russound RNET that I've been playing with - I will have a pretty neat control page for it soon enough.
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Launch indigohost from within python script

Post by matt (support) »

A native plugin would be the optimal approach, but there might be some other approaches as well eventually. Let me think about it for a bit.
Image
jamus
Posts: 179
Joined: Sat Dec 01, 2007 9:34 am

Re: Launch indigohost from within python script

Post by jamus »

nlagaros wrote:I'm just a beginner with python and am not up to creating a plugin just yet. I would like to access Indigo from within an existing python script I have so I can write to variables and turn devices on and off. Is there an easy way to launch indigohost and execute a command?
Have you looked at the RESTful API? In Indigo 4, I used it primarily to update variables, but it's possible to turn devices on and off too. Here's some code I used to update variables:

Code: Select all

def setVariable(host,port,root,variable,value):
            conn = httplib.HTTPConnection(host,port)
            params = urllib.urlencode({'value':value})
            headers = {"Content-type": "application/x-www-form-urlencoded"}
            url=root+"/variables/"+variable
            conn.request("PUT",url,params,headers)
            response = conn.getresponse()
            if (response.status==303):
              conn.close
              return response
            print "Problem setting "+variable+" to "+str(value)+": "+str(response.status)+" "+response.reason
            print response.read()
            conn.close()
            return response
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Launch indigohost from within python script

Post by matt (support) »

Oh yeah, I had forgotten about that. Great suggestion I think for what he is looking for.
Image
nlagaros
Posts: 1646
Joined: Mon Dec 20, 2010 2:16 pm

Re: Launch indigohost from within python script

Post by nlagaros »

That did the trick! Thanks!
bschollnick2
Posts: 1355
Joined: Sun Oct 17, 2004 8:21 am
Location: Rochester, Ny
Contact:

Re: Launch indigohost from within python script

Post by bschollnick2 »

jamus wrote:
nlagaros wrote:I'm just a beginner with python and am not up to creating a plugin just yet. I would like to access Indigo from within an existing python script I have so I can write to variables and turn devices on and off. Is there an easy way to launch indigohost and execute a command?
Have you looked at the RESTful API? In Indigo 4, I used it primarily to update variables, but it's possible to turn devices on and off too. Here's some code I used to update variables:
Jamus,

Don't forget, I have a unofficial Restful wrapper for Indigo already constructed in Python.
Restful Link

The main benefit, is that I've already done much of the work, and it's a bit more abstracted... And completely reusable, as a standalone module.
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33
nlagaros
Posts: 1646
Joined: Mon Dec 20, 2010 2:16 pm

Re: Launch indigohost from within python script

Post by nlagaros »

Thanks for all the help. I shelled out to curl initially, but this wrapper looks perfect.
bschollnick2
Posts: 1355
Joined: Sun Oct 17, 2004 8:21 am
Location: Rochester, Ny
Contact:

Re: Launch indigohost from within python script

Post by bschollnick2 »

nlagaros wrote:Thanks for all the help. I shelled out to curl initially, but this wrapper looks perfect.
Feel free to give me feedback, it was designed with Indigo 4 in mind, but v5 features can be added as well...
And feel free to send suggestions for code, etc...
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33
jamus
Posts: 179
Joined: Sat Dec 01, 2007 9:34 am

Re: Launch indigohost from within python script

Post by jamus »

bschollnick2 wrote:Jamus,

Don't forget, I have a unofficial Restful wrapper for Indigo already constructed in Python.
Restful Link

The main benefit, is that I've already done much of the work, and it's a bit more abstracted... And completely reusable, as a standalone module.
Yep, I completely forgot, which I feel terrible about because we had a discussion on this forum about the Python API a while back. :(

I think there's still use for your API in 5.0. I get the impression that remote access via python, if even possible, would require an indigo installation to get the necessary modules. I haven't had a chance to read through all the documentation, so I could be mistaken.
bschollnick2
Posts: 1355
Joined: Sun Oct 17, 2004 8:21 am
Location: Rochester, Ny
Contact:

Re: Launch indigohost from within python script

Post by bschollnick2 »

jamus wrote:
bschollnick2 wrote:Jamus,

Don't forget, I have a unofficial Restful wrapper for Indigo already constructed in Python.
Restful Link

The main benefit, is that I've already done much of the work, and it's a bit more abstracted... And completely reusable, as a standalone module.
Yep, I completely forgot, which I feel terrible about because we had a discussion on this forum about the Python API a while back. :(

I think there's still use for your API in 5.0. I get the impression that remote access via python, if even possible, would require an indigo installation to get the necessary modules. I haven't had a chance to read through all the documentation, so I could be mistaken.
Not with the Restful API Wrapper. It's completely independent of Indigo.. It's effectively just using the Python equivalent of CURL to communicate with Indigo.

- Benjamin
------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33
jamus
Posts: 179
Joined: Sat Dec 01, 2007 9:34 am

Re: Launch indigohost from within python script

Post by jamus »

bschollnick2 wrote:
jamus wrote: I think there's still use for your API in 5.0. I get the impression that remote access via python, if even possible, would require an indigo installation to get the necessary modules. I haven't had a chance to read through all the documentation, so I could be mistaken.
Not with the Restful API Wrapper. It's completely independent of Indigo.. It's effectively just using the Python equivalent of CURL to communicate with Indigo.

- Benjamin
I meant that remote access with the official Python API may not be possible or require an indigo installation.
Locked

Return to “Extending Indigo with Plugins and Python”