How to get SmartThings hub's ID?

Hi Guys,

I’m a newbie here,
simple question, is there a way to get SmartThings hub’s ID?

I know we can get all the paired devices’s ID by using this

http://docs.smartthings.com/en/latest/ref-docs/device-handler-ref.html#device

but how to get SmartThings Hub’s ID?

You can get a list of your hubs and their IDs from https://graph.api.smartthings.com/api/hubs or in the IDE go to “My Hubs” and then click on the hub. The hub id will be after “https://graph.api.smartthings.com/hub/show/” in the address bar of your browser.

1 Like

What do you want to do with the hub id?

Great!!
But is there a way we can get it from the SmartApp coding level like maybe getID()?
Instead of calling https://graph.api.smartthings.com/api/hubs and i need to do some parsing to get the ID.

I might have few SmartThings hub and I want to know from which hub the sensor triggered

1 Like

I do not know of a way to get the hub id easily in a SmartApp but as far as I know you can only have one hub per location so you can use the Location object which is available to tell where something triggers. http://docs.smartthings.com/en/latest/ref-docs/location-ref.html Will that work for what you want to do?

1 Like

If I’m using location as an ID, it might keep changing if i place my hub to different location right?
Let say I do my development at my office this morning and I bring my hub back home to continue my development at evening time.

If really there’s no get hub ID function available, I might just use https://graph.api.smartthings.com/api/hubs and do some parsing on SmartApp code there.
Thanks Andy…

Yeah, I would guess that they assumed the location object would cover anything needed since most people won’t be moving hubs from location to location on a regular basis. Also, an instance of a SmartApp runs inside the context of a location and can’t really interact with other locations I am pretty sure.

1 Like

Ok, couldn’t leave it alone… It looks like a device object does have a hub property which has an id property.

def eventHandler(evt) {
  log.debug "${evt.device.hub.id} is the hub id."
}
1 Like

This is obviously not documented. I will check, maybe there is a location.hub.id property or similar…

Engineer joke:

“Sometimes a thing which obviously should exist, does exist – – it just isn’t obvious!” :wink:

1 Like

It’s not doc’d yet. You can get the hubs for a location via location.hubs which returns a list of hubs for that location. You could then get the id from each hub in the location that way: def hubIds = location.hubs*.id. Note that location.hubs will return a list of hubs for that location, even if there is only one hub.

You can also get the hub for an event via evt.hub, and get the id from there if you want the hub associated with the event. There is only one hub for an event.

We’ll get it clarified and in the docs.

2 Likes

Yah… 3 years on and the documentation remains very incomplete. Guess I should be thankful for the tremendous ongoing improvements. I just find it incomprehensible that the API for an “open” platform aren’t documented at the same time that the Objects and Methods are coded!!!.

hubID is documented under the Event Object, but no others, as far as I can tell.

http://docs.smartthings.com/en/latest/ref-docs/event-ref.html#hubid

Jim, how does one get multiple hubs in a location?

1 Like

It used to be possible to connect multiple hubs on a location from the IDE. This is no longer the case, but some customers have more than one hub on a location. A very small subset.

1 Like

So is this a permanent feature deprecation?

Is the data model going to change so that there is a 1:1 constraint between Location :left_right_arrow: Hub?

No - that was removed over a year ago. Multi-hub locations are in our future.

1 Like

This is “sorta” important to know for some folks that may be writing SmartApps or Device Handlers, etc., that are using location.id vs. hub.id.

It’s one thing for the Platform to currently not allow the installation of more than one Hub in a Location, but it is another for the data model to never allow it, or for the data model to actually explicitly imply that it “will be in our future”.

Not sure I’m making sense… I’m trying to ask if the relationship: Location:Hub is still, officially, 1:Many (as in one location object can be related to many hub objects, but a hub belongs to exactly one and only one location.

Or … will the data / object model in regards to Location and Hubs completely change when multi-hub locations are re-introduced??

Thank you guys,

I tried evt.device.hub.id and evt.hubId both are return same value

But this -> https://graph.api.smartthings.com/api/hubs
the ID is different with evt.device.hub.id and evt.hubId

I think is shouldn’t be a matter since I will only use either evt.device.hub.id and evt.hubId

But this → https://graph.api.smartthings.com/api/hubs
the ID is different with evt.device.hub.id and evt.hubId

Strange, I get the same hub id from all of them.

1 Like