UniFi binding beta [3.2.0;3.6.0)

I finally just switched to the new beta binding. Great work thanks!

Is it planned to add access points as things in the future? I currently use the Art of Wifi PHP Library to activate/deactivate my access points at night time (or at least my wife does). This works great but I’m always trying to keep custom built stuff around OH to an absolute minimum and just stick with the regular bindings as much as possible.

@ariela Lot’s of feature requests :smile: It looks like these require new type of things and/or calling a different api on the controller. Because the forum here is not a convenient place to track larger change request. I’d like to suggest if you can please create an issue on the openhab-addons GitHub repository issue tracker. Add a list of the features, grouped by: openHAB thing - openHAB channel - UniFi data field - Description of the channel. The more clearer the requirements are the faster I can add them.

@ariela , @N20VSLS I’ll add 2 channels to the wlan thing: number of wirelessClients and number of guestClients.

@DrRSatzteil activating the access point itself is not possible currently. I also don’t know and would need to find out the api call needed to activate/deactive the ap. If you have more information on that please post it here. There are some possible alternative solutions, but I’m not sure if they do work for you: 1) If you power the AP via a PoE port you can disable the power to the port, effectively shutdown the AP. But this might be a bit of brute force method. 2) It’s possible to active/deactive a network via a wlan thing. This can disable the whole WiFi network, not specifically a AP. So that might be a bit to much.

3 Likes

