[OBSOLETE] Unifi Presence Sensor

I’ve updated the SmartApp and Docker image yet again :slight_smile:. This time, I’ve changed up the presence check logic slightly. I’ve also included in the SmartApp an Offline Delay time (in seconds) so a device is not marked “Away” until the given seconds have elapsed (1-300) since the device was “last_seen” on the network.

Hi there,

I’ve installed your SmartApp and DTH, however I seem to be struggling with getting the SmartApp to communicate with the UniFi Bridge server.

The UniFi Bridge is running as a Synology Docker Image on the same subnet as the SmartThings Hub and the UniFi controller.

I have tested local authentication using the local URL for the UniFi Controller (e.g. https://localhost:8443/manage/site/default/dashboard) and this appears to be the correct credentials.

When I browse to http://192.168.x.x:9443/ I get the Hello World Message, and when I browse to http://192.168.x.x:9443/config I get “No config file!”

In Live Logging in IDE I get the following debug log when I hit submit:

error java.lang.RuntimeException: Unexpected status code 400 from global /clients/null with status text @line 58 (installed)

debug Installed with settings: [offlineDelay:300, unifiPassword:password, unifiUsername:username, monitorGuest:false, bridgeAddress:192.168.x.x:9443, unifiAddress:192.168.y.y:8443, unifiSite:default]

Please could you let me know if there is anything else I can try?

Best wishes,
Guy

@Guy1992

Thanks for giving this solution a try! Hmm, at line 58 of the SmartApp, the app is trying to generate an access token. I’ve only see this section of the code fail when OAuth is not enabled on the SmartApp. Can you please double check to ensure you have enabled OAuth on this SmartApp?

1 Like

Doh! That was it - thanks for your quick reply all set up now :smiley:

1 Like

Any idea how to get this to work with the new UBios devices like the UDM or UDMP?

1:42:58 PM: trace getPhrases(), state.welcomeIssue = null
1:42:46 PM: debug Getting list of UniFi clients
1:42:19 PM: trace getPhrases(), state.welcomeIssue = null
1:42:18 PM: debug Telling the UniFi Bridge to monitor the following device(s): null
1:42:18 PM: debug toMonitor = null
1:42:18 PM: debug Updated with settings: [offlineDelay:200, unifiUsername:Dev, bridgeAddress:192.168

Hi @thesohoguy, thanks for bringing this to my attention. Sucks that it just doesn’t work :slight_smile:. Did a little research and found this post in the Unifi forums. That lead me to review the code here.

From looking at this, I’m lead to believe the only change with the API is the login URL?

        if ($http_code === 200) {
        $this->is_unifi_os = true;
        curl_setopt($ch, CURLOPT_REFERER, $this->baseurl . '/login');
        curl_setopt($ch, CURLOPT_URL, $this->baseurl . '/api/auth/login');
    } else {
        curl_setopt($ch, CURLOPT_REFERER, $this->baseurl . '/login');
        curl_setopt($ch, CURLOPT_URL, $this->baseurl . '/api/login');
    }

Looks like on UBios devices, they throw in ‘auth’ into the API login URL.

I don’t have any devices to test with but I can see about accounting for this and we can see if that fixes things :slight_smile:. I’ll try to work on this over the weekend.

Ah, looks like the API endpoints are also prefaced with “/proxy/network”. I’ll give it a shot :slight_smile:

I’ve been trying to get this working with my UDM Pro to no avail.

I’ve installed the bridge in docker on Unraid. I’ve verified that ST can talk to the container. Here’s my config file:

{"st":[{"app_url":"https://graph-eu01-euwest1.api.smartthings.com:443/api/smartapps/installations/"},{"app_id":"redacted"},{"access_token":"redacted"}],"unifi":[{"address":"192.168.1.1:443"},{"username":"myusername"},{"password":"mypassword"},{"site":"default"},{"offline_delay":60}]}

I’ve verified that the bridge can ping my UDM Pro and vice-versa using SSH.

Here’s my log from ST;

c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:32:26: debug Telling the UniFi Bridge to monitor the following device(s): null
c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:32:26: debug toMonitor = null
c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:32:26: debug Updated with settings: [unifiUsername:redacted, offlineDelay:60, unifiSite:default, unifiAddress:192.168.1.1:443, bridgeAddress:192.168.1.6:9443, unifiPassword:<redacted>, monitorGuest:false]
c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:32:26: debug initialize
c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:18:45: error groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'I' with an int value of 73
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Internal Server Error
^ @line 165 (parseClients)
c093187a-d0e9-4100-aec8-f3f88b9fe4b5 22:18:45: debug Getting list of UniFi clients

This error repeats over and over when I leave the smartapp open on the Unifi Clients page, as it refreshes.

Any suggestions appreciated.

Thanks

Thanks @rickydg for your interest in this project :slight_smile:. Unfortunately, this solution doesn’t work with Unifi Dream Machine. I don’t have a UDM to further develop out this solution to cover that. Maybe I’ll buy a UDM (even though I don’t need one) to further develop this, granting I can get someone to buy the UDM from me afterwards at full price.

The issue that I know of is that the UDM operates behind a proxy so you need to access the API endpoinds differently.

Thanks for the reply.

Thats a real shame :frowning:

I do hope somehow we (the community) manage to move forwards with this somehow. It cold be a real game changer for presence!

Well done for all your hard work so far!

Likewise, hoping this could work on UDM and directly as a podman container on the UDM itself.

Posted as an idea on your github @xtreme22886
Running other containers on UDM reference: https://github.com/boostchicken/udm-utilities/blob/master/run-pihole/README.md

Hi @xtreme22886

I’m getting the same problem as @rickydg. I’m running my controller on the same machine that is running docker.

I get the Hello World message but the config file is empty for the bridge. I have VLANS on my network, I’ve tried opening up access from my hub to my controller (same IP as docker) and also moved my hubs into the same VLAN as my server. Nothing seems to work? Any ideas?

Hi @xtreme22886 - I got this sorted. It was a docker issue. Thanks for making this btw - just gonna head of and donate!

1 Like

Hi @mixedveg, thanks for the update and I’m glad you got things sorted out :D.

Anyone using this with the new app ? I set it all up and can see our mobile phones as devices in the IDE and in the old app but not at all in the new app (I manually moved them in the IDE to a ‘room’ to see if that would help - but it didn’t) As a result, the devices don’t show when you create a new automation.

Thanks

It looks like a limitation with the New App - I just noticed this too (as I also notice that any Mobile Phone presence devices from the ‘Classic’ app don’t appear either!)

Correct, this app only works with the SmartThings Classic app, not the new app.

Thanks. Any plans to get it working with the new app, given that the old one is to be retired ?

Yes I do plan on it. But I’ll probably wait till I’m forced by SmartThings. They’ve been saying the Classic app is going away but there is no time defined for that yet. I have many SmartApps that I’m currently using that do not currently work in the new app so will likely not worry about it until the Classic app goes away and the other apps I have gain support for the new SmartThings app.

Thanks, I’ll probably leave the bridge in place for now then.