Trigger conditional with a python script

Posted on
Fri Nov 20, 2020 5:18 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Trigger conditional with a python script

With the following script (which runs), I do not know how to
1) embed (Indigo wants indents, unless I indent the 'if' line, in which case iIndigo doesn't want an indent, or
2) as a file - how do I return a true for the conditional?

Code: Select all
hseStatus = indigo.variables[1568794432].value
T15 = indigo.variables[1193285363].getValue(bool)
T18 = indigo.variables[566274194].getValue(bool)
if hseStatus == "Vacant" and not T15 or T18:

Posted on
Fri Nov 20, 2020 5:28 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Trigger conditional with a python script

You don't have anything after your if statement - it has to have something to execute if the condition is true, and that's what has to be indented.

However, if you just change "if" to "return" (and delete the colon at the end) then it should do what you want as an embedded condition script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Nov 20, 2020 5:44 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Trigger conditional with a python script

That answered my first question (how to embed) - thank you. (To test the python script, I changed the value of a test variable, but couldn't figure out how to return True for indigo).
For my education, how does one return 'true' with a conditional script file?

Posted on
Fri Nov 20, 2020 6:55 pm
FlyingDiver offline
User avatar
Posts: 7217
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Trigger conditional with a python script

SMUSEBY wrote:
That answered my first question (how to embed) - thank you. (To test the python script, I changed the value of a test variable, but couldn't figure out how to return True for indigo).
For my education, how does one return 'true' with a conditional script file?

Code: Select all
return True


For the script you provided:

Code: Select all
hseStatus = indigo.variables[1568794432].value
T15 = indigo.variables[1193285363].getValue(bool)
T18 = indigo.variables[566274194].getValue(bool)
if hseStatus == "Vacant" and not T15 or T18:
     return True


Slightly more Pythonic:
Code: Select all
hseStatus = indigo.variables[1568794432].value
T15 = indigo.variables[1193285363].getValue(bool)
T18 = indigo.variables[566274194].getValue(bool)
return hseStatus == "Vacant" and not T15 or T18

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

Posted on
Sat Dec 10, 2022 7:01 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Trigger conditional with a python script

2 years later, this embedded conditional script issue continues to be a challenge.
In a trigger, the conditional script, when tested, returns "Script did not return a valid Boolean value:
Code: Select all
party = indigo.variables[1067262694].getValue(bool) #party
xmas = indigo.variables[1633517906].getValue(bool) #holiday season
now = indigo.server.getTime()
time_1500   = now.replace(hour=15, minute=00, second=0, microsecond=0)
if (time_1500 > now):
    if (party or xmas):
        return  True

Whereas, in a TDA, compiling the embedded conditional script below returns no errors:
Code: Select all
ltSensor = indigo.devices[269189693] #bYrd z-wav
ambLt = int(ltSensor.states["sensorValue"])
party = indigo.variables[1067262694].getValue(bool) #party
xmas = indigo.variables[1633517906].getValue(bool) #holiday season
if (party or xmas):
    if ambLt < 21:
        return  True


I'm stumped - again.

Posted on
Sat Dec 10, 2022 7:15 pm
FlyingDiver offline
User avatar
Posts: 7217
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Trigger conditional with a python script

Your first script doesn't return anything if the conditions fail. You might want to do:
Code: Select all
party = indigo.variables[1067262694].getValue(bool) #party
xmas = indigo.variables[1633517906].getValue(bool) #holiday season
now = indigo.server.getTime()
time_1500   = now.replace(hour=15, minute=00, second=0, microsecond=0)
if (time_1500 > now):
    if (party or xmas):
        return  True
return False


I'm not sure what a TDA is. But the fact you don't get an error at compile time doesn't mean you won't get one at run time.

You probably want a default return value at the end of the second script as well.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests