I am working on writing a device handler for a contact sensor.
In my parse method I call createEvent, and return that event from parse. This event doesn’t show up in recent activites in the app or in the live logs, and the icon in the app doesn’t change.
The live log does show my log message with the event:
Parse returned [name:contact, value:closed, isStateChange:true, displayed:true, linkText:Virtual, descriptionText:Virtual contact is closed]
Can anyone see what I’m doing wrong?
metadata {
definition (name: “Test Open/Closed Sensor”, namespace: “jwagoner0”, author: “”) {
capability "Contact Sensor"
capability "Sensor"
capability “Refresh”
}
simulator {
status "open": "body:eyJTdGF0ZSI6ICJvcGVuIn0="
status "closed": "body:eyJTdGF0ZSI6ICJjbG9zZWQifQ=="
}
tiles {
standardTile("contact", "device.contact", width: 3, height: 2) {
state "open", label: '${name}', icon: "st.contact.contact.open", backgroundColor: "#e86d13"
state "closed", label: '${name}', icon: "st.contact.contact.closed", backgroundColor: "#00A0DC"
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat") {
state "Refresh", action: "refresh.refresh", icon: "st.secondary.refresh"
}
main "contact"
details(["contact", "refresh"])
}
}
def parse(String description) {
def evt
def map = [:]
def descMap = parseDescriptionAsMap(description)
def body = new String(descMap[“body”].decodeBase64())
def slurper = new JsonSlurper()
def result = slurper.parseText(body)
if (result.containsKey("State")) {
def contactState = result.State
state.contact = result.State
log.debug("state.contact set to ${contactState}")
if (result.State == "open") {
evt = createEvent(name: "contact", value: "open")
} else {
evt = createEvent(name: "contact", value: "closed")
}
}
log.debug "Parse returned $evt"
return evt
}