Ubiquiti Unifi Binding Feature Discussion

Tags: #<Tag:0x00007f5c912cd1f8> #<Tag:0x00007f5c912ccfc8>

(mdeneen) #182

What needs to be done to include this in a 2.2 or 2.3 release?

(Matthew) #183

Really just a rebase and squash which should result in a clean PR.

I’ll try to do this today.

(Matthew) #184

I was about to open a PR and I remembered the two outstanding issues…

  1. @psyciknz did you ever sort out your issue or are you still getting **null** in the calls to your controller? Do you have a site parameter defined on the UniFi Controller bridge?

  2. Is the consensus to change the online channel to a Contact? It makes sense to me as it’s read-only.

I’m going to wait for your feedback before I open the PR. Hopefully we can do this quick enough to get it into the 2.2 release.

(Angelos) #185

sounds good to me

(Psyciknz) #186

Where is the site parameter set?

I have a Things, Unifi Controller, but it only has a name as and location (or should I set location to be the name of the network?

(Psyciknz) #187

I’ve tried removing my controller and found the binding in resolved state to gave it a restart. Then I was able to see the binding config - couldn’t see a site in there, so tried adding the controller again. Now I see to be in some sort of mess where i can’t see the binding config anywhere.

So still not sure where I add the site.

EDIT. Just moved to the 2.2.0-SNAPSHOT and now I can get it to work.

(Angelos) #188

I use a things file:

root@homer:~# more /etc/openhab2/things/Unifi.things 
Bridge	unifi:controller:Unifi_HomeR	"Unifi Controller: HomeR" @ "Unifi" [host="", username="angelos", password="whatever", port=8443, refresh=10]
	Thing	client	Angelos_S6	"Angelos_S6" @ "Unifi"	[mac="ec:1f:72:17:xx:xx", site="default"]
	Thing	client	Simona_I6	"Simona_I6" @ "Unifi"	[mac="a8:66:7f:e3:xx:xx", site="default"]

Site is defined at the thing level (not the Bridge). I haven’t changed the “default” name of the site in the Unifi Controller to test if it will work (but it should).

In PaperUI, the site option appears under the thing’s configuration parameters

and here are my items (I only link to the main 2 channels)

root@homer:~# more /etc/openhab2/items/Unifi.items 
/* Unifi Items */

Switch	Angelos_S6_PRES	"Angelos S6 Presence"	<present>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Angelos_S6:online"}
Number	Angelos_S6_RSSI	"Angelos S6 RSSI [%s]"	<signal>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Angelos_S6:rssi"}

Switch	Simona_I6_PRES	"Simonas I6 Presence"	<present>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Simona_I6:online"}
Number	Simona_I6_RSSI	"Simonas I6 RSSI [%s]"	<signal>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Simona_I6:rssi"}

(Psyciknz) #189

Yeah I could only see it there when setting up an item. Where it sounded
like I was supposed to be seeing it in the controller.

You’ll notice that after updating to 2.2 snapshot it started working for me.

(Angelos) #190

I am currently running:
openHAB 2.2.0 Snapshot Build #1028 on a Debian Jessie with Oracle’s JVM 8u144 with org.openhab.binding.unifi and Unifi Controller version 5.5.19 (need to up to 5.5.20)

the binding works fine on this latest release. I never had problems with it since I started using it.

@psyciknz: what is your opinion on changing the channel type for the Online channel from Switch to Contact? (I am in favor since it is a “read only” setting)

(Psyciknz) #191

I’ve never used a contact item. But if its read only as you say (and I assume interacting with it on the UI is disabled?) then I’d be for it.

(Angelos) #192

I just realized that I am behind on the org.openhab.binding.unifi build that I am using :slight_smile: (#29)

There is build #33 available: https://jenkins.otr.mx/job/openhab2-unifi-binding/

downloading now :stuck_out_tongue:

(Matthew) #193

@psyciknz sorry for the confusion, as @Dim said, the site parameter was moved to the Thing. Glad to hear the 2.2.0-SNAPSHOT is working.

@Dim Those builds were coming from my rebase / squash commits I was pushing last night - automation ftw!

I will put together a Contact variant today and push it - probably as a new branch. Should be pretty straight forward but it will break existing configs so I would like to see some testing in the wild before I open a PR.

I will keep everybody posted.

(Angelos) #194

should be very easy to adjust: Simply change the item type from Switch to Contact in our Unifi.items:

Contact	Angelos_S6_PRES	"Angelos S6 Presence"	<present>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:Angelos_S6:online"}

keep up the greatness coming @mgbowman :wink:

This binding is used by me for presence detection (one of many possible uses)…
and it is (by far) the best presence detection solution that I have used so far (and I have tried several :smile:)

(Matthew) #195

Agreed :smile:

The fact most phones keep the wireless association - therefore visible in the UniFi controller - make this a much more reliable presence detection solution than any other “network monitoring” or GPS (read: battery drain) approach out there.

The only (minor) drawback is the delay introduced by the controller in marking a client as away. This could be fixed in the binding but it would take a bit of rework as the binding was designed to be stateless (as it should be).

Off to work!

(Kim Andersen) #196

I have a problem with this one.
I downloaded the jar, placed it in the addon folder, but nothing happens. Cant see the binding anywhere?? What went wrong?
I assume it´s suppose to go into usr/share/openhab2/addons/ ??


PS forgot to mention, its and apt-get installation.

(Hugues Pelletier) #197


Is it possible to ad the uptime value of a connected client as a new channel ?
I need to know now long a client has been there and the value is there in the Unify controller?

Or add the last seen value (to get beter results) in presence detection?


(Cody) #198

Agreement here as well. :grinning:

I was originally planning on needing to rely on an aggregate of several sensors to get reliable data, but so far there doesn’t seem to be a need. Admittedly I haven’t started to actually use the presence data for anything, but I have never seen it be inaccurate.
Any way in which it might fail, other methods are just as, if not more, susceptible to. Wifi being turned off, device left behind, etc.

Reducing the time for reporting as away would be a nice improvement for future versions. As it stands now though this binding is pretty sweet.

(Matthew) #199

Here you go…

Please checkout the updated README

Noteworthy changes:

  1. The online channel was changed to a Contact - The normal (state) of the Contact can be configured on the Thing definition allowing you to change the polarity*.

  2. Added an uptime channel (Number) - This is the time, in seconds, the wireless client has been connected to the controller. The UniFi Controller UI displays this value in the UPTIME column.

  3. Added a lastSeen channel (DateTime) - This is the date & time the wireless client was last seen by the controller.

* Since I couldn’t decide what the normal Contact state should be for absent vs present states, I added a Thing Configuration parameter contactType so you get to decide :wink:

Please update to the latest build org.openhab.binding.unifi-2.2.0-SNAPSHOT.jar and report back if you guys have any issues.

For now, I’m leaving the binding purely stateless. We will just have to live with the delay introduced by the controller when it comes to marking a client as absent. Maybe in the future I will find a simple way to support some kind of binding specific timeout.

Looking forward to feedback.

I can give you one of my use cases that may switch on a lightbulb (no pun intended… ok maybe a little)

I track my wife and I’s iPhones. I have a “It’s Bedtime” scene that is trigged when the living room’s harmony switches off in the evening. All the lights along the path to the bedroom dim up and both of our bedside table lamps turn on.

When both bedside table lamps turn off, this means “we’re in bed” and all the lights in the house turn off.

What does this have to do with presence detection?

My wife travels a lot for work so when she’s not home, her bedside lamp doesn’t come on - I only have to turn mine off. I got annoyed having to roll over every night and turn hers off whenever she was away. Am I lazy? Yes, yes I am! :smiley:

Command <ON or OFF> not supported for channel: online
(Hakan Tandogan) #200

This is the main valid reason for all automation :laughing:

( ) #201

I need to ask, why is this method better than others, e.g. the normal network binding dhcplisten+ping method? Seems to me both have the same benefits and restrictions…