How to add more than 10 locations without IDE?

I need to add more than 10 locations to my SmartThings app on Android. Can’t used IDE now I’m told, so I need another method.

1 Like

Use the ST CLI.

smartthings locations [IDORINDEX]
smartthings locations:create
smartthings locations:delete [ID]
smartthings locations:history [ID]
smartthings locations:rooms [IDORINDEX]
smartthings locations:rooms:create
smartthings locations:rooms:delete [ID]
smartthings locations:rooms:update [ID]
smartthings locations:update [ID]
1 Like

Ok, i have CLI installed, but no idea what to do past typing

.\smartthings locations:create

seems it was a complex input to create location?

PS C:\Users\Andrew\smartthings> .\smartthings locations:create
» Error: input is required either via file specified with --input option or from stdin
PS C:\Users\Andrew\smartthings>

Yes, they aren’t walking you through that one so you need to provide the input that the API would expect. In JSON the minimum you can have is the following:

{
  "name": "nameoflocation",
  "countryCode": "GBR"
}

The countryCode requires three letters and needs to be set appropriately (presumably these ones).

If you put that into a file e.g. location.json then run smartthings locations:create -i location.json you should be there.

Is it possible to recursively issue multiple commands in a single JSON file? The above method does work to create more than 10 locations.

But, if you wanted to create several locations in a single command, how would you go about doing it? Here is what I tried so far, which did not work because there are multiple “name” lines and I must have incorrect syntax.

[
{
  "name": "100",
  "countryCode": "USA"
},
{
  "name": "101",
  "countryCode": "USA"
},
{
  "name": "102",
  "countryCode": "USA"
},
{
  "name": "103",
  "countryCode": "USA"
},
{
  "name": "104",
  "countryCode": "USA"
},
{
  "name": "105",
  "countryCode": "USA"
},
{
  "name": "106",
  "countryCode": "USA"
},
{
  "name": "107",
  "countryCode": "USA"
},
{
  "name": "108",
  "countryCode": "USA"
},
{
  "name": "109",
  "countryCode": "USA"
},
{
  "name": "110",
  "countryCode": "USA"
}
]

It doesn’t look like the API allows for creating more than one Location per call. Personally I’d use something like the ‘curl’ command line tool to create each Location as that would make the job easier. In Windows CMD that would be:

curl -H "Authorization: Bearer {{Personal_Access_Token}}" -H "Content-Type: application/json" https://api.smartthings.com/locations -d "{\"countryCode\":\"GBR\",\"name\":\"Test1\"}"

Obviously you can clean that up if you are using a single quote aware shell.

Bear in mind that the documentation claims that a user can only be associated with 50 Locations and that there is a rate limit on creating Locations of 50 per minute. Whether that is true or not is another matter.

1 Like

Thank you!@ finally worked with the

.\smartthings locations:create -i location.json using that json command! Took me forever to do this and crazy this is the length I have to go through, but at least its done now!!

the new SmartThings Advanced Web App has become available recently and you can add Locations there:

https://my.smartthings.com/advanced

2 Likes