Well crud. This is driving me Nuts. There are definitely line breaks in there. If you look at the ide logs. The one that errors out has definite line feeds in it compared to the other one.
Here is my groovy code for getting that info from the device handler. Any help would be appreciated with this.
def alerts = get("alerts")?.alerts
def alertType = "[${alerts?.type[0]}]"
def newKeys = alerts?.collect{it.type + it.date_epoch} ?: []
//log.trace device.currentState("alertKeys")
def oldKeys = device.currentState("alertKeys")?.jsonValue
def noneString = "There Are No Current Weather Alerts"
if (!newKeys && oldKeys == null) {
send(name: "alertKeys", value: newKeys.encodeAsJSON(), displayed: false)
send(name: "alert", value: noneString, descriptionText: "${device.displayName} has no current weather alerts", isStateChange: true, displayed: false)
}
else if (newKeys != oldKeys) {
if (oldKeys == null) {
oldKeys = []
}
send(name: "alertKeys", value: newKeys.encodeAsJSON(), displayed: false)
def newAlerts = false
alerts.each {alert ->
if (!oldKeys.contains(alert.type + alert.date_epoch)) {
def msg = "${alert.description} from ${alert.date} until ${alert.expires}"
//send(name: "alert", value: pad(alert.description), descriptionText: msg, isStateChange: true)
send(name: "alertMessage",value: "${alert.message}",displayed: true)
sendEvent(name:"alert", value:"${alertType}", displayed: false)
newAlerts = true
}
}
if (!newAlerts && device.currentValue("alert") != noneString) {
send(name: "alert", value: noneString, descriptionText: "${device.displayName} has no current weather alerts", isStateChange: true, displayed: false)
send(name:"alertMessage",value:"", displayed: false)
}
}
}
else {
log.warn "No response from Weather Underground API"
}
}