Broadlink Black Bean (RM 3 Mini) IR Controller - Integration in OpenHAB

(davorf) #62

I forgot to mention that you will need to install pycrypto and netaddr packages in Python besides packages required for previous version.

Best regards,

(farhan) #63

Hi davor,

We also need to install broadlink module, right?

Also, how does learning process work? Will it automatically write learned codes in the .ini file with particular command names?


EDIT: ignore the question. Missed the last paragraph from your previous post :pensive:

(davorf) #64

Hello Farhanito!

Yes, I forgot to mention you’ll have to install broadlink module too. The easiest way to do it would be downloading it from github, and running If you’re using both Python 2.X and Python 3.X make sure you install all additional modules to the right version (2.X)

Best regards,

(davorf) #65

By the way, you should download latest version with some code cleanup.

Best regards,

(Will Waterston) #66

Hi Guys,

I have a RM3 Mini and have been watching this thread develop and all the work that has gone into it… what determination!

I’ve trying to duplicate some of the methods that have been suggested without success so far.

For my latest efforts -

installed e-Control app and captured the power toggle command for my AVR, which works from the app
installed tPatcketCapture on my phone
started e-Control
started tPacketCapture and put in running state with VPN
toggled power from e-Control to AVR (AVR powered off)
stopped tPacketCapture
Copied the file to my (windows) laptop for analysis with wireshark.

When looking at the packets in wireshark I can see traffice to and from my phone, and some broadcast packets, but no packets directed to the IP address of the RM3.

My phone is connected to the same wireless network as the RM3.

Did I miss something in my procedure?

Also, it seems from the latest posts that the python script can now be used to capture packets during learning, is that correct? If so, could someone give the steps for how this is setup? ie, what has to be connected to network, wireless etc?


(davorf) #67

Hello Will!

Since Farhanito posted a broadlink package few days ago I’ve changed my script to use that package instead of intercepted UDP payload. Now it’s also possible to learn commands directly within a script, so you can avoid usage of e-Control app and packet sniffer. You’ll need to download a broadlink package from the github (you can find a link in a post from Farhanito), and run to install it. Note that you must use Python 2.X, because said package doesn’t work with Python 3.X. Besides manually installing broadlink package, you must install netaddr and pycrypto (you can do this via pip install). After that, just fill in IPAddress, Port, MACAddress and Timout in BlackBeanControl.ini and run with switch -c CommandName. That will put RM 3 into learning mode for X seconds (Timeout parameter in BlackBeanControl.ini - should be less than 60 seconds). After that, you should use the button on the remote you wish to learn from. Finally, just call -c CommandName with a name of the command you’ve learned and it will trigger that command.

Best regards,

(diego JIMENEZ) #68

Hi Davor

do you know if it works with RM2 devices?


(davorf) #69

Hello Diego!

The broadlink package Farhanito posted is meant for RM2 (as far as I know). Regarding my script, it’s pretty easy to set it up and test on your device, so you should just try and see if it works. I don’t have RM2, so I can’t tell you from my experience.

Best regards,

(diego JIMENEZ) #70

Thanks a lot

I installed and i can confirm it works with RM2

(Will Waterston) #71

Ok so just to clarify Farhanito’s script does support RM3 Mini? In the description it says RM2.


(Will Waterston) #72

Also, is the idea here that we will always use the python script via the EXEC binding to use the RM3 with openhab? Or is the intention here to use the python script to get (learn) the code which we extract and use in UDP send command?

I have python 3 running on my raspi which is also running openhab. I’m not sure how well an install of python2 will co-exist on the same device. Can I install as you have suggested above onto my Ubuntu machine, learn the codes, then use them with UDP send or some other method that will work? Or will it be fine to also install python2 on my raspi and they will live happily together?


(Lionello Marrelli) #73

