currentValue("attribute") doesn't have expected value?

My code calls device.currentValue("attribute") but it seems it only produces stale data. I suspect this is related to other threads like this one and this one but my issue is a little different so I can't figure out the solution from those threads.

Here's my relevant code:

   def deviceInputName = "theDevice" + inputIndex
    def attInputName = "theAtt" + inputIndex
    input deviceInputName, "capability.*", title: deviceInputTitle, multiple:multipleDevices, submitOnChange:true, required: true, width: 12
       input attInputName, "enum", title: attributeTitle, options: devAtt, multiple:multipleAttributes, submitOnChange:true, required: true
....

   if(updateTime == "realTime" && settings["theDevice"] && settings["theAtt"]) {
        td = settings["theDevice"]
        ta = settings["theAtt"]
        subscribe(td, ta, getEventsHandler)
    }

def getEventsHandler(evt) {
    getEvents()
}

def getEvents() {
....
if(eventMap) {eventChartingHandler(eventMap) }
}

def eventChartingHandler(eventMap) {
....
    labelValue = settings["theDevice" + labelID]?.currentValue(settings["theAtt" + labelID])
                             
}

This code is being triggered by a change in the value of one device attribute (namely, "theAtt" from "theDevice"). I'll call this the triggering attribute. When the triggering attribute value changes, it's always accompanied by a nearly simultaneous change in the attribute value based on which labelValue is set. I'll call this the label attribute value. Thus, I'm just grabbing the label attribute value (using currentValue) when the triggering attribute value changes. However, the label attribute value that I actually get is stale - it doesn't reflect the change.

Of course, I could perhaps introduce a delay, but I'd rather address the root of the issue than seemingly create a race condition. Any suggestions?

You linked my thread but I'm not sure you read it. :grin:

If you notice I mention you can supposedly add a second parameter to currentValue for "skip cache". If you pass true it should return the most recent value rather than the cached (stale) value.

Have you tried this?

2 Likes

Ah, nope missed that. Thanks I’ll try it!

Bummer. Didn't fix the issue.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.