Broadlink binding for RMx, A1, SPx and MP. Any interest?

Looks like there’s a big problem communicating with these 4th-generation (?) devices. Looking at the Python-broadlink repository, it looks like they use a special header on each request - this binding doesn’t do that … yet.

Hoping to get something out this weekend to address this. Sorry for the delay.
Cheers,
John

4 Likes

Hi all, looks like I have the same issue like the rest. I have RM4 mini and I couldnt find it automatically. I added the thing manually, filled in IP, port and MAC and I am getting constantly: Status: OFFLINE - COMMUNICATION_ERROR Couldn’t authenticate

Here are my logs:

2020-06-14 00:58:51.897 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4:67261b7f[v]: Authentication failed: 
java.net.ProtocolException: Response from device is not valid. (0x22=0xFF,0x23=0xFF,0x24=0xFF)
        at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket(BroadlinkProtocol.java:191) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket(BroadlinkBaseThingHandler.java:184) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.authenticate(BroadlinkBaseThingHandler.java:133) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.transitionToOnline(BroadlinkBaseThingHandler.java:262) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus(BroadlinkBaseThingHandler.java:218) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler$1.run(BroadlinkBaseThingHandler.java:95) [bundleFile:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_251]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_251]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_251]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_251]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_251]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_251]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_251]
2020-06-14 00:58:51.898 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4:67261b7f[v]: Attempting to authenticate prior to getting device status FAILED. Will mark as offline
2020-06-14 00:58:51.898 [WARN ] [handler.BroadlinkRemoteModel4Handler] - rm4:67261b7f[v]: Online -> Offline due to: Couldn't authenticate

Any idea what next? Are the pre-filled authorization key and IV correct? Thanks

OK RM4 owners, please try out BETA 10 available here:

https://github.com/themillhousegroup/openhab2-addons/releases/download/BROADLINK_2.5.BETA_10/org.openhab.binding.broadlink-2.5.1-SNAPSHOT.jar

This one builds in all the 4th-generation protocol changes as implemented by the Python code (linked just above in this discussion). Unfortunately I don’t have an RM4 device so have to work blind on this, but I have added some substantial unit testing based on network captures kindly provided by people in this thread so have some confidence that it’ll work…

There’s also a worthwhile improvement to ALL RM- devices (not just RM4s) - when sending a remote code, it used to throw a big error if the code was not an exact multiple of 16 bytes in length.
That’s now been rectified - the binding will automatically now “pad” the code with zero-bytes to make it the correct length to be transmitted by the Broadlink device. I’ve checked this on my RM mini 3.

Cheers and enjoy!
John

@themillhousegroup Thanks for the update. I am getting same issues with both RM3mini and RM4mini:

2020-06-17 15:35:05.741 [ERROR] [dlink.handler.BroadlinkRemoteHandler] - rm3:c8-f7-42-40-0c-f9[v]: Authentication failed: 
java.net.ProtocolException: Response from device is not valid. (0x22=0xFF,0x23=0xFF,0x24=0xFF)
        at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket(BroadlinkProtocol.java:191) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket(BroadlinkBaseThingHandler.java:204) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.authenticate(BroadlinkBaseThingHandler.java:147) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.transitionToOnline(BroadlinkBaseThingHandler.java:287) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus(BroadlinkBaseThingHandler.java:243) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler$1.run(BroadlinkBaseThingHandler.java:109) [bundleFile:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_251]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_251]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_251]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_251]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_251]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_251]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_251]
2020-06-17 15:35:05.743 [ERROR] [dlink.handler.BroadlinkRemoteHandler] - rm3:c8-f7-42-40-0c-f9[v]: Attempting to authenticate prior to getting device status FAILED. Will mark as offline
2020-06-17 15:35:05.744 [WARN ] [dlink.handler.BroadlinkRemoteHandler] - rm3:c8-f7-42-40-0c-f9[v]: Online -> Offline due to: Couldn't authenticate

Is there anything I should do to make it work? This rm3 was added by automatic detection via binding. My RM4 was not detected and had to be added manually.

So for everybody who is struggling with new RM3mini or RM4mini devices and getting Authentication failed message:

Apparently there is some new “feature” in RM devices which disables local API authentication if device is connected to the cloud.

And of course, the official Broadlink app makes it impossible for you to set up the device without connecting it to the cloud. So how did I get things up and running? Manually…

Download the official python-broadlink scripts and set it up (you have to use python3 and run python3 setup.py install ; it does not hurt to update pip3 install -U cryptography as otherwise you may encounter an error about initialization error)

Now once you installed the tools, put your device into AP mode (hold reset button until it starts flashing fast. then hold it once more until it starts flashing a bit slower) run python3 and lets get to some in-line coding:

