Not Stopping

Posted on
Wed Jun 29, 2022 11:38 pm
jltnol offline
Posts: 997
Joined: Oct 15, 2013

Not Stopping

So if the first IF statement is true, does the script stop there? and if so, how can I get it to continue to the rest of the script?
Code: Select all
import time
time = time.strftime("%B"" " "%d"", ""%Y" "  ""%I"":""%M" " ""P")

CurTemp = indigo.variables[358238426] # Current outside temp
HiTemp = indigo.variables[888702738] # HiTemp
HiTime = indigo.variables[422629946] # HiTime
LoTemp = indigo.variables[1777221291] # LoTemp
LoTime = indigo.variables[703113126] # LoTime

if CurTemp.value == "":
   indigo.trigger.enable(1132392789, value=True), indigo.trigger.enable(1818454130, value=False)

#set lo temp and time
if CurTemp.value <= LoTemp.value:
   indigo.variable.updateValue(1777221291, CurTemp.value), indigo.variable.updateValue(703113126, value=time)

#set hi temp and time
if CurTemp.value >= HiTemp.value:
   indigo.variable.updateValue(888702738, CurTemp.value), indigo.variable.updateValue(422629946, value=time)

Posted on
Thu Jun 30, 2022 5:15 am
DaveL17 offline
User avatar
Posts: 6782
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Not Stopping

The script will execute to the end. Take this for example:

Code: Select all
x = 3

if x >= 1:
    print(1)
   
if x >= 2:
    print(2)

if x >= 4:
    print(4)
   
if x >= 3:
    print(3)
The result is:

Code: Select all
1
2
3
However:

Code: Select all
x = 3

if x >= 1:
    print(1)
   
if x >= 2:
    print(2)
    quit()

if x >= 4:
    print(4)
   
if x >= 3:
    print(3)
Will yield:

Code: Select all
1
2

A Python script will (generally) run to the end unless it hits an instruction to stop or throws an error.

With your script, you have to remember that all Indigo variables are stored as strings. So in order to do mathematical comparison, you must convert them to a numeric value using something like:

Code: Select all
HiTemp = int(indigo.variables[888702738]) # HiTemp
# or
HiTemp = float(indigo.variables[888702738]) # HiTemp
I prefer float where possible as it's more precise.

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

[My Plugins] - [My Forums]

Posted on
Thu Jun 30, 2022 7:29 am
FlyingDiver offline
User avatar
Posts: 7257
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Not Stopping

Oh, and don't put multiple statements on one line. Do:
Code: Select all
import time
time = time.strftime("%B"" " "%d"", ""%Y" "  ""%I"":""%M" " ""P")

CurTemp = indigo.variables[358238426] # Current outside temp
HiTemp = indigo.variables[888702738] # HiTemp
HiTime = indigo.variables[422629946] # HiTime
LoTemp = indigo.variables[1777221291] # LoTemp
LoTime = indigo.variables[703113126] # LoTime

if CurTemp.value == "":
   indigo.trigger.enable(1132392789, value=True)
   indigo.trigger.enable(1818454130, value=False)

#set lo temp and time
if CurTemp.value <= LoTemp.value:
   indigo.variable.updateValue(1777221291, CurTemp.value)
   indigo.variable.updateValue(703113126, value=time)

#set hi temp and time
if CurTemp.value >= HiTemp.value:
   indigo.variable.updateValue(888702738, CurTemp.value)
    indigo.variable.updateValue(422629946, value=time)

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

Posted on
Thu Jun 30, 2022 8:24 am
jltnol offline
Posts: 997
Joined: Oct 15, 2013

Re: Not Stopping

Thanks for the info. I'll take your line construction suggestions to heart, as I have plenty of small scripts that have multiple "then" lines... it does make it easier to follow.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron