Global var connector help

I have a global variable (gHolidayName) setup with a connector. I can read it in custom apps but now I want to set it. I have this in my app:

And run the following commands:

image

In the logs I see the following:

image

The app prints out "Just another day" which is what is in the variable. Then it looks like it sets the global variable to "Bugs" as intended but when it prints out the variable again it has the original value.

What am I doing wrong?

It's likely the platform just hasn't had enough time to commit the new value by the time you read it again given that you're doing it as the very next thing in that code snippet. If you actually use the value at another point in the app, you'll probably be fine; if you're just curious to test, inserting a pauseExecution() for a second or so (likely even just tens or hundreds of milliseconds) before you read it may be enough. The other possibility is that something is going wrong with the way you're setting the value, but that would be easy to check on the actual device.

I had thought about timing but the global variable never changes. I can look at it in RM half an hour later and it is still the original value.

I just checked with a global string variable, and this minimal app worked for me. I'd make sure your global variable is really a string (or, more generally, that the type matches whatever you're setting) or consider sharing the full code for a minimal test case that fails for you.

definition(
    name: "TEST App - Global Variable Set",
    namespace: "Test",
    author: "Test",
    description: "Minimal test app",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "",
    iconX3Url: ""
)

preferences {
    page name: "pageMainPage"
}

def pageMainPage() {
    dynamicPage(name: "pageMainPage", uninstall: true, install: true) {  
        section("Test App") {
             input name: "dev1",  type: "capability.sensor", title: "Select device:", submitOnChange: true
             input name: "btn1", type: "button", title: "Push me to set value!"
        }
    }
}

def appButtonHandler(btn) {
    log.trace "Button pushed..."
    log.debug "BEFORE: Value is ${dev1.currentValue('variable')}"
    dev1.setVariable("Test app value!")
    pauseExecution(1000)
    log.debug "AFTER: Value is ${dev1.currentValue('variable')}"
}

I will note that sometimes that "AFTER:" log still fetches the old value, but after increasing the pause to 1 second, this seems to happen less. You could probably address that with currentValue('variable', true) to force a read from the database instead of the cached value in the device, but I wouldn't do that unless this matters for actual usage. The above is somewhat contrived in that you'd rarely need to read a value immediately after setting it. You already know what it is, and in real use, you'd likely be reading the value--probably correctly--in a future execution of the app.

In any case, I know the device itself is changing because I can see the device page. If you haven't been looking at that, you should to really tell what is or isn't going on. The app, of course, can't read the "correct" value if it was never set--but again, that is working for me.