import broadlink
broadlink.setup('myssid', 'mynetworkpass', 3)

Once you do this, the flashing on RMx should stop flashing and after a short while the device will become pingable (find its IP on your router e.g.)

I then wanted to get some IR codes for my broadlink.map, so I had to learn them. To do that, first cd into cli folder of python-broadlink package and edit broadlink_discovery file. On top replace python with python3 , as python2 does not work with this.

Then run ./broadlink_discovery and if your device is set up ok, you will see it detected together with something like

0x2712 1.1.1.1 aaaaaaaaaa

So this is your IP as well as MAC and you use this with another script to start the learning process.

Execute:

broadlink_cli --device "0x2712 1.1.1.1 aaaaaaaaaa" --learn

And point your IR blaster to the RMx, press the buttons and if the gods are with you, you should see a hex and base64 captured code. Use that in your broadlink.map

Now for RM3 device I was able to detect and add it automatically via PaperUI, but for RM4 I had to add device manually. Just select RM4 type, enter IP, MAC (with : separators) and port=80 and you should be good to go. After this the device should show as ONLINE.

So to sum up - if you want to use latest firmware on RM3/4 devices you cannot set them up with Broadlink Android app.

1 Like

You can use the app, but I would certainly recommend your way of doing it though.

See my post, go to its history and wind it back one step and you’ll see instructions on using the app to get your Broadlink device connected to your WiFi.

But I think using python-broadlink is the better way, which is why I switched my instructions to using it once I’d found the correct method!

1 Like

Wow - fantastic work @michnovka and @hafniumzinc - obviously the changes in the 4th-generation devices are even bigger than “just” adding some extra header bytes to the protocol.

@themillhousegroup could you please update the README.md of your binding to reflect these findings? This thread is quite long and confusing for new users and over time our findings will get lost and some other poor soul will waste their afternoon reinventing the wheel. Thanks!

4 Likes

@themillhousegroup Thanks for your work

i have seen a regression on the SP2.

The SP2 get turned off when the thing is becoming online.

Simple to reproduce it:

Disable the thing from paperui
Enable the thing from paper UI => The SP2 Get turned off

i have attached the trace logs
tracelog.txt (10.4 KB)

So I did some debugging. I have total of 5 RMX devices set up in my home, all of them worked fine for 1 day and today out of nowhere some issues started happening (I am not aware of any reboot, maybe there was a router downtime for few minutes, but not sure)

Only one device (the one I configured as the very first one in OpenHab) stays ONLINE ans can send commands. The rest go Offline: Couldn’t find statically-IP-addressed device within few seconds after startup. The behavior is very strange: If I turn any of the broken ones OFF, and turn it back ON, all others start working for about 30 seconds. After that they all go offline again (except for the one).

I can restart any one of those that appear as offline and suddenly all others show up as ONLINE and are functioning as expected. However within 30 seconds, they show as offline.

This is my setup:

RM3 Office - 192.168.1.50 - c8:f7:42:40:0c:f9 
RM4 Gym 192.168.1.180 - 24:df:a7:e8:62:b3
RM4 Bedroom 192.168.1.232 - 24:df:a7:e8:5c:6e
RM4 Guest room - 192.168.1.22 - 24:df:a7:e8:62:15
RM4 Living room - 192.168.1.202 - 24:df:a7:34:b7:5b

This is my items:

String                  BroadlinkRM3_Command                    "Broadlink RM3 Office"   (gACOffice)  { channel="broadlink:rm3:c8-f7-42-40-0c-f9:command" }
String                  BroadlinkRM4_Command                    "Broadlink RM4 Living room"   (gACLounge)  { channel="broadlink:rm4:cd278176:command" }
String                  BroadlinkRM4_MasterBedroom_Command      "Broadlink RM4 Master Bedroom"   (gACMasterBedroom)  { channel="broadlink:rm4:303436bd:command" }
String                  BroadlinkRM4_GuestRoom_Command          "Broadlink RM4 Guest Room"   (gACGuestRoom)  { channel="broadlink:rm4:f59f574e:command" }
String                  BroadlinkRM4_Gym_Command                "Broadlink RM4 Gym"     (gACGym)  { channel="broadlink:rm4:d2f2eed0:command" }

And this is my log:

2020-06-21 18:00:03.211 [WARN ] [handler.BroadlinkRemoteModel4Handler] - rm4:d2f2eed0[^]: Online -> Offline due to: Couldn't find statically-IP-addressed device
2020-06-21 18:00:04.887 [WARN ] [dlink.handler.BroadlinkRemoteHandler] - rm3:c8-f7-42-40-0c-f9[^]: Online -> Offline due to: Couldn't find statically-IP-addressed device
2020-06-21 18:00:06.220 [WARN ] [handler.BroadlinkRemoteModel4Handler] - rm4:f59f574e[^]: Online -> Offline due to: Couldn't find statically-IP-addressed device
2020-06-21 18:00:09.253 [WARN ] [handler.BroadlinkRemoteModel4Handler] - rm4:303436bd[^]: Online -> Offline due to: Couldn't find statically-IP-addressed device

