Hi Guys,
A noob question. I am trying to get the value of a global variable. In order to do so I am trying to use the Hub Variable API and the getGlobalVar (String) method as described here: Hub Variable API | Hubitat Documentation
The app script compiles ok but I am getting the following error:
Method getGlobalVar not found on location object: No signature of method: com.hubitat.hub.domain.Location.getGlobalVar() is applicable for argument types (java.lang.String) values: [outside_current_temp_gv]
Is 'Method getGlobalVar not found on location' indicating that there is no method called getGlobalVar ?
What am I missing? What am I doing wrong?
Cheers,
The parts of the app code related to getting the global variable:
def initialize() {
log.debug "Initializing"
// Fetch a hub variable
fetchHubVariable()
// Fetch immediately on initialization
schedule("0 * * * * ?", fetchHubVariable) // Fetch every minute for demonstration purposes
// Method to fetch the value of the static hub variable and log it
def fetchHubVariable() {
def outsideTempGV = getGlobalVar("outside_current_temp_gv")
if (outsideTempGV != null) {
state.currentValueOutsideTempGV = outsideTempGV.value
log.debug "Current outside temperature from hub variable is: ${state.currentValueOutsideTempGV}"
} else {
log.warn "Global variable 'outside_current_temp_gv' not found."
}
}
// Helper method to get the value of the global variable by name
def getGlobalVar(varName) {
def globalVar = location.getGlobalVar(varName)
log.debug "Global variable fetched: ${globalVar}"
return globalVar
}