Ubiquiti Unifi Binding Feature Discussion

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

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

Iā€™ll try to do this today.

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.

2 Likes

sounds good to me

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?

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.

I use a things file:

root@homer:~# more /etc/openhab2/things/Unifi.things 
Bridge	unifi:controller:Unifi_HomeR	"Unifi Controller: HomeR" @ "Unifi" [host="172.16.13.100", 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"}

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.

1 Like

I am currently running:
openHAB 2.2.0 Snapshot Build #1028 on a Debian Jessie with Oracleā€™s JVM 8u144 with 2.1.0.201706081307 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)

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.

1 Like

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:

@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.

1 Like

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:)

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!

1 Like

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/ ??

Greets
Kim

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

Hi.

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?

Thanks.

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.

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:

4 Likes

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

1 Like

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ā€¦