This is for sure a binding error, did anybody experience similar issues whilst using more devices at once? Any ideas how to proceed? Thanks!

EDIT:

There is also something wrong when it comes to updating thing configuration. I changed the IP in Thing configuration via Paper UI, enabled trace logging and I see it still uses the old IP

2020-06-21 18:43:45.782 [TRACE] [dlink.handler.BroadlinkRemoteHandler] - rm3:c8-f7-42-40-0c-f9[v]: updateItemStatus; checking host availability at 192.168.1.50

Only after restarting openhab I got the correct IP in logs.

I also found based on logs that this is the line that fails. I have no idea why though, but it returns false for some of my devices. They are pingable though

EDIT2:

Why do I see

2020-06-21 18:55:00.987 [ERROR] [nding.broadlink.internal.ModelMapper] - Device identifying itself as '25276' is not currently supported. Please report this to the developer!
2020-06-21 18:55:00.988 [ERROR] [nding.broadlink.internal.ModelMapper] - Join the discussion at https://community.openhab.org/t/broadlink-binding-for-rmx-a1-spx-and-mp-any-interest/22768/616

wasnt this supposed to be fixed in the last release?

Hi @michnovka,
Lots to look at in your post!

Firstly, device '25276' corresponds to 0x62bc which is not currently a supported device code. It appears that there are a large number of RM4-class devices with a range of device codes - I’m expanding the ModelMapper to match a range of codes from 0x610f to 0x62bf to try and catch them all - this will be in the next beta release (see below).

Secondly, I’m very suspicious about the fact that your RM3 device appears to work properly but none of your RM4s do. My first guess was that Broadlink have made RM4s un-pingable, but you say that they can be pinged, so I’m quite confused. You can see that the NetworkUtils.hostAvailabilityCheck() is very simple and uses the standard Java mechanisms for determining device reachability. I’d be very interested to see more detailed logs around what happens around that time - especially if you could enable TRACE-level logging for the binding if you still have problems after upgrading to the next beta version.

Thirdly, I’m still worried about the issue that seems to exist in (some recent versions of) PaperUI where configuration value changes (like IP address changes) are not getting passed down to the binding. I’ve added some code to this new version that explicitly “pulls” new configuration in - hopefully this helps.

Here’s Beta 11 with the above changes:
https://github.com/themillhousegroup/openhab2-addons/releases/download/BROADLINK_2.5.BETA_11/org.openhab.binding.broadlink-2.5.1-SNAPSHOT.jar

Cheers,
John

1 Like

Hi, I am new in openHAB and have just managed to install a simple AVM Fritz-Binding and some other very simple things. So please forgive me asking “stupid” noob questions… :wink:
Could one of you please tell me which Broadlink binding is the best one for my purposes and how to install it (since it does not seem to be listed in bindings for easy one click installation)?
I have a RM Pro, a RM Pro Plus and four RM Mini 3 devices and want to control RF plugs and some IR devices (receiver, TV etc.). Thanks a lot in advance!

PS: I am running openHAB 2.5.6 with PaperUI (which should be the best for beginners, right?) on a Windows 10 PC.

I have three broadlink rm3 mini that works almost always well, but sometimes they miss a command. I also notice in the openhab.log that the things go from Online to Offline (As it is an error), but there is no log line stating that they are online again. Is there a way to know if a command has been received by a device? Alternatively, I was looking for a status channel, but the paperUI does show only the “command” channel. In this case I could re-program a rule that issue the command only if the thing is online.

Thank you,
Lionello

have a new rm4 pro but getting

Plugin didn’t detect it so manual added

Status: OFFLINE - COMMUNICATION_ERROR Couldn’t authenticate

in paper UI any suggestions ?

==> /var/log/openhab2/openhab.log <==

2020-06-29 15:37:37.306 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4:38512d12[v]: Authentication failed:

java.net.ProtocolException: Response from device is not valid. (0x22=0xFF,0x23=0xFF,0x24=0xFF)

at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket(BroadlinkProtocol.java:191) ~[bundleFile:?]

at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket(BroadlinkBaseThingHandler.java:206) ~[bundleFile:?]

at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.authenticate(BroadlinkBaseThingHandler.java:149) [bundleFile:?]

at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.transitionToOnline(BroadlinkBaseThingHandler.java:289) [bundleFile:?]