Python 2.7 is already installed in raspbian, at least in my raspberry v3. The davorf script worked out of the box in my case. I simply used the exec binding.
The udp binding that I tested had some problems, though: the binding tries to process the udp packet sent back by the mini, therefore the status of the associated items is undefined. They can be solved by writing a javascript function, instead of a simple map file.
The script should read the configuration file written by a suitably modified davorf python script, split the packet randomly modifying the required bytes and finally process the return packet, in order to let the item keep the right state. Unfortunately. I’m not a javascript programmer therefore I cannot actually implement it. I found easier, in my application to awitch to exec byinding with python But if someone is willing to try I’m more than happy to help.

(davorf) #74


Having Python 2.X and 3.X on the same machine is feasible, but you should either use Python launcher and add shebang #!python2 to the beginning of my script, or explicitly call Python 2.X executable before the script name. Regarding usage of UDP payload from the Command section of the BlackBeanControl.ini, I’m not sure if it will work (actually, I’m pretty sure it will not). To be able to save a payload to the .ini, I have to add 4 bytes to the beginning, decrypt it, convert it to hex stream and then write it via configparser to the .ini file. Then, when I read a command payload from the .ini, I convert it back from hex, encrypt it again, cut the first 4 bytes of the payload and send it via broadlink send_data(). Even if a payload would work just without first four bytes (manually deleted from a payload), there still remains a problem with 4 bytes which can’t be the same for 2 consecutive commands, so, fixed payload could only work with the very first solution (using dummy command before actual payload). All in all, it seams much easier to use exec binding and call python script, than doing all this “gymnastics” just to be able to send command via TCP binding.

Best regards,

(farhan) #75


First I’d like to clarify that it’s not my script at all :slight_smile:
I just happened to find that on github and posted it here. All credit goes to @mjg59 the developer.

Yes, it works with RM3, RM2/Pro (including Temperature reading and RF), and probably more Broadlink devices, as it also finds my SPcc (Contros) socket too. Can’t control the socket yet, though.

Hopefully @mjg59 will continue with the development to support even more Broadlink devices. Or maybe you guys here can help him @github.


(Will Waterston) #76

Are there any special networking requirements as to how the RM3 and device with python installed are setup, in order to successfully capture the data?

I have the raspi with python and blackbean capture on a wired network, and the blackbean is on my wireless network connected via an access point which is on the same subnet as the raspi.

In my previous attempts to capture packets using wireshark installed on a windows laptop also connected to the wireless network I have never been able to observe/capture any data directed towards the IP address of the RM3. I’ve seen internet traffic to various addresses during the capture, which come from my phone when using e-Control, but never traffic directly to the blackbean.

I’ll try the python capture during learning and see how it goes.

(Lionello Marrelli) #77

The only way to capture packets to and from the mini that I found was to install wireshark directly on the android device where the broadlink app was installed. In your case, you have to capture packets on the raspberry.

(Sam) #78

trying to get it work on sp mini.

(Will Waterston) #79

well…wow… it works!

installed broadlink package, got the scripts, used the learning mode… the light comes on the RM3 thats a good sign, captured command, replayed command to test… yep it works

awesome! going to get another one of these for another room in the house.

Now to integrate the python commands into EXEC binding in openhab, shouldnt be too hard

thanks everyone :slight_smile:

(davorf) #80

Hello Will!

I’m glad it works. Integrating it into OpenHAB should be fairly easy. The only problem I’ve had was access to PATH environment variable in Windows. I’ve had to put full paths for both, Python 2.7 executable and Here is my Exec binding configuration in .items file:


Remember that, if you are using Exec binding in Windows, you should use @@ instead of blanks in command line (so, two “at” signs instead of one blank).

Best regards,

(davorf) #81

I forgot to mention that, if you’re going to use in OpenHAB, you don’t have to learn commands before connecting them via Exec binding to an item. You just set your item up and the first time you use it, it will trigger a learning mode. That’s the reason I didn’t want to make an additional switch in the script for entering learning mode explicitly.

Best regards,