Below is untested, but probably works. Note because of the 10 minute delay/sleep in the script this one has to be saved as an external .py script file. Indigo requires that embedded scripts finish their execution within a few seconds or it kills them, but external file scripts can run indefinitely.
- Code: Select all
varWaterToday = indigo.variables["WaterUse_01_Today"]
varWaterHouseNightLeak = indigo.variables["WaterHouseNightLeak"]
water0 = varWaterToday.getValue(float)
indigo.activePlugin.sleep(600) # sleep for 10 minutes
varWaterToday.refreshFromServer() # have to refresh our copy with the server's version since 10 minutes have passed
water10min = varWaterToday.getValue(float)
waterDelta = water10min - water0
indigo.server.log(u"Total measured water leak is " + str(waterDelta))
indigo.variable.updateValue(varWaterHouseNightLeak, str(waterDelta))
# try to sort out a toilet flush (about a gallon to 1.6 gallons) vs a slow or large leak
if (waterDelta >= 1 and waterDelta <= 10) or waterDelta > 20:
indigo.server.log(u"possible leak")
indigo.actionGroups.execute("Water Measure Night Leak Detected?")