Access Hub Variables from App Code?

I'm using app settings to store API URL etc against each of our hubitat apps. I'd like to store this once in a hub variable and then access the hub variable from each of my groovy apps.

Can someone share a bit of code on how to read a hub variable from app code.

Believe you’ll have to create a connector and have the app use the resulting device to access the variable attribute.

I've asked, and there is currently no API that makes hub variables accessible to apps. I hope this changes some day, though I understand that they do not, at least in their current implementation (and perhaps never) generate events, so they are not useful for "waking" apps or using their values in every context--but it could certainly have its use (something that just needs to be read at the time of execution, for example--a color temperature or level to set a light to, a number of minutes to wait, a volume level, or whatnot).

So, the connector workaround above is what we'll have to use for now. Note that the specific attribute you're looking for will depend on the type of connector you (or the user) actually created.

Thanks. I hacked up the below code. I created a connector and was able to access the variables.

/**

preferences {
section("Settings"){
input "apiURL", "capability.sensor", title: "API Hub Variable"
}
}

def installed() {
initialize()
}

def updated() {
initialize()

log.debug apiURL.currentValue("variable")

}

def initialize() {

}

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