How to get a SmartThings hub location mode UUIDs (home, stay, away)?

Currently looking at this page for automation using the new Rules API: GitHub - SmartThingsDevelopers/Sample-RulesAPI: Rules are a versatile tool, enabling you to automate the Devices and services that connect to the SmartThings Platform. When possible, Rules execute locally on a Hub.
And in particular, trying to develop one that gets/sets the current location mode of the hub like one of the samples:
Sample-RulesAPI/cameras_on_when_im_away.json at master · SmartThingsDevelopers/Sample-RulesAPI · GitHub

But am not seeing a way to create a query using the location or device endpoints that return the UUIDs for a hub’s location modes. Does anybody know how to do that?

thanks,
Dennis

To cut a long story short, if you do a GET on /locations/{{locationId}}/modes you’ll get a listing.

It isn’t clear why modes haven’t made it to the API reference or the CLI.

1 Like

Ah ok, thanks Graham, works perfectly!
I wonder what else is not documented. I know there is no documentation for random sleep time.

I had all the same questions. Here is a driver I built for HubiThings Replica that has create, delete, set, get and get all modes working examples.

https://github.com/bloodtick/Hubitat/blob/main/hubiThingsReplica/devices/replicaSmartThingsHub.groovy

1 Like

Following on from this, how to get the current location mode of the hub and set it?
I tried querying the hub using the devices endpoint passing the hub’s device id but that doesn’t seem to return the current location mode.

thanks,
Dennis

Do a GET on /locations/{{locationId}}/modes/current to get the current mode.

To set it you use a PUT to the same endpoint with the body:

{ "modeId": "{{id}}" }

Update: Can we pretend I didn’t really put a semi-colon in there first time around?

2 Likes

FYI, a quick and easy way to get mode information - including ID - is from the Locations->Modes path of my API Browser+:

1 Like

Thanks again Graham. I am able to get the current mode with the GET, but changing it to a PUT and adding the body with an id that I retrieved with the call to modes endpoint, I am getting a 422 Unprocessable Entity status code. Is it working for you?

thanks,
Dennis

It is when I remove the stray semi-colon I inexplicably put in the JSON. I’d like to blame my having written the original post while lying awake at 4am in a Pinotage induced haze. However I wasn’t actually that hazy to start with and I still didn’t realize six hours later after more sleep, breakfast and coffee. So the body is meant to be valid JSON of the form:

{
    "modeId": "12345678-90ab-cdef-0123-4567890abcde"
}

It does need the Content-Type header set for application/json if your default is something different.

Awesome thanks Graham, I was missing the content-type header field.