Controlling Indigo from Command Line (or .py files)

Posted on
Wed Aug 24, 2011 4:39 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Controlling Indigo from Command Line (or .py files)

I've updated the Plugin Scripting Tutorial to show how you can now pass Indigo commands (and python source) to Indigo, and how you can execute Indigo python files. See the tutorial for the details on setting up an indigohost shell alias, but below are a few examples.

Get the current brightness of the device “office lamplinc”:

Code: Select all
indigohost -e 'return indigo.devices["office lamplinc"].brightness'

Toggle the device “office lamplinc” three times:

Code: Select all
indigohost -e '
indigo.device.toggle("office lamplinc")
indigo.device.toggle("office lamplinc")
indigo.device.toggle("office lamplinc")
'

Execute an Indigo python file:

Code: Select all
indigohost -x /SomeFolder/indigo_script.py'

Note there is some overhead each time you call indigohost since it creates a new process and has to establish a connection to the Indigo Server.

Embedded python scripts inside Indigo actions (schedules, triggers, etc.) don't have this overhead because they all share a single indigohost (IPH) process, but because of this the Indigo Server only allows embedded python scripts 10 seconds to execute. If they take more than 10 seconds, then they should be broken out into a .py file which will create a new process (but have the overhead of having to establish a new Indigo Server connection).

Image

Posted on
Fri Jul 05, 2013 10:23 am
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Controlling Indigo from Command Line (or .py files)

How do I pass command-line arguments to a Python script written for IndigoPluginHost? If I pass arguments to it, it says "multiple occurrences" (huh?).

How do I make a #! script for IndigoPluginHost?

What does the -f option do? It's in IndigoPluginHost's help message, but I can't find an explanation.

Cheers
-- perry

Posted on
Sun Jul 07, 2013 1:43 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Controlling Indigo from Command Line (or .py files)

Perry The Cynic wrote:
How do I pass command-line arguments to a Python script written for IndigoPluginHost?

The plugin host that executes the python script doesn't currently accept additional (script) arguments.

Perry The Cynic wrote:
How do I make a #! script for IndigoPluginHost?

