[ANSWERED]Questions on Basic Trigger Condition Script proble

Posted on
Tue Jun 09, 2015 8:27 pm
russg offline
Posts: 46
Joined: Oct 02, 2014

[ANSWERED]Questions on Basic Trigger Condition Script proble

OK, I feel stupid asking this.... but I've been attempting to write my first trigger condition script for two days, without luck, and I'm down to just trying to get a simple 1 line script to execute. Eventually I'm trying to create a script in a Trigger Condition for the NOAA Weather+ so that I can parse the weatherAdvisory1Text for key words and execute different actions. However, I'm still trying to get a on-line script of anything running. In the questions below, you'll see I've tried applescript & Python, both inside the Indigo app and in the external development UIs - with zero luck. It's getting really frustrating, and I'd appreciate any help!

I'm running OS X 10.10.3 and Indigo-Pro 6.1.0. My Python is 3.4.3.

1. I am planning on putting my script inside a Trigger Condition. As there is no way to point to a file, I need to debug the code in either the AppleScript Editor or the Python IDLE, and then paste it into the trigger condition window, correct?

2. To start, I open the existing script 'example - list devices.scpt'. When I run it, I get:
'IndigoServer got an error: Application isn’t running." number -600'
but, the indigo server is running, and all of my other triggers & actions work fine, as do the web pages for the control pages.. Any ideas on what is wrong?

2. Second, I tried a simple a simple applescript In the trigger/condition script box, where I type the following text in and click 'compile and test':
'set onState to on state of device "693038355"
when the ID is from a leak detector device I have added. I get the error:
'can't get on state of device '693038355''
Any ideas, or other examples of how to run a one-line script?

3. Third, I tried a simple Python script in the trigger/condition script box:
'indigo.devices.len()'
but I get the error message:
'an unknown token can't go after this identifier' (where 'indigo' is highlighted')
any thoughts?

4. I've tried all kinds of simple scripts in the Python IDLE environment, and while straight Python runs fine, I can't figure out the code to connect to Indigo. Are there any complete examples of a Python file?

5. Finally, I read that custom states (such as NOAA W+) can NOT be accessed by AppleScript -true or false?

thanks in advance.

Posted on
Tue Jun 09, 2015 11:18 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Questions on Basic Trigger Condition Script problems....

I don't know your answer for sure, but one thing I do know is Yosemite isn't supported yet.

Your indigo/Python problems quite possibly stem from this as there were Python changes in Yosemite.

Posted on
Wed Jun 10, 2015 5:12 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Questions on Basic Trigger Condition Script problems....

For AppleScript, did you try something like:

set onState to on state of device named "Leak Detector"

For Python, it's something like

onState = indigo.devices[693038355] .states[u"On State"]

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

Posted on
Wed Jun 10, 2015 9:05 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Questions on Basic Trigger Condition Script problems....

russg wrote:
I'm running OS X 10.10.3 and Indigo-Pro 6.1.0. My Python is 3.4.3.


Indigo doesn't support Python 3.4.3 - it uses Python 2.6 (on Yosemite).

russg wrote:
1. I am planning on putting my script inside a Trigger Condition. As there is no way to point to a file, I need to debug the code in either the AppleScript Editor or the Python IDLE, and then paste it into the trigger condition window, correct?


It's true there is no way to point a condition script to a file. Also, condition scripts can only be AppleScripts.

russg wrote:
2. To start, I open the existing script 'example - list devices.scpt'. When I run it, I get:
'IndigoServer got an error: Application isn’t running." number -600'
but, the indigo server is running, and all of my other triggers & actions work fine, as do the web pages for the control pages.. Any ideas on what is wrong?


That is, unfortunately, an OS issue that's been getting worse for the last several Mac OS releases. It's unclear why it happens, and there is no concise workaround. We've reported it to Apple and there is a radar bug filed for it, but no response as of yet.

russg wrote:
2. Second, I tried a simple a simple applescript In the trigger/condition script box, where I type the following text in and click 'compile and test':
'set onState to on state of device "693038355"
when the ID is from a leak detector device I have added. I get the error:
'can't get on state of device '693038355''
Any ideas, or other examples of how to run a one-line script?


AppleScript doesn't know about IDs - so you have to reference the device by name instead.