at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus(BroadlinkBaseThingHandle

@Lionello_Marrelli

you need to store the thing status into a switch item with a rule like the one

rule "broadlink:sp2:34-ea-34-f5-ae-aa"
when Thing  "broadlink:sp2:34-ea-34-f5-ae-aa" changed
then
{

		var String thingStatusInfo = getThingStatusInfo("broadlink:sp2:34-ea-34-f5-ae-aa").getStatus.toString
		switch (thingStatusInfo) {
			case "ONLINE" : {thingStatusInfo="ON"}
			default : {thingStatusInfo="OFF"}
		}		
		
		
    logInfo("txtBroadlink SP2 [192.168.1.105] SP2_3-thingStatusInfo", thingStatusInfo.toString)
		SP2_3_LastUpdate.postUpdate(new DateTimeType())
		SP2_3_Status.sendCommand(thingStatusInfo.toString)
		

}
end  

you can persist the Switch item and use this timeline Timeline for Basic UI

1 Like

Did you block internet access for your broadlink devices? Mine always disconnected for a few seconds and then reconnected. This stopped when I allowed internet access for the broadling in the router settings.

Hi,
I’m new to openHAB, I use openHAB 2.5.6-2, I downloaded the latest available version of addon:

org.openhab.binding.broadlink-2.5.1-SNAPSHOT.jar

and installed it in the path:
/usr/share/openhab2/addons/
I blocked the internet access of the RM4 mini, I see the device in things but in error:

Broadlink RM4 Mini / RM4 Pro [192.168.2.26]
Broadlink RM4
The Broadlink RM 4 is an IR transmitter with Wi-Fi connectivity.
Status: OFFLINE - COMMUNICATION_ERROR Couldn’t authenticate

In the log I see:

2020-07-03 19: 03: 05.753 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4: 24-df-a7-e8-6b-98 [v]: Attempting to authenticate prior to getting device status FAILED. Will mark as offline
2020-07-03 19: 03: 05.755 [WARN] [handler.BroadlinkRemoteModel4Handler] - rm4: 24-df-a7-e8-6b-98 [v]: Online -> Offline due to: Couldn’t authenticate
2020-07-03 19: 03: 35.781 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4: 24-df-a7-e8-6b-98 [v]: Authentication failed:
java.net.ProtocolException: Response from device is not valid. (0x22 = 0xFF, 0xFF = 0x23, 0x24 = 0xFF)
at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket (BroadlinkProtocol.java:191) ~ [bundleFile :?]
at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket (BroadlinkBaseThingHandler.java:206) ~ [bundleFile :?]
at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.authenticate (BroadlinkBaseThingHandler.java:149) [bundleFile :?]
at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.transitionToOnline (BroadlinkBaseThingHandler.java:289) [bundleFile :?]
at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus (BroadlinkBaseThingHandler.java:245) [bundleFile :?]
at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler $ 1.run (BroadlinkBaseThingHandler.java:109) [bundleFile :?]
at java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:511) [?: 1.8.0_212]
at java.util.concurrent.FutureTask.runAndReset (FutureTask.java:308) [?: 1.8.0_212]
at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 301 (ScheduledThreadPoolExecutor.java:180) [?: 1.8.0_212]
at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:294) [?: 1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149) [?: 1.8.0_212]
at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:624) [?: 1.8.0_212]
at java.lang.Thread.run (Thread.java:748) [?: 1.8.0_212]
2020-07-03 19: 03: 35.789 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4: 24-df-a7-e8-6b-98 [v]: Attempting to authenticate prior to getting device status FAILED. Will mark as offline
2020-07-03 19: 03: 35.791 [WARN] [handler.BroadlinkRemoteModel4Handler] - rm4: 24-df-a7-e8-6b-98 [v]: Online -> Offline due to: Couldn’t authenticate

What can I do to make authentication work?
I tried with:
097628343fe99e23765c1513accf8b02
562e17996d093d28ddb3ba695a2e6f58

and

097628343fe99e23765c1513accf8b02
8c393262037dfc87fd511150db7133dd
but I always get the same error.

Can you help me ?
Kind regards,
Elia

It should be part of the Thing definition see below

Hello nakh_Home.
thanks for your answer, but I tried both strings.

I tried with:
097628343fe99e23765c1513accf8b02
562e17996d093d28ddb3ba695a2e6f58

and

097628343fe99e23765c1513accf8b02
8c393262037dfc87fd511150db7133dd

inserting the first in authenticationKey and the second in IV, but I always get the same error in the log.
I am using a mini RM4.
Do you have any other ideas?
Kind regards,
Elia

My RM4 connection to openhab using the broadlink binding was working fine until yesterday. I inadvertently responded to the Broadlink RM4 upgrade request and now - similar to Eliah I am now getting the “Status: OFFLINE - COMMUNICATION_ERROR Couldn’t authenticate”. Has the upgrade changed the authentication key?