UniFi binding beta [3.2.0;3.6.0)

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)

feature request: be able to change the port profile on ports. I.e. from “All” to “Disabled” (or specific networks if you have them). I have a wired computer that I want to disable the port, but it’s not PoE, so I can’t just cut power. When I want to cycle it it’s because it’s gone out of communication, so Unifi doesn’t even recognize it’s on the network, so I can’t use wiredClient to reconnect it.

@DaveL looking at your second log, it looks like it can access the device, but then it returns 404. A 404 means the page/data it tries to access doesn’t exist. This could either mean it tries the wrong url or it tries to make an api call that is not supported by the device. Can you try with trace log level to see what it actually tries and get as return value?

@ccutrer I’m not sure if I understand correctly what you’re specifically asking, Partly I can somewhat guess what you want. But to be sure can you specify on thing (either existing or new) you want to have this feature. What channel, what values should it have (or just a switch channel). And if you know the command to send to the device.

Screenshot from the UI: Dropbox Capture

It would be a Switch channel if all you can do is turn it on or off, or a string channel if you can set specific profiles. I don’t know the actual API call to do it. It would be a channel on the poePort thing, as well as probably a new port thing for ports that don’t support PoE (or if you can have “optional” channels on things, maybe poePort should just be renamed port, and not expose the PoE channels for ports that don’t support PoE).

Thanks @hilbrand, I’m not too familiar with a typical return from a TRACE but here is what I’m seeing:
With my settings pointing to my gateway/IP subnet and port 443 when I save my configuration I get only the “Loading model ‘unifi.things’” Info log entry…no errors or additional messages. But the THING is still in an ERROR:CONFIG state. When I change something, e.g. to port 8443 I receive the following TRACE and ERROR (using my IP example):

2022-04-23 09:11:17.681 [TRACE] [nal.api.model.UniFiControllerRequest] - >> GET https://123.456.789.111/logout
2022-04-23 09:11:17.756 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.thingUpdated()' on 'org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler@6b71474': com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
	at com.google.gson.JsonParser.parseReader(JsonParser.java:66) ~[bundleFile:?]
	at com.google.gson.JsonParser.parseString(JsonParser.java:47) ~[bundleFile:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.prettyPrintJson(UniFiControllerRequest.java:248) ~[?:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.getContent(UniFiControllerRequest.java:152) ~[?:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiControllerRequest.execute(UniFiControllerRequest.java:131) ~[?:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.executeRequest(UniFiController.java:226) ~[?:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.logout(UniFiController.java:136) ~[?:?]
	at org.openhab.binding.unifi.internal.api.model.UniFiController.stop(UniFiController.java:110) ~[?:?]
	at org.openhab.binding.unifi.internal.handler.UniFiControllerThingHandler.dispose(UniFiControllerThingHandler.java:128) ~[?:?]
	at org.openhab.core.thing.binding.BaseThingHandler.thingUpdated(BaseThingHandler.java:153) ~[?:?]
	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) [?:?]
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $
	at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1562) ~[bundleFile:?]
	at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1403) ~[bundleFile:?]
	at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:541) ~[bundleFile:?]
	at com.google.gson.stream.JsonReader.peek(JsonReader.java:424) ~[bundleFile:?]
	at com.google.gson.JsonParser.parseReader(JsonParser.java:61) ~[bundleFile:?]
	... 19 more

@hilbrand hey man, when we’ll see this binding in the official milestone? :slight_smile:

Andrea