Dipping a toe in, floundering

Posted on
Sun Sep 10, 2017 3:27 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Dipping a toe in, floundering

I can probably file this under "a little knowledge is a dangerous thing"

Trying to create a shell script that sends python to Indigo.
Code: Select all
#!/bin/sh
python indigo.actionGroup.execute(17622409777)

this results in
Code: Select all
Indigo:~ name$ ./kbutton*t
./kbutton.scpt: line 2: syntax error near unexpected token `('


How stupid am I? More to the point, what did I get wrong?

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 10, 2017 4:12 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Dipping a toe in, floundering

i don't think you can from outside indigo start something inside indigo.

the plugin SATI http://forums.indigodomo.com/viewforum.php?f=185 creates a framework that will read files in
~/documents/sati/fromAS-# ;;; # =1-16

then execute that command from these files within indigo


available commands:
Code: Select all
commands in input file fromAS-n supported:

getVariable;:;:;variableName/id
setVariable;:;:;variableName;:;:;value
getDeviceState;:;:;deviceName/id;:;:;stateName

action group
exeAction;:;:;actionName/id

device on/off
turnDeviceOn;:;:;deviceName/id
turnDeviceOff;:;:;deviceName/id

digital output devices
setBinaryOutputOn;:;:;deviceName/id;:;:;index of output pin
setBinaryOutputOff;:;:;deviceName/id;:;:;index of output pin

dimmer
setBrightness;:;:;deviceName/id;:;:;value (0-100)

Thermostats
setHeatSetpoint;:;:;deviceName/id;:;:;value
setCoolSetpoint;:;:;deviceName/id;:;:;value
setFanModeOn;:;:;deviceName/id
setFanModeAuto;:;:;deviceName/id



and for subscriptions:
subscribeDeviceState;:;:;deviceName/id;:;:;stateName;:;:;channel
subscribeDeviceStateDelete;:;:;deviceName/id +stateName
subscribeVariable;:;:;variableName/id;:;:;channel
subscribeVariableDelete;:;:;variableName/id

and for python execute:
execCmd;:;:;pythonCode

devName and varName and actName  can be strings or IDs



";:;:;" is used as a separator

syntax is:
Code: Select all
command separator arguments


to execute action group "abc"
put
Code: Select all
"exeAction;:;:;abc"
without the "
into file ~/documents/sati/fromAS-1

then the action group abc will be executed.

It was written for AppleScript for 2 way communication to be able to talk to indigo circumventing the "application not active error", but can be used for anything that can create a file.

Karl
Last edited by kw123 on Sun Sep 10, 2017 4:16 pm, edited 1 time in total.

Posted on
Sun Sep 10, 2017 4:15 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Dipping a toe in, floundering

and to initiate python it is:
Code: Select all
 python code.py arg1 agr1 agr2

Posted on
Sun Sep 10, 2017 4:48 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Dipping a toe in, floundering

kw123 wrote:
i don't think you can from outside indigo start something inside indigo.


Actually, you can just use the IndigoPluginHost to execute a script. Start by creating the indigohost alias (I put that in my .profile so it's always available).

Next, take a look at the args for indigohost:

Code: Select all
FatBook:~ jay$ indigohost --help
Allowed options:
  --help                       show this help message
  -f [ --folder ] arg          target plugin folder name (default arg)
  -i [ --interactive ]         run in interactive shell mode
  -d [ --debug_mode ] arg (=0) debugging mode selector
  -e [ --emb_script ] arg      execute arg as embedded script source
  -x [ --ext_script ] arg      execute the target file path arg as an external
                               script
  -p [ --port ] arg (=1176)    indigo server port number


Next, just call it with your script using the -e option:

Code: Select all
indigohost -e 'indigo.actionGroup.execute(17622409777)'


Which you can call from a bash script if you want. Note, you can also use this with the -x option to execute an Indigo Python script in a different file (see the args above).

If we had some more context, we might be able to make it even easier... 8)

Advanced Tip

One more cool thing that I don't think is mentioned anywhere else: if you want an Indigo python script to be executable from a shell by changing it's mode to executable, you can do that too. First, create a link to a path that does not contain spaces. I put it:

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


This creates a path without spaces, which is important for the shebang to work at the top of an Indigo Python script. Add it:

Code: Select all
#!/usr/local/bin/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -x


to the top of the script, make the script executable, and it will now behave like any other unix command. For instance, I have this script:

Code: Select all
#!/usr/local/bin/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost -x
from time import sleep
indigo.server.log("Starting script")
for i in range(20, 0, -1):
    indigo.server.log("countdown: {}".format(i))
    sleep(1)


saved in ~/jay/Projects/Indigo Scripts/simple_sleep.py. I changed it so that it's executable:

Code: Select all
chmod +x ~/Projects/Python/Indigo/simple_sleep.py


so now I can just do:

Code: Select all
FatBook:Indigo jay$ ./simple_sleep.py


to run the script. This is useful for other utilities that may require you to specify a single unix command.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Sep 10, 2017 8:10 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Dipping a toe in, floundering

Cool did not know that.


Sent from my iPhone using Tapatalk

Posted on
Sun Sep 17, 2017 9:21 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

jay (support) wrote:
If we had some more context, we might be able to make it even easier... 8).


I got some of those Flic buttons, and they work by triggering scripts. So I need a scripted way of making an action group trigger. Easy for me to do with an AppleScript workflow, but I figured this would be a good way to start learning how to do the same thing with Python.

also I don't mean to sound ungrateful, but the stuff KW wrote is meaningless to me and to continue the "dipping a toe in" metaphor, only seems to me like a suggestion to scuba dive in the deep end.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 9:29 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

@jay, I tried
Code: Select all
echo "alias indigohost='/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost'" >> ~/.bashrc

and after exit, then closing the remote terminal window and opening another to try "indigohost -i", I get
Code: Select all
-bash: indigohost: command not found


Does this not work remotely? My Indigo box is headless.

Never mind. I got it. I see my default shell wasn't bash for some reason.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 9:47 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

and now I try it and get
Code: Select all
Connected to Indigo Server v7.0.3, api v2.0 (localhost:1176)
>>> indigohost -e 'indigo.actionGroup.execute(1761409777)'
  File "<console>", line 1
    indigohost -e 'indigo.actionGroup.execute(1761409777)'
                                                         ^
SyntaxError: invalid syntax
>>>

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 10:03 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Dipping a toe in, floundering

It looks like the above you executed in the Indigo plugin scripting shell (opened via the Plugins->Open Scripting Shell menu). Inside that shell the indigo namespace is available, so you would just use:

indigo.actionGroup.execute(1761409777)

If you are trying to execute it from a normal bash shell (either Terminal or script), then you need the indigohost -e which is used to pass the command through to Indigo's scripting shell where the indigo namespace is available.

Image

Posted on
Sun Sep 17, 2017 10:09 am
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

matt (support) wrote:
It looks like the above you executed in the Indigo plugin scripting shell (opened via the Plugins->Open Scripting Shell menu). Inside that shell the indigo namespace is available, so you would just use:

indigo.actionGroup.execute(1761409777)

OK, that worked once I had the shell running.
matt (support) wrote:
If you are trying to execute it from a normal bash shell (either Terminal or script), then you need the indigohost -e which is used to pass the command through to Indigo's scripting shell where the indigo namespace is available.


My script (and note, it's a script I'm trying to call) looks like
Code: Select all
#!/bin/bash
indigohost -e 'indigo.actionGroup.execute(1761409777)'
fails with
Code: Select all
./kbutton.scpt: line 2: indigohost: command not found
it's almost like I have two different bash shells installed. Is that possible?

Doesn't seem to be so:
Code: Select all
bash-3.2$ finger md
Login: md                     Name: Mike D
Directory: /Users/md              Shell: /bin/bash


but somehow, my script can't find the indigohost, while I can manually on the command line.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 11:07 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Dipping a toe in, floundering

Remember, you created the indigohost alias in the interactive shell you're running when you log in (via .bashrc). When you execute a shell script the way you have it set up, it's starting a different bash shell process to run the script which doesn't run your local .bashrc, and that shell doesn't know what indigohost is.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Sep 17, 2017 12:35 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

gotcha.

I know this is outside of straight indigo support, but I'm unclear how to fix this, or even what terms I should search for. How can I tell ALL bash shells where indigohost is, or alternately, specify something besides /bin/bash in the script? No idea what else I would be pointing the script to.

Or should I just put the full path to the command in the script? That seems cumbersome, given that with the equipment I have now (3 Flic buttons) I may ultimately have 9 different scripts. Buttons support 3 actions each.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 12:46 pm
Different Computers offline
User avatar
Posts: 2541
Joined: Jan 02, 2016
Location: East Coast

Re: Dipping a toe in, floundering

I went ahead and put the full indigohost path in, and now it works.

Thanks for everyone's help, and if you can point me to a resource for learning how to alias this for all shells, I would appreciate it!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Sun Sep 17, 2017 2:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Dipping a toe in, floundering

Again, depending on the exact scenario, you can also follow the Advanced Tip from my post above. That would potentially keep you from having to wrap Indigo python calls in shell scripts by allowing Indigo Python scripts to be executed directly (no aliases needed).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests