Ubiquiti Unifi Binding Feature Discussion

BOOM!!

1 Like

Oh, so which one is it now, a switch or contact? Though mine seems to be happy with a contact item.

As part of the review process of the PR, Kai asked Matt to change it from a Contact to a Switch. So, in the lastest versions it’s a Switch.

Ok, and that’s the one in the PR…but that’s not the same version as from jenkins?

Here.

Use a Switch

Here are my items:

/* Unifi Items */

Switch		S8_PRES	"S8 Presence [MAP(Unifi.map):%s]"	<switch>		(gUnifi)	{channel="unifi:client:Unifi_HomeR:S8:online"}
String		S8_AP	"S8 AP [%s]"				<qualityofservice>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:S8:ap"}
Number		S8_RSSI	"S8 RSSI [%s]"				<qualityofservice>	(gUnifi)	{channel="unifi:client:Unifi_HomeR:S8:rssi"}
Number		S8_UPTM	"S8 Uptime [%d]"			<time>			(gUnifi)	{channel="unifi:client:Unifi_HomeR:S8:uptime"}
String		S8_UPTF	"S8 Uptime F [%s]"			<time>			(gUnifi)
DateTime	S8_TIME	"S8 Last Seen [%1$tH:%1$tM:%1$tS]"	<time>			(gUnifi)	{channel="unifi:client:Unifi_HomeR:S8:lastSeen"}

Unifi.map:

ON=Home
OFF=Away
NULL=Unknown

nice trick to display properly the uptime:

Unifi.rules

rule "Format S8 Uptime Display"
when
	Item S8_UPTM changed
then	
	var int days = ((S8_UPTM.state as DecimalType).intValue / (86400))
	var int hours = (((S8_UPTM.state as DecimalType).intValue / 3600) - (24 * days))
	var int minutes = (((S8_UPTM.state as DecimalType).intValue / 60) - ((1440 * days) + (60 * hours)))
	var int seconds = (((S8_UPTM.state as DecimalType).intValue) - ((86400 * days) + (3600 * hours) + (60 * minutes)))
	var String result = ""
	if (days > 0) { result = result + days + "d, " }
	if (hours > 0) { result = result + hours + "h, " }
	if (minutes > 0) { result = result + minutes + "m, " }
	if (seconds > 0) { result = result + seconds + "s" }		
	S8_UPTF.postUpdate(result)
end

then put the formatted item (S8_UPTF) on your sitemap

1 Like

Cool thanks, I’ll download from there, and swap back to switches.

Nice. I think I’l use that! :+1:

1 Like

and of course… the emergency rule when the wife enters the house…

rule	"Send Pushover when Wife becomes present @ Home"
	when
		Item I6_PRES changed from OFF to ON
	then
		logInfo("Wife_Presence", "Wife entered Home")
		sendPushoverMessage(pushoverBuilder("Wife entered Home").withPriority(0))
end

:slight_smile:

1 Like

Yeah I have similar to control outside lights since the normal use case is on alarm disarm…of course if one of us is home, then there’s no disarm event to turn on the lights, so unifi is used to figure out someone arrived home, turn on lights.

1 Like

Love it! :smiley:

1 Like

Hi All

Giving this a go for presense detection, typically I come home through the back of the house, which means I trigger a few motion sensors to walk in through the back door.

Would this work OK to have Alexa play a welcome message? Is there a way to have the binding check the presense of a mobile phone on a particular Access Point?


rule "Play Welcome Message when Kris enters the House"
when
        Item Kris_Mobile changed from OFF to ON
then
        if (BackEveMotionAlarm == ON && FibaroEye1Motion == ON) {
         logInfo("Mobile Presense", "Kris has entered the Home")
          Echo_Living_Room_TTS.sendCommand('Welcome Home Kris')
}
end

Hey guys,

The latest stable dev build can always be found here:

openhab2-unifi-binding-v2

Regarding the whole -v2 tag in the URL, @Kai had asked me to switch from Jackson JSON processing to GSON processing as it’s provided by the ESH stack - so I created a new branch as it was some pretty big changes. There was also some poorly written exception handling code that I heavily refactored to clean it up (it took me even a while to figure out what I was originally thinking when I wrote it).

Rest assured, this binding is not dead, I just don’t have any spare time - every waking minute I’m working on the electrical at the house.

I promise, this will get included in the repo and it’s going to get new features as I must implement PoE support to increase my WAF stock :wink:

What ideas do you guys have for new features?

I’ll start:

  1. PoE Support
  2. ???

Cheers!

mgb

3 Likes

Hi Guys, ive created the switches for my two devices (not online currently) and I see this in the log:


15:56:36.203 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from UNDEF to OFF
15:56:36.223 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from OFF to UNDEF
15:56:36.239 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from UNDEF to OFF
15:56:36.256 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from OFF to UNDEF
15:56:46.279 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from UNDEF to OFF
15:56:46.297 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from OFF to UNDEF
15:56:46.317 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from UNDEF to OFF
15:56:46.333 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from OFF to UNDEF
15:56:46.787 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'unifi.items'
15:56:56.363 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from UNDEF to OFF
15:56:56.383 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from OFF to UNDEF
15:56:56.399 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from UNDEF to OFF
15:56:56.415 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from OFF to UNDEF
15:57:06.440 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from UNDEF to OFF
15:57:06.458 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from OFF to UNDEF
15:57:06.474 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from UNDEF to OFF
15:57:06.497 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from OFF to UNDEF
15:57:16.518 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from UNDEF to OFF
15:57:16.538 [INFO ] [smarthome.event.ItemStateChangedEvent] - Kris_Mobile changed from OFF to UNDEF
15:57:16.553 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from UNDEF to OFF
15:57:16.569 [INFO ] [smarthome.event.ItemStateChangedEvent] - Jodie_Mobile changed from OFF to UNDEF

Items


/* Unifi Items */
Switch  Kris_Mobile  "Kris' Mobile Presence [MAP(unifi.map):%s]"        <switch>                (gUnifi) {channel="unifi:client:KrisMobile:online"}
Switch  Jodie_Mobile "Jodies Mobile Presence [MAP(unifi.map):%s]"       <switch>                (gUnifi) {channel="unifi:client:JodieMobile:online"}

PoE support would be enough for me. I already have a use case for my house: when Mains electrical power is down and I am on UPS, I want to shut down the PoE on some ports (for Cameras and APs) on the Unifi switch.

1 Like

POE support would be amazing with 1000s of uses and will help save the planet!

How’s about hotspot voucher support - press a button and unifi returns a voucher code for your guest wifi that you can give to guests or display on habpanel / sitemap or email to yourself? Saves printing a load and having to find where you put then :smiley:

1 Like

Hotspot voucher systems are network admin’s kryptonite. What would you say about an automatically rotating 8 digit passcode that changed say every 24 hours… but I guess this would mean the controller would have to “re-provision” the APs would which cause network downtime so forget what I said…

:bulb:

Let’s assume we’re using one time voucher codes…

  1. Binding generates a code via the controller and stores it in an item
  2. Binding detects someone has joined the guest network
  3. Binding assumes the previously generated and stored voucher is no longer valid
  4. Repeat

This way you could have the next voucher stored in item and displayed in your preferred UI. Would still need a way to force the binding to generate a new code just in case things get out of sync but I’m just thinking out loud for the moment.

However, keeping in spirit with OH2 and bindings should only act as a bridge, this shouldn’t be implemented within the binding. I think it could still be accomplished using actions + rules if the binding had the appropriate info about the guest network (SSID, # of active clients, etc…).

Again, just thinking out loud…

Thoughts?

As soon as I’d pressed the post button your first idea about the rotating code jumped into my mind. If you do have to re-provision the APs then this would be a no go I would say. I think I remember seeing one of Willie Howie’s YouTube videos doing something similar. Also if all existing users got kicked off when the code changed then this would be a bit of a pain, say if you had visitors for a weekend or something.

I guess one time vouchers would be the ultimate goal, maybe even with a mechanism to generate ones of different duration. I’m sure there’s a project in the UniFi forum (I’ll see if I can find it again) where someone has basically done this with a Pi and a receipt type printer, using the API so it should be possible. But, as you say if the binding can do bridging that would make life a lot easier (I hadn’t really realised that this is all bindings are ‘allowed’ to do). I guess all the logic then goes into a rule, which maybe better anyway I guess allowing further customisation.

Anyone else having these issues? my mobile presense keeps going on and off, despite the phone not moving and directly under the AP

:frowning:

@dastrix80 what version of the binding are you running?

From the OH2 console run the following command:

openhab> bundle:list -s | grep unifi