openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.59k forks source link

[UniFi-binding OH3] IP address not being reported anymore, status flipping, presence detection impossible #9095

Closed Boby71 closed 3 years ago

Boby71 commented 3 years ago

Expected Behavior

When a defined device is connected to the WiFi, the IP address should be reported and the status should be online.

Current Behavior

Since UniFi controller version 6.0.23 the status and the IP address isn't being reported to openhab anymore. This seems to apply also for the mac address and the uptime. image

Possible Solution

Obviously an update of the interface on UniFi side broke the binding.

Steps to Reproduce (for Bugs)

  1. Install UniFi binding
  2. Define bridge and wirelessClient for your phone image
  3. Watch e.g. the MAC or IP address in PaperUi

Your Environment

openHABian, latest stable on Raspberry Pi3+

Boby71 commented 3 years ago

Update: Also in OH3 (3.0 stable and 3.1 snapshot) it doesn't work anymore: Data is not being reported; in addition (at least) iOS devices flip continuously between on- and offline status reported:

2021-01-01 18:19:43.332 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from OFF to ON

2021-01-01 18:19:53.786 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from ON to OFF

2021-01-01 18:20:35.626 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from OFF to ON

2021-01-01 18:20:46.072 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from ON to OFF

2021-01-01 18:21:27.888 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from OFF to ON

2021-01-01 18:21:38.321 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhoneRobert_Online' changed from ON to OFF

It seems there has been found a solution, but not for OH3: [https://community.openhab.org/t/unifi-binding-doesnt-turn-off-device-online-status/107527/10]

Unfortunately this way, the UniFi binding is completely useless :-(

steininger commented 3 years ago

I have similar behavior. on my controller I tried to run the following script and have seen that there is not on each entry a name. the base model https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/api/model/UniFiClient.java seems to try to get a name, maybe this makes the client invisible. i tried to workaround by handing out a alias name in unifi portal, without success. maybe a fallback towards the hostname-property in case of name-property not found would be nice.

$uController = 'https://yourIP:8443' # e.g 'https://192.168.1.2:8443'
# Identifier of the site in UniFi. Set to default for the default site
$uSiteID = "default"

$uUsername = 'yourUser' # yourAdmin UserID
$uPassword = 'yourPassword' # yourAdmin User Password
$uAuthBody = @{"username" = $uUsername; "password" = $uPassword }
$uHeaders = @{"Content-Type" = "application/json" }

# Allow connection with the Unifi Self Signed Cert
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12

$uLogin = Invoke-RestMethod -Method Post -Uri "$($uController)/api/login" -Body ($uAuthBody | convertto-json) -Headers $uHeaders -SessionVariable UBNT

if ($uLogin.meta.rc.Equals("ok")) {
    Write-Host -ForegroundColor Green "Successfully authenticated to $($uController) as $($uUsername)"

    # Get Sites
    $uSites = Invoke-RestMethod -Method Get -Uri "$($uController)/api/self/sites" -WebSession $UBNT -Headers $uHeaders
    write-host -ForegroundColor Cyan "Sites"
    $uSites.data.name

    # Get Devices
    $uDevices = Invoke-RestMethod -Method Get -Uri "$($uController)/api/s/$($uSiteID)/stat/device" -WebSession $UBNT -Headers $uHeaders
    write-host -ForegroundColor cyan "Devices"
    $uDevices.data.name

    # Get Active Clients
    $uActiveClients = Invoke-RestMethod -Method Get -Uri "$($uController)/api/s/$($uSiteID)/stat/sta" -WebSession $UBNT -Headers $uHeaders
    write-host -ForegroundColor cyan "Active Clients by name"
    $uActiveClients.data.name
    write-host -ForegroundColor cyan "Active Clients by hostname"
    $uActiveClients.data.hostname
    write-host -ForegroundColor cyan "Active Clients by mac"
    $uActiveClients.data.mac

}
else {
    Write-Host -ForegroundColor Red "Unsuccessfull in authenticating to $($uController) as $($uUsername)"
}
steininger commented 3 years ago

In UniFiController.java line 258 may be a serialization problem. i have no experience in debugging, so if anyone else find something here before me, let me know.

i'll setup my environment and come back.

image

steininger commented 3 years ago

after multiple openhab-cli clean-cache this was fixed for me. maybe it had to do with trials in ui or with multiple reboots with clean cache. i would suggest to close this.