russg wrote:
3. Third, I tried a simple Python script in the trigger/condition script box:
'indigo.devices.len()'
but I get the error message:
'an unknown token can't go after this identifier' (where 'indigo' is highlighted')
any thoughts?


"indigo" is a Python module and "devices" is a python list - so you want to call the len method with the list as the parameter:

Code: Select all
len(indigo.devices)


russg wrote:
4. I've tried all kinds of simple scripts in the Python IDLE environment, and while straight Python runs fine, I can't figure out the code to connect to Indigo. Are there any complete examples of a Python file?


The problem you're seeing is that the indigo module must be included from within a special process that wraps our C++ objects (in the server) in Python. To get an interactive Python shell, select the Plugins->Open Scripting Shell menu item. That will start an interactive Python 2.6 shell in the terminal application that has the indigo module already imported. The Indigo scripting tutorial in the docs will probably answer a lot of your questions.

russg wrote:
5. Finally, I read that custom states (such as NOAA W+) can NOT be accessed by AppleScript -true or false?


This is the approach I think I'd take if I were you: since you need to get access to a custom device's state, you'll need to use Python. So, rather than use the built-in conditions tab, you'd actually implement a Python script as the action (either embedded or as a script file) on your trigger. The script would then perform whatever logic you need (get the device state, parse the value, etc) and then it would execute actions based on the results. The best way to do that is to create action groups for each alternative, then have the script execute the appropriate action group based on the parsing logic.

[MODERATOR NOTE] moved to the Conditions forum since that's a more appropriate place for this question.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 10, 2015 12:50 pm
russg offline
Posts: 46
Joined: Oct 02, 2014

Re: Questions on Basic Trigger Condition Script problems....

Jay, that was a lot of concise, excellent info, thank you! I'll revert to python 2.6.2 and try again. I was trying to use one language for everything (new to applescript and python), but didn't realize condition scripts could only be apple script, and that applescript isn't reliable for external scripts. I was banging my head trying to do everything with one language, which just isn't feasible.

I'm almost there, just a couple of follow up questions:

1- I've used the Open Scripting Shell (OSS), but it only processes single commands. So, for creating/editing python files would you advise using a simple text editor without any embedded Indigo wrapper code, but execute/test it within the OSS?

2- Is there a way to develope a python file besides using a dumb text editor? It would be great to have some type of intelligent UI with syntax checking & some debug functionality,. Would I start a UI like IDLE within the Open Scripting Shell, or use a UI outside of the Open Scripting Shell with an Indigo wrapper for debugging? what would you advise?

Finally, your advise on moving the filtering from the trigger object to the action object (where python files run) clicked a switch for me - I was focused on doing the filtering to minimize trigger events and keep system overhead to a minimum, which in most cases just isn't an issue.

Thank you very much! -russg

Posted on
Wed Jun 10, 2015 12:55 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Questions on Basic Trigger Condition Script problems....

I highly recommend Textwrangler. It isn't a full-on IDE, but does have syntax checking and debug. The down side is that it can't run Indigo syntax--and for that, I cut and paste to an embedded script window in Indigo and debug there.

Dave

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

[My Plugins] - [My Forums]

Posted on
Wed Jun 10, 2015 2:31 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Questions on Basic Trigger Condition Script problems....

Unfortunately, because of how we had to wrap our C++ objects and server communications with Python, traditional Python IDEs are of limited value since you can't debug scripts that use the indigo module. For text editing, I use BBEdit (which I've used for many years). TextWrangler is the free version of BBEdit so that's a good recommendation from Dave. You can paste in a full script into the scripting shell - just make sure that the indents are right.

You aren't really losing anything by moving the conditional logic to the action - the trigger still fires regardless. Using conditions simply stops the action execution. But running a condition script is basically the same as running an action script, so it doesn't really matter either way.

Python is definitely the way to go for all scripts except the ones that require AppleScript (like talking to other Mac apps, which is hard to do with Python). Python is the future, AppleScript is legacy.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 10, 2015 11:26 pm
russg offline
Posts: 46
Joined: Oct 02, 2014

Re: [ANSWERED]Questions on Basic Trigger Condition Script pr

Ah, the clouds finally parted and things are moving right along. Thank you so much for taking the time to explain all of that. Your support really is awesome.
-russg

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest