[Discontinued] OH2 Ubiquiti Networks mPower binding

Update: This binding is not available/supported anymore. I recommend to use MQTT: https://github.com/magcode/mpower-tools/tree/master/mqtt/client


Original message:
I’m happy to provide a first beta version of this binding.

Download it here: https://github.com/magcode/openhab2-addons/releases

Please help and provide feedback either here in this thread or directly in GitHub: https://github.com/magcode/openhab2-addons/issues

Documentation: https://github.com/magcode/openhab2-addons/tree/feature-mpower-binding/addons/binding/org.openhab.binding.mpower

4 Likes

Bravo !

First test from my side:

  1. Cleaned up my OH2 Snapshot 743 system from the old 1.x mPower binding
  • performed in Karaf console: config:delete org.openhab.mpower
  • removed the old org.openhab.binding.mpower-1.9.0-SNAPSHOT.jar file from /usr/share/openhab2/addons/
  • removed /etc/openhab2/services/mpower.cfg
  • removed all mPower related items from my setup
  • Shutdown OH2
  1. Downloaded the org.openhab.binding.mpower-2.0.01-SNAPSHOT.jar file to /usr/share/openhab2/addons/ (changed also file ownership to openhab:openhab)

  2. Startup OH2 and check Karaf console for the new Binding:

openhab> bundle:list | grep mPower
207 | Active   |  80 | 2.0.01.201701202009   | mPower Binding

openhab > feature:list | grep mPower
no result :)

openhab > log:set TRACE org.openhab.binding.mpower

And TADA !!!

2017-01-20 22:56:45.950 [DEBUG] [rnal.discovery.MpowerBridgeDiscovery] - Manufacturer matched: search: Ubiquiti Networks, device value: Ubiquiti Networks.
2017-01-20 22:56:45.952 [InboxAddedEvent           ] - Discovery Result with UID 'mpower:mpower:24_A4_3C_87_61_EA' has been added.
2017-01-20 22:56:45.955 [InboxAddedEvent           ] - Discovery Result with UID 'mpower:mpower:04_18_D6_54_1B_B7' has been added.
2017-01-20 22:56:45.956 [InboxAddedEvent           ] - Discovery Result with UID 'mpower:mpower:24_A4_3C_87_61_D3' has been added.
2017-01-20 22:56:45.957 [InboxAddedEvent           ] - Discovery Result with UID 'mpower:mpower:04_18_D6_59_FD_EA' has been added.

Testing more stuff now… So far, it’s fast, it’s good and it works ! :slight_smile:

Since I like to configure my stuff manually…

Here is my first mPower.things file:

Bridge	mpower:mpower:04_18_D6_54_1B_B7	"mP6-01 Comp Room"	[ host="172.16.13.1", password="ubnt", username="ubnt" ] {
	socket	1	"LAN Switch"	[ socketNumber="1" ]
	socket	2	"HomeR"			[ socketNumber="2" ]
	socket	3	"NAStorage"		[ socketNumber="3" ]
	socket	4	"ZTE Router"	[ socketNumber="4" ]
	socket	5	"HP Printer"	[ socketNumber="5" ]
	socket	6	"rPi3"			[ socketNumber="6" ]
}

and associated mPower.items file, linking the items to the channels:

Switch		mP6_01_01_O	"mP6_01_01 Outlet"		(gmPower)	{channel="mpower:socket:04_18_D6_54_1B_B7:1:outlet"}
Number		mP6_01_01_P	"mP6_01_01 Power [%.1f W]"	<energy>	(gmPower)	{channel="mpower:socket:04_18_D6_54_1B_B7:1:power"
}
Number		mP6_01_01_E	"mP6_01_01 Energy [%d Wh]"	<energy>	(gmPower)	{channel="mpower:socket:04_18_D6_54_1B_B7:1:energy
"}
Number		mP6_01_01_V	"mP6_01_01 Voltage [%d V]"	<energy>	(gmPower)	{channel="mpower:socket:04_18_D6_54_1B_B7:1:volta
ge"}
DateTime	mP6_01_01_U	"mp6_01_01 Update [%1$td.%1$tm.%1$tY %1$tH:%1$tM]"	<text>	(gmPower)	{channel="mpower:socket:04_18_D6_5
4_1B_B7:1:lastupdate"}

sitemap:

Frame { 
                Group item=gmPower label="mPower Outlets" icon="energy"
        }

This is beautiful ! :sunglasses: :sunglasses: :sunglasses:

1 Like

I think that this deserves the attention of the @maintainers. @magcode has produced an excellent 2.0 binding for the mfi mPower devices.

It is very robust and it may be ready for release as a new openHAB 2 Binding.

I will continue testing it but so far it is very easy to use (via Paper UI and/or via manual configs)

The outlets respond immediately to commands and everything works as expected (even tried some rules).

Thanks @Dim for testing. :bow:

Meanwhile I improved the timing a bit:

  • Optimized for a good balance: Don’t spam OH with too many updates. vs. Don’t bother the mPower with too many value reading requests.
  • If you switch a socket, after 3 seconds an update will be forced. This gives a nice feedback in the UI.
  • If a socket is turned off, basically no updates are pushed to Openhab. (you can see this by watching the “Last Update” channel.)
  • If a socket is turned on, its updated every x seconds (as configured in the bridge/mPower). Even here there might be an older “Last Update” value e.g. your device consumes a steady “Power” of 3 Watts, the “Voltage” stays steady at 230V, the “Energy Consumption” is climbing slowly only.
  • The minimum refresh is 10.000 ms. Default is 20.000 ms.

Beside that

  • sockets are now marked offline as soon as the mpower gets offline.
  • Watchdog checks now every 2 minutes.
  • lastUpdate channel is “advanced” now

will release a new beta later next week.

1 Like

Excellent!

Only 1 small/minor issue to report from my test environment:

If I define manually the bridge (power strip) and the sockets in a file (/etc/openhab2/things/mPower.things) :

Bridge	mpower:mpower:04_18_D6_54_1B_B7	"mP6-01"	[ host="172.16.13.1", password="ubnt", username="ubnt" ]
 {
	socket	1	"LAN Switch"	@	"mPower"	[ socketNumber="1" ]
	socket	2	"HomeR"			@	"mPower"	[ socketNumber="2" ]
	socket	3	"NAStorage"		@	"mPower"	[ socketNumber="3" ]
	socket	4	"ZTE Router"	@	"mPower"	[ socketNumber="4" ]
	socket	5	"HP Printer"	@	"mPower"	[ socketNumber="5" ]
	socket	6	"rPi3"			@	"mPower"	[ socketNumber="6" ]
}

…the socket number is not displayed when I navigate to the thing from Paper UI (Paper UI -> Configuration -> Things -> Edit)

…on HABmin, it displays correctly:

If I define my things via Paper UI, all works ok (if I remember well… i will double check). This is not important, since if you are working with manual definitions, you won’t be able to modify the thing config parameters from the UIs anyway, so it’s ok.

please try:

remove all your things from *.things file.
Save *.things file
revert everything and remove the quotes around socketNumber value
Save *.things file

Works?

socket	1	"LAN Switch"	[ socketNumber=1 ]
1 Like

Hell, yeah :slight_smile:

Bridge	mpower:mpower:04_18_D6_54_1B_B7	"mP6-01"	[ host="172.16.13.1", password="ubnt", username="ubnt" ]
 {
	socket	1	"LAN Switch"	@	"mPower"	[ socketNumber=1 ]
	socket	2	"HomeR"			@	"mPower"	[ socketNumber=2 ]
	socket	3	"NAStorage"		@	"mPower"	[ socketNumber=3 ]
	socket	4	"ZTE Router"	@	"mPower"	[ socketNumber=4 ]
	socket	5	"HP Printer"	@	"mPower"	[ socketNumber=5 ]
	socket	6	"rPi3"			@	"mPower"	[ socketNumber=6 ]
}

It would be useful to update your very good docs entry to show how someone can manually configure (if doesn’t want to use Paper UI) all options also in the .thing file:

Example (includes refresh interval):

Bridge  mpower:mpower:04_18_D6_54_1B_B7 "mP6-01"        [ host="172.16.13.1", refresh=60000, username="ubnt", password="ubnt" ] {
        socket  1       "LAN Switch"    @       "mPower"        [ socketNumber=1 ]
        socket  2       "HomeR"         @       "mPower"        [ socketNumber=2 ]
        socket  3       "NAStorage"     @       "mPower"        [ socketNumber=3 ]
        socket  4       "ZTE Router"    @       "mPower"        [ socketNumber=4 ]
        socket  5       "HP Printer"    @       "mPower"        [ socketNumber=5 ]
        socket  6       "rPi3"          @       "mPower"        [ socketNumber=6 ]
}

PR #1: https://github.com/magcode/openhab2-addons/pull/1 :slight_smile:

Hi, magcode.
Thanks much for your work!
In my case I found that my devices wouldn’t work with logs showing "auth failed"
After some tinkering it turned out that an exclamation mark (!) in my password prevented it from working.
I changed my password to a-z 9-0 password and it works well now.

Thank you.

  • Serg
1 Like

Small update: So far, all is working fine.

Just upgraded to the latest snapshot and tested the mPower 2.0.01-SNAPSHOT binding again.

root@host:~# more /var/lib/openhab2/etc/version.properties
openHAB Distribution Version Information
----------------------------------------
build-no        : Build #752
online-repo     : https://dl.bintray.com/openhab/mvn/online-repo/2.1.nightly

Repository        Version
----------------------------------------
openhab-distro  : 2.1.0-SNAPSHOT
smarthome       : 0.9.0-SNAPSHOT
openhab-core    : 2.1.0-SNAPSHOT
openhab1-addons : 1.10.0-SNAPSHOT
openhab2-addons : 2.1.0-SNAPSHOT
karaf           : 4.0.8

Hello Serg,

I tried but I could not reproduce the issue with the “!” in a password.
I tried both: manually defined in things file but also discovered mPower. I used the password “ubnt!123”. Works fine. Can you give more details/screenshots please?

@Dim thanks for testing and PR. It is merged now. Glad to see it working.

1 Like

and a new beta version: https://github.com/magcode/openhab2-addons/releases

Main change is a reworked timing as described above.
I’ll wait for more feedback and testing results till end of next week before I >>>TRY<<< my first “official” contribution to OH via a PR. :slight_smile:

1 Like

I think I spoke too soon, I’m still tinkering and the only combination that worked for me was ubnt:ubnt
I then changed my login to admin and password to alphanumeric string and still had “Auth Failed” show up in logs. I will try to reproduce it today and send you logs with screenshots. I will also try login ubnt with a changed password and see if it’s a login name problem.

  • Serg

Tested the new mPower binding version 2.0.02 on 3 different systems:
Main System 1: Laptop with Debian Jessie (my main system) running OH2 Snapshot #752
Test System 2: Laptop with Windows 10 x64 PC running OH2 2.0.0 Stable Release
Test System 3: Raspberry Pi 3 with Raspbian Jessie running OH2 2.0.0 Stable Release

All systems work perfectly and multiple tests were run with successful results.

I also like that if I lock one of the outlets in the mfi controller suite (put it in monitoring mode only), I cannot switch it off from OH2 :slight_smile: (this works as I expected)

Thanks @Dim for all your testing efforts :bow:

put it in monitoring mode only

Oh! I didn’t know about that feature. So its rather coincidence that the binding works “as expected”.

But … would it be an idea to add this feature to the binding? Like

socket  1       "LAN Switch"    @       "mPower"        [ socketNumber=1, monitoringMode=true ]

(No idea yet, how exactly this featured is realized on mPower “OS Level” though.)

1 Like

That would be a nice extra feature (to be able to lock / unlock the outlet from openHAB2 also)

In the mfi controller, you can set this lock when you configure the device:

This disables the On/Off button and the outlet cannot be switched off (either from mfi or from openHAB)

Maybe I can capture the packets that the mfi controller sends to the power strip to investigate the command sequence for this feature :slight_smile: More news soon…

1 Like

Cool. Let me know if you find something!

Update. I guess its rather easy:

/proc/power/lock
1 Like

so the idea would be to configure the “socket” thing with an additional property: lock = true/false.
At some point (maybe once I first try to switch it OFF) the “lock” will be actively set by the binding.