Page 1 of 1

Need help sorting out workflow

PostPosted: Sun Nov 26, 2017 11:05 pm
by tornado
Hi everyone,

Would like some assistance thinking something through. On my Raspberry Pi I have wired it to get a zone trigger for an alarm. I would like to ultimately send a notification to Indigo with the zone that 'fired'.

The current RPi script is a Python one. In it, I was calling an ssh shell script on the Mac mini Indigo server with the zone as a parameter. My problem is passing the parameter into Indigo. From what I can tell, it appears that I have to write 16 different .py files out instead of passing a parameter, which will then trigger the appropriate trigger/action group within Indigo. I'd love to pass the zone as a parameter, and then act upon the trigger in Indigo.

I keep running up against IndigoPluginHost and not being able to pass a parameter through it. Can anyone think of a better way than what I'm thinking, short of writing 16 different files for each alarm zone?

Thanks in advance,
Joe
P.S. I'd rather not use AppleScript to do this if possible.

Re: Need help sorting out workflow

PostPosted: Sun Nov 26, 2017 11:36 pm
by matt (support)
Take a look at this example on the scripting tutorial page.

First note, "indigohost" is just an alias to the IndigoPluginHost executable (higher up on that page it shows how it is defined). Using the -e command line argument you can pass the python code you want the IPH to execute. So in your example you probably want to device different Action Groups in Indigo and then just pass in to the IPH which one to execute like this:

indigohost -e 'indigo.actionGroup.execute(12345678)'

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 12:39 am
by berkinet
How about using the RESful API from the pi, you could just use curl from the shell , or “request” in python, set a variable in Indigo. Then have a trigger watch for any change in the variable, grab the variable value in a script, set the variable back to null or 0 and then do whatever...

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 1:58 am
by tornado
matt (support) wrote:
Take a look at this example on the scripting tutorial page.
First note, "indigohost" is just an alias to the IndigoPluginHost executable (higher up on that page it shows how it is defined). Using the -e command line argument you can pass the python code you want the IPH to execute. So in your example you probably want to device different Action Groups in Indigo and then just pass in to the IPH which one to execute like this:
indigohost -e 'indigo.actionGroup.execute(12345678)'


Thanks Matt. I have considered this but was hoping to pass a variable "zone#" to an actionGroup via the -e command. Can you think of a way to do that from a shell script for example?

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 2:00 am
by tornado
berkinet wrote:
How about using the RESful API from the pi, you could just use curl from the shell , or “request” in python, set a variable in Indigo. Then have a trigger watch for any change in the variable, grab the variable value in a script, set the variable back to null or 0 and then do whatever...


Thanks for the information. Wouldn't a RESTful API require me to constantly poll the RPi? I was thinking that having the Pi trigger an event, vs, polling for a change, would be more ideal (and less traffic over the wire of polling 16 zones). If I'm thinking of this wrong please let me know.

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 2:29 am
by racarter
You would use the RESTful API on the Pi. Here's a snippet from a Pi Python script I run to read one of two Flic buttons and set the appropriate variable in Indigo:

Code: Select all
indigoUrl = ("http://192.168.0.20:8176/variables/flic{}?_method=put&value={}".format(fString, cString))
requests.get(indigoUrl, auth=HTTPDigestAuth('<username>', '<password>'))

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 1:27 pm
by berkinet
tornado wrote:
...Wouldn't a RESTful API require me to constantly poll the RPi? I was thinking that having the Pi trigger an event, vs, polling for a change, would be more ideal (and less traffic over the wire of polling 16 zones). If I'm thinking of this wrong please let me know.

I think @racarter pretty much answered your question. But, to specifically address what you asked... The Restful API requests would be sent from the RPi to your Indigo server. The API calls would only be made when a zone trigger occurred on your Alarm/RPi. You would essentially use an Indigo variable as a vector through which you would pass data, I.e. the alarm zone number.

And, just because I was curious... It is unclear exactly how your RPi and Mac are connected - you mention executing commands on the Mac - but, I will assume you are using IP. When you say you are executing commands on the Mac from the RPi, are you doing that over an ssh connection?

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 5:37 pm
by tornado
berkinet wrote:
tornado wrote:
...Wouldn't a RESTful API require me to constantly poll the RPi? I was thinking that having the Pi trigger an event, vs, polling for a change, would be more ideal (and less traffic over the wire of polling 16 zones). If I'm thinking of this wrong please let me know.

I think @racarter pretty much answered your question. But, to specifically address what you asked... The Restful API requests would be sent from the RPi to your Indigo server. The API calls would only be made when a zone trigger occurred on your Alarm/RPi. You would essentially use an Indigo variable as a vector through which you would pass data, I.e. the alarm zone number.


Yes! Feeling dumb here. Here is the key thing I was missing - I didn't realize that Indigo presented RESTful APIs! I thought incorrectly that when you and @racarter referred to these APIs you were talking about hosting the APIs from the Pi, not from Indigo. It makes a lot more sense now to me.

For others that don't read closely like me the appropriate URL here is :
http://wiki.indigodomo.com/doku.php?id=indigo_s_restful_urls

And, just because I was curious... It is unclear exactly how your RPi and Mac are connected - you mention executing commands on the Mac - but, I will assume you are using IP. When you say you are executing commands on the Mac from the RPi, are you doing that over an ssh connection?

I was doing that over an SSH connection indeed, from a .py script on the Pi using paramiko. Sample code:

Code: Select all
def ssh_command_garage_open():
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect('10.0.1.68', username='ssh_username', password='ssh_password')
        stdin, stdout, stderr = client.exec_command('/Users/tornado/scripts/playGarageOpeningSound.sh')

        client.close()


Thanks to all!

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 9:34 pm
by matt (support)
tornado wrote:
Thanks Matt. I have considered this but was hoping to pass a variable "zone#" to an actionGroup via the -e command. Can you think of a way to do that from a shell script for example?

I think using the RESTful API is the way to go for this one. But to answer your question there isn't a direct way to pass an argument to an action yet, but the indirect way would be to have your python script do two things: set the value of an Indigo Variable to your parameter, then execute the Action Group. The Action Group could then use the value fo the variable.

Re: Need help sorting out workflow

PostPosted: Mon Nov 27, 2017 11:25 pm
by tornado
matt (support) wrote:
tornado wrote:
Thanks Matt. I have considered this but was hoping to pass a variable "zone#" to an actionGroup via the -e command. Can you think of a way to do that from a shell script for example?

I think using the RESTful API is the way to go for this one. But to answer your question there isn't a direct way to pass an argument to an action yet, but the indirect way would be to have your python script do two things: set the value of an Indigo Variable to your parameter, then execute the Action Group. The Action Group could then use the value fo the variable.


Thanks Matt! That makes sense.