Trigger Condition Python Scripts

Posted on
Tue Feb 14, 2012 2:54 pm
nsheldon offline
Posts: 2105
Joined: Aug 09, 2010
Location: CA

Trigger Condition Python Scripts

Hey guys.

I've been using Indigo since mid 2010. I'm pretty familiar with AppleScript, so I built all kinds of AppleScript into my fairly extensive Indigo/INSTEON setup. I just recently upgraded to Indigo 5 and have begun auditing my AppleScript code to see if there's a way to increase efficiencies by rewriting some of the AppleScript in Python (though I'm not nearly as familiar with Python as I am with AppleScript). I never liked the "dot-object" OO programming syntax much, so I'm having to adjust to the less readable code.

In any case, I'm using the new NOAA Weather plugin and have created a "Weather" device. I'm using it to determine sprinkler watering time behavior by 1) determining if there was precipitation each day, and 2) updating the "sprinklerDurationMultiplier" variable based on the highest temperature in the day. When converting all my "variable changed" triggers to "device changed" triggers, I noticed that 1) there doesn't seem to be a way to access plugin device parameters via AppleScript and 2) it's only possible to use AppleScript in the "If script returns true" entry field of the Condition tab in a trigger. The tests that I'm performing are multiple string matches against the "currentCondition" state (e.g if indigo.devices['Weather'].states['currentCondition'].find('Rain') > 0 or indigo.devices['Weather'].states['currentCondition'].find('Showers') > 0) in the NOAA Weather device. When clicking the "Compile and Test" button, Indigo returns an AppleScript error "Expected 'then' but found unknown token." I thought about using the multiple condition matching rules, but the only matching options available for the Current Condition status are "is equal to" and "is not equal to".

Would it be possible to 1) add a "contains" and "does not contain" option for device statuses that are textual values and/or 2) have selectable script types for the "If script returns true" field in the Conditions tab?

Posted on
Tue Feb 14, 2012 3:19 pm
jay (support) offline
Site Admin
User avatar
Posts: 15795
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Trigger Condition Python Scripts

1) add a "contains" and "does not contain" option for device statuses that are textual values


We've discussed it and it's on the feature request list.

2) have selectable script types for the "If script returns true" field in the Conditions tab?


Adding Python to script conditions is actually quite challenging - because Python scripts aren't run in the same process as the server so it poses some interesting design issues. Those issues are sorta in place for AppleScript also but to a lesser extent. We may eventually do it - but we have to get more requests before it moves up on the priority list. We'd much rather add more specific tests to the UI editor (as you ask in the first question) though we understand that there will always be some things that we can't anticipate.

Remember also that there is an option that goes back to what people used to do before we added script conditions in Indigo 4: add your conditional logic in an actual execute script action. It's less reusable and you have to execute your actions via the script (and action objects in the IOM aren't quite done yet), but it will give you the ability to do the conditional logic before executing your actions. Once we get actions done that is... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Feb 14, 2012 4:03 pm
nsheldon offline
Posts: 2105
Joined: Aug 09, 2010
Location: CA

Re: Trigger Condition Python Scripts

Hey Jay.

Sounds good. Yea, I can see how getting the returned result of a Python script for a condition test could be challenging. I use conditional statements within individual actions in a number of triggers and schedules still (especially time delayed actions), so that's not too big of a deal. I think more specific tests in the UI editor would be the better route to go overall too.

Regards,
Nathan

Posted on
Mon Sep 30, 2019 4:27 pm
matt (support) offline
Site Admin
User avatar
Posts: 19370
Joined: Jan 27, 2003
Location: Texas

Re: Trigger Condition Python Scripts

Indigo 7.4 is now available and includes support for Python embedded conditional scripts (inside Triggers and Schedules).

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest