Newbie Python Question about Controlling Indigo from Outside

Posted on
Sun Apr 17, 2016 3:01 pm
blueballsius offline
Posts: 16
Joined: Feb 09, 2015

Newbie Python Question about Controlling Indigo from Outside

Sorry if this is posted somewhere, but i read through all 5 pages of Python posts and all of the Python scripting tutorials could not find an answer.

I can control Indigo from the IPH, but am not sure how to control it by executing a python script.

I just want to toggle a light.

In IPH i can successfully toggle the light using the following command:

indigo.device.toggle("Theater Light")

what do i need to add to be able to toggle this light by executing a python script outside of Indigo? Many Thanks for your help.

Posted on
Sun Apr 17, 2016 3:41 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Newbie Python Question about Controlling Indigo from Out

You can send commands to Indigo using the Restful API through calls to urllib2 or Curl.

Dave

[ETA] If digest authentication is being used (and it should be) you'll need something that supports it (like the requests module below.)
Last edited by DaveL17 on Sun Apr 17, 2016 7:40 pm, edited 1 time in total.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Apr 17, 2016 5:14 pm
blueballsius offline
Posts: 16
Joined: Feb 09, 2015

Re: Newbie Python Question about Controlling Indigo from Out

Thanks Dave. Unfortunately, i don't know how to do that either. Could you please give me an example of what the whole code should look like to turn a device on or off or toggle from outside of Indigo?

Posted on
Sun Apr 17, 2016 6:10 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Newbie Python Question about Controlling Indigo from Out

Here's a link to the Restful API wiki:
http://wiki.indigodomo.com/doku.php?id=indigo_s_restful_urls

I've never done Restful calls before, and there may be better ways to do it, but this works and runs quickly:
Code: Select all
import requests
from requests.auth import HTTPDigestAuth

url = 'http://indigo_server_url:8176/devices/device_name_goes_here?toggle=1&_method=put'
requests.get(url, auth=HTTPDigestAuth('username', 'password'))

Note that if you use spaces or special characters in your device names, you'll have to encode those:
Living Room - Vase becomes Living%20Room%20%2D%20Vase for example. A quick Google search will give you tips on encoding URLs.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 18, 2016 9:24 am
blueballsius offline
Posts: 16
Joined: Feb 09, 2015

Re: Newbie Python Question about Controlling Indigo from Out

Thanks a lot for your help, Dave. I still didn't quite get it to work, but luckily the sudo command that Matt just posted in -600 error/apple script thread seems to have cured my applescript errors, so i'm back to using AS, which i am much more comfortable with. Thanks again.

Posted on
Tue Apr 19, 2016 8:21 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Newbie Python Question about Controlling Indigo from Out

Is the python script running on a different Mac? If it is on the same Mac, then you can have Indigo execute it from the Execute Script action, either embedded in the edit field of that action panel or as an external file. You can also use the indigohost process to execute the script. There are some examples here. Note indigohost is really an alias to a binary inside the IndigoPluginHost.app package. Near the top of that wiki page it shows how to create the alias in your .bashrc file so it can be accessed more easily.

All the above techniques automagically make available the python indigo module. It is actually embedded inside the indigohost. It handles the communication with the IndigoServer and provides all the indigo API calls. Currently the only way to get access to that module is by executing the script from Indigo or via the indigohost process. That is, there is no way to import the indigo module into a python script that isn't running inside the indigohost. If that is a requirement then using the much more limited RESTful API is a good approach.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests