Have to run script twice

Posted on
Fri Jan 07, 2022 11:12 am
zoff offline
Posts: 47
Joined: Jan 21, 2013

Have to run script twice

To update the variable irrigationScheduleV, I have to run this script twice or turn on zone1 outside of the script first and then run the script.
Code: Select all
import time
irrigationScheduleV = indigo.variables[1907577400]
zone1 =indigo.devices[1366164308] # "zone 1"
indigo.device.turnOn(zone1)
time.sleep(2)
if  (zone1.onState == True):
 indigo.variable.updateValue(irrigationScheduleV, "15")

What am I missing here?

Posted on
Fri Jan 07, 2022 1:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Have to run script twice

Because the zone1 variable is a snapshot of the device state at the time it was retrieved - so when you issue the turnOn command the instance itself still represents the old state. You need to refresh the snapshot of the device before you use it in the if statement:

Code: Select all
import time
irrigationScheduleV = indigo.variables[1907577400]
zone1 =indigo.devices[1366164308] # "zone 1"
indigo.device.turnOn(zone1)
time.sleep(2)
# refresh the snapshot instance so that it has any recent changes
zone1.refreshFromServer()
if  (zone1.onState == True):
 indigo.variable.updateValue(irrigationScheduleV, "15")

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jan 07, 2022 1:43 pm
zoff offline
Posts: 47
Joined: Jan 21, 2013

Re: Have to run script twice

Thank you!
That did it.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests