SmartThings Community

Wi-Fi Presence App?


(Andreas A.) #21

Do you have OAuth enabled for the SmartApp? Double-check the appID & accessToken. What happens when you execute the curl calls (after substituting the variables)?

Yes - that looks correct.


(MacTechGenius) #22

I made the “appID” the Client ID and the “accessToken” my Client Secret from the SmartApp oAuth.

Screenshots of my OAuth:
23 PM

What does that mean? - What happens when you execute the curl calls (after substituting the variables)?

Currently, I am just pasting the file path of the script on Terminal.

But after I deleted the “a.ST_WiFi_Presence” file (the count file that my script generates. I did get an error after pasting the file path on Terminal.

Here it is:

I also tried switching the appID and accessToken on the script and this is the error Terminal gave me.

Also the script runs very quickly, I have 60 network devices so I would imagine it would take a few seconds to scan.

Thanks :smile:


(Andreas A.) #23

As the error states, you are using an invalid token. You don’t use the token that is listed in the app’s settings but the tokens for the instance you are running (since you can run more than one instance of the app). Open the IDE logging and then open the SmartApp on your phone. When you tap “Done” you will see the correct credentials listed in the IDE.

arp is fast and efficient – it doesn’t have to scan all the devices every time.


(MacTechGenius) #24

Thanks.

I got the TOKEN and REST API from the IDE Live Logging.
IDE

I pasted the Token into the AccessToken on the script. Is my appID the ClientID from the OAuth settings? Or do I change it to the REST API?
43 PM

Also, should I remove the “-” in the AppID and accessToken?

But I still get the invalid_token error on Terminal.
terminal

Much appreciate your help!!!


(Andreas A.) #25

You use the REST API from the IDE logging.

No - you use them exactly as they are logged in the IDE.


(MacTechGenius) #26

Thanks for the response!

I made the changes, but I still get an error. It appears a string of characters are appending to the end of my token. Could that be the issue??

Thanks


(Andreas A.) #27

You need to remove the trailing $ in both curl lines


(MacTechGenius) #28

It works!!! Thanks so much!!!

The app reported that I arrived. Awesome!!

And then since I have 4 devices I want to monitor. Do I create 3 more devicetypes and tie in the same SmartApp? And then get the token and REST API for each smartapp and create 3 new scripts?

Also, how do I automate this with crontab -e? I pasted the path like this, but I am not sure how to save it so I can close Terminal?

Thanks


(Andreas A.) #29

It depends whether you care about them individually or not. If you only care whether any of them is present, you can tie them all into a single simulated sensor and use all MAC IDs separated by “|” in the script. If you want to know individual statuses, you need to install multiple simulated presence sensors, multiple instances of the smart app (each to link to one sensor each) and multiple copies of the script (each with the proper credentials to link to one of those smart apps).

Looks like you’re using vi as your default editor – I don’t really use vi so you would have to read up on that or change the default editor to something else (such as nano).


(MacTechGenius) #30

Appreciate all your help!!

I will look into that…for now I just have this running on Terminal every 100 seconds. Seems to work.
31 PM

Thanks


(Barry Murphy) #31

I have adapted for people using a mikrotik router (no need for another computer with a script).

Simply load the following code as a script

:local RebekahMac "18:65:90:5A:2A:8E";
:local RebekahPresent [/ip arp find mac-address=$RebekahMac];
:local BarryMac "3C:2E:F9:21:0F:5B";
:local BarryPresent [/ip arp find mac-address=$BarryMac];

:if ([:len $RebekahPresent] > 0) do={
     :log info "Rebekah Present";
     /tool fetch mode=https url="https://graph.api.smartthings.com/api/smartapps/installations/$appID/home?access_token=$token" keep-result=no;
} else={
     :log info "Rebekah not here";
     /tool fetch mode=https url="https://graph.api.smartthings.com/api/smartapps/installations/$appID/away?access_token=$token" keep-result=no;
}

:if ([:len $BarryPresent] > 0) do={
     :log info "Barry Present";
     /tool fetch mode=https url="https://graph.api.smartthings.com/api/smartapps/installations/$appID/home?access_token=$token" keep-result=no;
} else={
     :log info "Barry not here";
     /tool fetch mode=https url="https://graph.api.smartthings.com/api/smartapps/installations/$appID/away?access_token=$token" keep-result=no;
}

Add to a scheduler fo every 5 mins and job done


(James Costantini) #32

For those of us not technically inclined, I got UniFi to work for triggering a user’s presence by doing some sneaky things…

First, I set up email alerts in the UniFi controller for Client Connect and Client Disconnect. I had them send to a new gmail account I just created. Now, UniFi will send you all the notifications, so I made a trigger in gmail that had the user’s cell phone MAC address and the word “Disconnected” or “Connected” assign a different label to them.

Then, I went into the SmartThings Dev portal and added a new simulated switch called “User Home”.

Then, I went into IFTTT and set up 2 applets that used the Gmail trigger for each label and then either turned User Home ON or User Home OFF.

I’m using SmartRules, so from there I added a rule that said if the User Home was on for off for more than 10 mins, then set the presence to Home or Away.

Yes, lots of work to avoid coding, but for the less tech inclined it should work.


(Dat Tran) #33

Can you help with what is UniFi? Thanks


(Mark) #34

It’s a brand name for routers and other networking devices.


(Dat Tran) #35

Thank you.


#36

I have an WiFi presence solution I made that isn’t specific to router models etc. Put a few hours into making it work so if anyone still is having issues, feel free to try it out.