Was throwing an error because the IF command was uppercase but now i got it working. Thank you very much for this and the entire HubDuino platform its very useful.
I'm using a Mega with 12 sensors and 4 switches going in to enable and monitor my in floor radiant heating system and mechanical equipment, so for the contact sensors i didn't want to figure out which state is which since some of the device contacts are normally open and some are normally closed. This will also work nicely with displaying any custom state like Wet/Dry, ect
If anyone wants this for the future full code is below:
/**
*/
metadata {
definition (name: "Child Contact Sensor", namespace: "ogiewon", author: "Dan Ogorchock", importUrl:
capability "Contact Sensor"
capability "Sensor"
attribute "AlarmStatus", "String"
}
preferences {
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}
}
def logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("logEnable",[value:"false",type:"bool"])
}
def parse(String description) {
if (logEnable) log.debug "parse(${description}) called"
def parts = description.split(" ")
def name = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null
if (name && value) {
// Update device
sendEvent(name: name, value: value)
//Start of new Code for custom attribute
if (value == "open") {
sendEvent(name: "AlarmStatus", value: "Alarm")
}
else {
sendEvent(name: "AlarmStatus", value: "Normal")
}
//end of new code
}
else {
log.error "Missing either name or value. Cannot parse!"
}
}
def installed() {
updated()
}
def updated() {
if (logEnable) runIn(1800,logsOff)
}