As I’m currently using the Art of Wifi client (GitHub - Art-of-WiFi/UniFi-API-client: A PHP API client class to interact with Ubiquiti's UniFi Controller API) let me share the implementation of this project with you. The activation/deactivation works like that:

public function disable_ap($ap_id, $disable)
    {
        if (!is_bool($disable)) {
            return false;
        }

        $this->curl_method = 'PUT';
        $payload           = ['disabled' => $disable];
        return $this->fetch_results_boolean('/api/s/' . $this->site . '/rest/device/' . trim($ap_id), $payload);
    }

Oh and regarding you other suggestions: unfortunately my POE switch isn’t a UniFi one so this is not an option for me. And disabling the wifi networks does not disable the radio afaik. So disabling the device seems to be the way to go for me.

1 Like

Finally got around to installing the latest version. Had been running the released version. All working well.

Thanks for your excellent work on this binding @hilbrand!

1 Like

I see the WLAN thing has a channel for a QR code for joining the WLAN network. I’d love to be able to display a QR code for joining the guest network. Just wondering if anyone has already done the work to create the QR code.

If not, I’ll take a look at it. I seem to recall there’s a Linux command to create a QR code, so should be easy enough.

1 Like

The openHAB main UI has a build in option to display a parameter as QR code. This can’t be directly used for displaying the QR code as channel. But means it should be possible to create a widget using the already present QR code library. The parameter-qrcode can be found here: openhab-webui/parameter-qrcode.vue at 3.3.0.M2 · openhab/openhab-webui · GitHub

Oh, nice.

Please see my comment in your PR. It looks like you might have the S and T swapped in the QR string.

1 Like

I’ve updated the jar posted in the topic. Reinstalling the market place should fix this qrcode string.

This change also adds 2 channels to the wlan thing: wirelessClients and guestClients, which show a count of the number of connected clients to the wlan. If the thing was created via the ui the thing needs to be recreated (remove and re-add).

1 Like

Thanks for the quick fix!

But…

You’re including the P: twice for the passcode.

WIFI:S:mySSID;T:WPA;P:P:myPassword;;

:man_facepalming: I’ve fixed the typo in the wifi QR code and updated the jar.

Looks good. Thanks!

Since I don’t use Main UI yet, and in case anyone is interested, these two lines of bash script will create the base64 representation of the QR code image.

base64String=`qrencode --output=- --type=PNG "${qrString}" | base64 --wrap=0`
echo -n "data:image/png;base64,"${base64String}

The shell variable ${qrString} should contain the value of the qrcodeEncoding channel on the WLAN thing.

The string returned by the above can be used to create a RawType, which can be used to update the state of an openHAB image item.

If your system doesn’t have qrencode installed, it can be installed using sudo apt install qrencode

Here’s my complete shell script.

#!/bin/bash

if [ $# -ne 1 ] || [ ${#1} -le 0 ] ; then
    qrString="Error: No string provided"
else
    qrString=$1
fi

base64String=`qrencode --output=- --type=PNG "${qrString}" | base64 --wrap=0`
echo -n "data:image/png;base64,"${base64String}

And the associated DSL code fragment.

val String s = executeCommandLine(Duration.ofSeconds(10), "/opt/openhab3/conf/scripts/create-qr-as-openhab-image.sh", newState.toString)
postUpdate(Ufi_Wlan_GuestNetwork_QRImage, RawType.valueOf(s))
3 Likes

Hi everybody,

i setup the new UNIFI Binding a few days ago. Looked good first but then i saw that the Status always changed between ONLINE and OFFLINE(COMMUNICATION ERROR). This happens every time it tries to refresh (e.g. if i set Refreshinterval to 10 it get’s ONLINE for 10 seconds and then OFFLINE for 10 secondes and so on).

I’m using DreamMachine (not pro) with latest firmware and application (UnifiOS UDM 1.11.4 / Network 7.0.23)
unifi.log (18.7 KB)

I tried updateing to OH 3.3.0M2 coming from 3.3.0 snapshot of december.

I only set up the Bridge and my 3 Wifi-Networks in OH.
Bridge:
UID: unifi:controller:49f0d40789
label: UniFi Controller
thingTypeUID: unifi:controller
configuration:
host: 192.168.100.1
refresh: 10
password: xxxx
unifios: true
port: 443
username: xxxx

Looking at your log output it looks like a wlan device doesn’t have a xpassphrase. Does one or more of the wifis don’t have a password set? If so removing that one should fix the problem (until I have created a fix) If not can you run with trace log level. This prints the raw data from the controller and should give an insight in what is missing. (Best send log via dm as it contains a lot of data)

1 Like

Hey @hilbrand
yes this is my guest wifi. Great! Disabling the guestwifi thing in OH fixed the issue for now.

Looking forward for a new version to test it.

Regards,
Carlo

I’ve updated the binding which should fix the guest wifi issue.

Hey @hilbrand ,
thank you very much! Works like a charm now.

Hello! I’ve just installed the binding and am having some issues with it. In the OpenHAB dashboard it shows as installed (and I can go into settings and make adjustments) but I am getting the following log entry:

2022-04-03 09:14:35.001 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-unifi': Error:
	Error downloading mvn:org.apache.felix/org.apache.felix.configadmin.plugin.interpolation/1.1.4

When installing I received plenty of “failed to install” error messages but it shows now, but seems to not be installed. But I don’t see a bundle installed when I’m in the console (with a bundle:list). Am I missing something simple here? I’m on build 3.3.0.M2.

Thanks!

That doesn’t look familiar. Not able to download might be something temporary not being available. Maybe if you try again it works.

I now have my binding installed (seemingly properly) but I have a completely non-functioning bridge, it’s showing a status “ERROR:CONFIG”. I believe it is completely related to my bridge configuration and I’m not sure I’m grabbing the correct host information. My bridge thing is:

Bridge unifi:controller:home "Unifi Controller" [ host="xxx.xxx.xxx.2", port=443, unifios=true, username="username, password="mypassword", refresh=10 ] 

(phone thing information not shown)
I’m using a UDM-Pro. For the host IP I tried its WAN address and had no luck; with that I get some very unhappy log entries:

2022-04-15 07:27:26.778 [ERROR] [.handler.UniFiControllerThingHandler] - Unknown error while configuring the UniFi Controller
org.openhab.binding.unifi.internal.api.UniFiException: Unknown HTTP status code 499 returned by the controller
	at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.getContent(UniFiControllerRequest.java:167) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.execute(UniFiControllerRequest.java:131) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.executeRequest(UniFiController.java:226) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.login(UniFiController.java:129) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.start(UniFiController.java:106) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler.initialize(UniFiControllerThingHandler.java:92) [bundleFile:?]
	at org.openhab.core.thing.binding.BaseThingHandler.thingUpdated(BaseThingHandler.java:155) [bundleFile:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-04-15 07:27:26.779 [INFO ] [openhab.event.ThingStatusInfoEvent  ] - Thing 'unifi:controller:home' updated: OFFLINE (CONFIGURATION_ERROR): Unknown HTTP status code 499 returned by the controller

I next tried the gateway IP address for the network on which my OpenHAB server resides. So if my Gateway/IP Subnet was defined as 123.456.789.111/24, I used 123.456.789.111 as the bridge “host.” With that my bridge happily loads and I’m getting no error messages in the logs. But still no change in the bridge thing status, still “ERROR:CONFIG.”

Note that in both cases I’m using port 443. When I apply 8443 the logs fill up with the same errors as above.

Unifios=true loads ok, but false gives the following log entries:

2022-04-15 07:35:36.669 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'unifi.things'
2022-04-15 07:35:36.699 [WARN ] [i.internal.api.model.UniFiController] - Not Authorized! Please make sure your controller credentials have administrator rights
2022-04-15 07:35:36.700 [INFO ] [openhab.event.ThingStatusInfoEvent  ] - Thing 'unifi:controller:home' updated: ONLINE
2022-04-15 07:35:36.700 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'unifi:controller:home' changed from OFFLINE (CONFIGURATION_ERROR): Unknown HTTP status code 499 returned by the controller to ONLINE
2022-04-15 07:35:36.701 [INFO ] [openhab.event.ThingStatusInfoEvent  ] - Thing 'unifi:wirelessClient:home:DavidsPhone' updated: ONLINE
2022-04-15 07:35:36.701 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'unifi:wirelessClient:home:DavidsPhone' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
2022-04-15 07:35:36.701 [INFO ] [openhab.event.ThingUpdatedEvent     ] - Thing 'unifi:controller:home' has been updated.
2022-04-15 07:35:36.704 [WARN ] [.handler.UniFiControllerThingHandler] - Unhandled exception while refreshing the UniFi Controller unifi:controller:home - Unknown HTTP status code 404 returned by the controller
2022-04-15 07:35:36.705 [INFO ] [openhab.event.ThingStatusInfoEvent  ] - Thing 'unifi:controller:home' updated: OFFLINE (COMMUNICATION_ERROR): Unknown HTTP status code 404 returned by the controller
2022-04-15 07:35:36.705 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'unifi:controller:home' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Unknown HTTP status code 404 returned by the controller
2022-04-15 07:35:36.705 [INFO ] [openhab.event.ThingStatusInfoEvent  ] - Thing 'unifi:wirelessClient:home:DavidsPhone' updated: OFFLINE (BRIDGE_OFFLINE)
2022-04-15 07:35:36.705 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'unifi:wirelessClient:home:DavidsPhone' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)