shebangs cannot have spaces (escaping and quoting doesn't work), so you have to create a link to the IPH bundle:

Code: Select all
sudo ln -s /Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app /usr/bin/indigohostapp

Then you can use a shebang like this:

Code: Select all
#!/usr/bin/indigohostapp/Contents/MacOS/IndigoPluginHost -x

indigo.device.toggle(1221944241)


Perry The Cynic wrote:
What does the -f option do? It's in IndigoPluginHost's help message, but I can't find an explanation.

It is used internally by the Indigo Server when launching plugins, so should not be specified. It might someday be used to launch plugins on remote clients, but that isn't fully supported yet.

Image

Posted on
Mon Dec 23, 2013 3:54 pm
cec offline
Posts: 7
Joined: Feb 27, 2012

Re: Controlling Indigo from Command Line (or .py files)

Hi,
I'm running Indigo 6.0.7 and want to work with Python to update Indigo variables. I followed the tutorial and put the alias in my .bashrc file, but when I try to either execute a .py script or just do the interactive test as shown on the website, I get immediately a 'connection closed' error followed by a 'received quit signal.'

here is a relevant screen trace (terminal on a Mac OS 10.8.5):

------------------------
CeC$ cat .bashrc
echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 5/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bashrc
CeC$ indigohost -i
2013-12-23 15:47:05.188 IndigoPluginHost[20689:707] connection to server was closed
2013-12-23 15:47:05.287 IndigoPluginHost[20689:707] Quiting Indigo Plugin - received quit signal
CeC$
------------------------

I've looked at Indigo preferences and the start server screen but I don't see anything there that looks related to Python.

What am I doing wrong?
Thanks!
CeC

Posted on
Mon Dec 23, 2013 7:23 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Controlling Indigo from Command Line (or .py files)

If you are running Indigo 6, then the alias should point to the Indigo 6 folder:

Code: Select all
echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bashrc


Note that line appends the alias to your .bashrc file, so you are probably going to need to open it in a text editor and delete the previous/old paths.

Does that fix the problem?

Image

Posted on
Mon Dec 23, 2013 10:30 pm
cec offline
Posts: 7
Joined: Feb 27, 2012

Re: Controlling Indigo from Command Line (or .py files)

Thanks Matt-

I was editing .bashrc but I also had a .bash_profile which had the alias to Indigo 5, thus changing .bashrc didn't fix things but changing .bash_profile did.

Thanks!
CeC

Posted on
Wed Dec 25, 2013 10:00 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Controlling Indigo from Command Line (or .py files)

How would I retrieve a plugin preference via the IndigoPluginHost command line?

Posted on
Thu Dec 26, 2013 11:30 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Controlling Indigo from Command Line (or .py files)

Code: Select all
plugin = indigo.server.getPlugin("com.some.plugin.key.as.defined.in.its.plist")
prefVal = plugin.pluginPrefs["somePrefKey"]
return prefVal  # or maybe print(prefVal)

Image

Posted on
Thu Dec 26, 2013 11:41 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Controlling Indigo from Command Line (or .py files)

I did try something similar. I think I'm missing something obvious so pardon my ignorance. Here is my result:

Code: Select all
>>> sp = indigo.server.getPlugin("com.ssi.indigoplugin.Sonos")
>>> print sp
pluginDisplayName : Sonos
pluginId : com.ssi.indigoplugin.Sonos
pluginSupportURL : https://vulture.lagaros.com/wiki/projects/homeautomation/Home_Automation.html
pluginVersion : 0.6.9
>>> a = sp.pluginPrefs["rootZPIP"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'PluginInfo' object has no attribute 'pluginPrefs'
>>>


matt (support) wrote:
Code: Select all
plugin = indigo.server.getPlugin("com.some.plugin.key.as.defined.in.its.plist")
prefVal = plugin.pluginPrefs["somePrefKey"]
return prefVal  # or maybe print(prefVal)

Posted on
Thu Dec 26, 2013 11:49 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Controlling Indigo from Command Line (or .py files)

Doh. You aren't missing anything. That plugin object returned from that lookup is just a thin shim that contains a few attributes (pluginId, pluginDisplayName, pluginVersion, isEnabled) and not the full instance. It will take some additional plumbing work on our end to expose the preferences dict.

If you really need access to the prefs, then you could read the file directly from:

/Library/Application Support/Perceptive Automation/Indigo 6/Preferences/Plugins/com.ssi.indigoplugin.Sonos

Image

Posted on
Thu Dec 26, 2013 11:56 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: Controlling Indigo from Command Line (or .py files)

Perfect - I can definitely go directly to the preferences file. Thanks.

matt (support) wrote:
Doh. You aren't missing anything. That plugin object returned from that lookup is just a thin shim that contains a few attributes (pluginId, pluginDisplayName, pluginVersion, isEnabled) and not the full instance. It will take some additional plumbing work on our end to expose the preferences dict.

If you really need access to the prefs, then you could read the file directly from:

/Library/Application Support/Perceptive Automation/Indigo 6/Preferences/Plugins/com.ssi.indigoplugin.Sonos

Posted on
Wed Jun 01, 2016 8:05 am
RedYuriPrime offline
Posts: 58
Joined: Oct 14, 2014
Location: Oxford

Re: Controlling Indigo from Command Line (or .py files)

Hi,

I am trying to simplify, replacing an action group which starts a number of python code modules using the format 'execute linked script file 'Heating.py' etc. and initiating all these from a single python script, itself initiated by a trigger.

Reading this topic (and relying on the title of it), it seems to suggest using the format:
indigohost -x/path/pythonfile.py'

However I get the error that indigohost is not a known command.

I also tried using the route of importing the additional modules, but then modlues which otherwise run fine started throwing errors at the command 'return', which suggests they are not running in the correct environment

What command should I be using?

Thanks

Z-wave system with 80+ devices, Indigo7 on a dedicated MacMini
Controlling lighting, heating, hotwater, security; but still a lot to learn ... :shock:

Posted on
Wed Jun 01, 2016 9:17 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Controlling Indigo from Command Line (or .py files)

If you're trying to do this from inside an Indigo trigger, that's the wrong thing to do. Any external round trip is going to be more complicated than just doing what you need to do in the trigger actions.

Why not just put those scripts in the action itself? Is there some reason they have to be external files? Or just put multiple actions on the trigger, each calling an external script like you're doing in the action group now?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Jun 01, 2016 9:48 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Controlling Indigo from Command Line (or .py files)

RedYuriPrime wrote:
indigohost -x/path/pythonfile.py'

However I get the error that indigohost is not a known command.


I agree with @FlyingDiver's questions - I think knowing a bit more about exactly what you're wanting to do may lead to a much simpler solution.

However, to answer your specific question, you need to provide the full path to the command that starts up the IndigoPluginHost process:

Code: Select all
/Library/Application\ Support/Perceptive\ Automation/Indigo\ 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -x /path/to/pythonfile.py


The command used in this thread assumes you've set up the alias as described in the Python Scripting Tutorial.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 01, 2016 11:31 am
RedYuriPrime offline
Posts: 58
Joined: Oct 14, 2014
Location: Oxford

Re: Controlling Indigo from Command Line (or .py files)

Thanks for the immediate feedback - I haven't managed to try Jay's solution yet as TeamViewer is down across half the world, and my MAC runs headless. However, in response to the request for more info on the problem:

The problem:
On a reboot after a power failure, Indigo needs to resume all services. Services are provided by a series of python scripts (modules) that run in continuous loops - this makes managing variables somewhat easier than having to save and reload each time the modules are triggered by a schedule. There are several different modules because they provide very different functions -one runs heating, one runs security, etc. and it is easier to maintain them by separating the logical functions, which work on different timescales in any event.

Indigo can provides a trigger as it starts up, which I can use to trigger an initial python script to reset various indigo stored variables as required - I then want that same python script to start up the other python modules. At the moment I use the rather inelegant solution of having an Action Group with a series of actions each running the server action of running on of the python modules.
Hence, I am seeking the code to put in a python script which initiates another python script under exactly the same environment as it if was initiated by the server action in an Action Group.

Hope that clarifies.

Z-wave system with 80+ devices, Indigo7 on a dedicated MacMini
Controlling lighting, heating, hotwater, security; but still a lot to learn ... :shock:

Who is online

Users browsing this forum: No registered users and 4 guests