Update WindowOrDoorOpen.groovy
authorRahmadi Trimananda <rahmadi.trimananda@uci.edu>
Tue, 6 Aug 2019 17:23:04 +0000 (10:23 -0700)
committerGitHub Enterprise <noreply@github.uci.edu>
Tue, 6 Aug 2019 17:23:04 +0000 (10:23 -0700)
third-party/WindowOrDoorOpen.groovy

index 2bb4901..0444040 100755 (executable)
@@ -82,6 +82,8 @@ def updated() {
 }
 
 def initialize() {     
+       // Adjustment for saved state
+       frequency = frequency + 1
        def MAX_CONTACT=30
        state?.lastThermostatMode = null
        // subscribe to all contact sensors to check for open/close events
@@ -271,8 +273,8 @@ def sensorTriggered(evt, indice=0) {
                clearStatus(indice)
        } else if ((evt.value == "open") && (state?.status[indice] != "scheduled")) {
                def takeActionMethod= "takeAction${indice}"       
-               runIn(freq, "${takeActionMethod}",[overwrite: false])
                state?.status[indice] = "scheduled"
+               runIn(freq, "${takeActionMethod}",[overwrite: false])
                log.debug "${theSensor[indice]} is now open and will be checked every ${delay} minute(s) by ${takeActionMethod}"
        }
 }
@@ -473,10 +475,13 @@ def takeAction(indice=0) {
        def maxNotif = (givenMaxNotif) ?: 5
        def max_open_time_in_min = maxOpenTime ?: 5 // By default, 5 min. is the max open time
        def msg
+       def open = "open"
+       def closed = "closed"
     
        def contactState = theSensor[indice].currentState("contact")
        log.trace "takeAction>${theSensor[indice]}'s contact status = ${contactState.value}, state.status=${state.status[indice]}, indice=$indice"
-       if ((state?.status[indice] == "scheduled") && (contactState.value == "open")) {
+       //if ((state?.status[indice] == "scheduled") && (contactState.value == "open")) {
+       if ((state?.status[indice] == "scheduled") && (contactState == open)) {
                state.count[indice] = state.count[indice] + 1
                log.debug "${theSensor[indice]} was open too long, sending message (count=${state.count[indice]})"
                def openMinutesCount = state.count[indice] * delay
@@ -511,8 +516,9 @@ def takeAction(indice=0) {
                takeActionMethod= "takeAction${indice}"       
                msg = "contact still open at ${theSensor[indice]}, about to reschedule $takeActionMethod"
                log.debug msg            
-               runIn(freq, "${takeActionMethod}", [overwrite: false])
-       } else if (contactState.value == "closed") {
+               //runIn(freq, "${takeActionMethod}", [overwrite: false])
+       //} else if (contactState.value == "closed") {
+       } else if (contactState == closed) {
                restore_tstats_mode()
                clearStatus(indice)
                takeActionMethod= "takeAction${indice}"       
@@ -534,7 +540,7 @@ private void save_tstats_mode() {
                return    
        } 
        tstats.each {
-               it.poll() // to get the latest value at thermostat            
+               //it.poll() // to get the latest value at thermostat            
                state.lastThermostatMode = state.lastThermostatMode + "${it.currentThermostatMode}" + ","
        }    
        log.debug "save_tstats_mode>state.lastThermostatMode= $state.lastThermostatMode"