preferences {
section("Doors") {
input "doors", "capability.contactSensor", title: "Door to monitor:", multiple: true, required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
log.debug doors.displayName
doorStates()
}
def doorStates() {
log.debug doors.currentValue("contact")
def doorState = doors.currentValue("contact")
log.debug doorState
if (doorState == "closed") {
log.debug "The door is closed"
} else {
log.debug "The door is open"
}
}
Alright, itās late and Iāve been triggering log errors for a while. The above works correctly and says that the device value is closed. So why is the if/else statement returning āThe door is openāā¦?
Again, this has to be my unfamiliarity with Groovy. This is painful to lose time on an if/else statementā¦
I got this to return correctly by converting the returned currentValue to a string (currentValue.join()) for the comparison. I donāt feel like thatās the preferred method however - if someone can chime in Iād appreciate it.
Iām simply checking the value of a set of doors for a Good Night app. If the doors are open, close them. So while I have the above solved, I want to iterate the returned values and trigger and event depending on their state. Iām going to have to check the values of the returned array so I donāt think the method I just used will work.