WiFi Client - REST API?

Hi there.

I’m hoping to get some assistance here.

Goal:
I want to automatically disable some webcore pistons from running based on which wireless phones are at my house. I cannot install WebCoRE or SmartThings on this(these) mobile devices.

What I’ve done so far:
I have written a powershell script that will pull the connected wireless clients from my UniFi system.

The list of clients are written to a text file on my Windows PC.

Next Step:
Use ST REST API to open/close a virtual sensor.

When the virtual sensor is closed (the client is connected), then WebCoRE will see this closed sensor and then I can disable the automation(s).

Has anyone done anything like this - using WiFi to open/close something in ST?

1 Like

I know people have used WiFi detection to turn on a virtual presence sensor, so similar idea. The options available depend on the specific router you have. See the presence FAQ for discussion of several projects:

FAQ: The Many Ways of Detecting Presence

Thanks. These look like you need to mobile device(s) in order to get these set up.

I may have missed it, but I didn’t see anywhere to make a POST to the API.

I’m not a developer, so I’m just looking for a way to logon to the REST API. The documentation I’ve found requires you do know a bit more than I do…

After I logon, I can focus on how to make the device ‘open’ or ‘closed’

I might be missing something in your requirements, but couldn’t you just call a webCoRE piston by its external URL and cut out the extra step?

Hi. I don’t know what you mean.

  1. Where would you call it from? Do I just go to a URL?

The other thing is that I already have a piston.

The piston I have is based on location… so if someone is home, don’t do X, Y or Z.

I actually misinterpreted your intentions with webCoRE. For some daft reason I was thinking you were intending to pause pistons, but I now realise you were simply intending to use the virtual sensors in a piston. Perhaps I should have been sleeping instead.

I’ve only ever played with the SmartThings API to test executing scenes (just in case I ever want to execute a scene from webCoRE or ActionTiles) but I imagine closing a sensor is similarly easy once you know how. Executing a scene, for example, is simply a POST request with a bearer token. As is typical with SmartThings documentation, it makes more sense when you already know how to do it.

Although I was initially thinking of your calling a webCoRE piston to directly pause pistons, you could, of course, still use one to close your sensors instead of calling SmartThings API.

Every piston has an external URL. If you open a piston in your webCoRE dashboard you’ll see a section named ‘Quick Facts’ …

Clipboard01

At the bottom is a link to its external URL which is of the form https://graph.api.smartthings.com/api/token/<uuid>/smartapps/installations/<uuid>/execute/:<uuid>: (the host name might vary). If you make a GET call to that your piston gets executed in a similar way to it is when you hit the ‘Test’ button. You can also add arguments to the call that can be used in the piston (e.g. ?sensor=name&state=closed would be accessible as {$args.sensor} and {$args.state}).

You can use the Virtual Trigger, IFTTT.

This will give you a URL, listed at the bottom, that you can use a specific call within the Piston rather than using the execution link, which is indiscriminate and will force you to build many pistons. You do not have to use this link only in IFTTT. You can use it anywhere.

The other option would be to send unsolicited HTTP POST messages to the hub on your local network on port 39500. These messages will be passed off to a device with a device ID that matches the MAC address of the sending device and automatically sent to the parse method within the driver.

Hi, and thanks for the suggestion!

Here’s what I ended up doing:

  1. Using the UniFi Controller API, I was able to login, get the device list, and filter it for the devices I’m interested in tracking.

  2. Created a script that says: when the devices are connected, turn on a virtual switch and execute this piston. This script runs every 30 minutes to check if the device is present.

  3. If the device is found, execute piston 1.
    If the device is not found, execute piston 2.

Piston 1 - sets a global variable to ‘present’.
Piston 2 - sets a global variable to ‘not present’.

I then use that global variable in my other pistons that will turn off all of the lights when I leave the house (naturally I don’t want that to happen if someone else is there), Alexa Guard on/off, and other functions like that.

Thanks for all your help!

You can consolidate it by appending variable to the calling script to pass to the piston.

piston_url/?status=present (or not_present)

Your receiving piston can extract the variable from $args.status and proceed from that.

Sounds above me! I’m no developer, so I’m not entirely sure how I would do that.

Actually, I think I got it.

I created a dynamic variable called ‘status’.
Selected ‘Argument’ and named it ‘status’.

Then I created 2 if statements.
1 - if arg.status = present ---- turn on virtual switch.

2 - if arg.status = not_present ---- turn off virtual switch.

Seems to work!

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.