The weird problem I am having is that sometimes when this script runs, the suppression variable doesn't get set to true even though the rain amounts clearly exceed the threshold then when I immediately manually run the script a second time, it get set correctly (nothing else has changed in the meantime). The only thing I can think of is that there is some ordering problem here with the way the Python script is reading and updating Indigo variables. But I am not at all sure. Can anyone else see what I am doing wrong?
Thanks,
Jon
- Code: Select all
# SET UP VARIABLES
rainTodayVar = indigo.variables[298150352] # "rainToday"
rainTomorrowVar = indigo.variables[375236753] # "rainTomorrow"
suppressVar = indigo.variables[88571208] # "suppressZ1irrigation"
rainThreshold = indigo.variables[1822895225].value # "rainThreshold"
# UPDATE RAIN TODAY FROM WEATHER UNDERGROUND
rainToday = indigo.devices[417831836].states["precip_today"] # State "precip_today" of "Home Weather WUnderground"
indigo.variable.updateValue(rainTodayVar,unicode(rainToday))
# ADD UP RAIN TOMORROW FROM WEATHER UNDERGROUND
totalRainTomorrow = 0
for i in range(24):
if i < 9:
hourQpf = "h0" + str(i+1) + "_qpf"
else:
hourQpf = "h" + str(i+1) + "_qpf"
totalRainTomorrow += indigo.devices[1542636177].states[hourQpf] # State "hXX_qpf" of "Hourly forecast WUnderground"
indigo.variable.updateValue(rainTomorrowVar,unicode(totalRainTomorrow))
# SET SUPPRESS VAR TO TRUE IF EITHER RAIN TODAY OR RAIN TOMORROW > THRESHOLD, OTHERWISE FALSE
if rainTodayVar.value > rainThreshold or rainTomorrowVar.value > rainThreshold:
indigo.variable.updateValue(suppressVar,"true")
else:
indigo.variable.updateValue(suppressVar,"false")