Api call to detect that app/driver is executing on hubitat hub?

is there such an api?

thanks.

I don’t think there is one officially.
I’ve just written one though that works for me. I’m using the hub ID. SmartThings hub ID is a long GUID type string whereas Hubitat returned “1” so I just check for the length of the hub Id.

if (location.hubs[0].id.toString().length() > 5) { state.hubtype = "SMARTTHINGS" } else { state.hubtype = "HUBITAT" }

After running this, you can check state.hubtype throughout your code to see which hub you are running on. I’ll be doing this so I can work around incompatibilities and have one code base for BigTalker on both platforms.

2 Likes

the hub id is a Long in Hubitat not a String, that is why you are getting an exception.
you should be able to do this: location.hubs[0].id.toString().length() > 5

1 Like

Fantastic that works. I’ll edit my original post to show this (which simplifies it to 1 line of code:

if (location.hubs[0].id.toString().length() > 5) { state.hubtype = "SMARTTHINGS" } else { state.hubtype = "HUBITAT" }
1 Like

You could also wrap it up in a function and call that function when you need it.

def getHubType(){
    if (location.hubs[0].id.toString().length() > 5) { return "SMARTTHINGS" } else { return "HUBITAT" }
}

Then when needed just call your getHubType function.

I’ll do this in my initialize() function to set a variable for use throughout my code:

state.hubType = getHubType()

then throughout the code where there are differences in how you call a command or do something,

if (state.hubType == "HUBITAT") { 
    //Do some Hubitat stuff
} else {
    //Do some non-Hubitat stuff
}

If you didn’t want to store it in a state variable, just use what’s returned from the function, such as:

if (getHubType() == "HUBITAT") { 
    //Do some Hubitat stuff
} else {
    //Do some non-Hubitat stuff
}
1 Like