Broadlink/Bestcon RM4C Mini via MQTT

It’s taken me some time to get this all working, so I hope this is useful for someone else!

The situation

The room has one of these fan/light combos on the ceiling. The whole fixture can be controlled via the included infra-red (IR) remote, which looks like this:

To enable automation of the fan/light I got a Broadlink RM4C Mini (branded as BestCon).

Click here for prerequisites
  • MQTT broker - I use Mosquitto , setup as per its defaults
    • On my setup, Mosquitto and OpenHab are running on the same device, at 192.168.1.92
  • Javscript Transformation installed in OpenHab
    • PaperUI -> Add-ons -> Transformations -> Javascript Transformation -> Install
Click for system details

Setup was on a Raspberry Pi 3B+ on Stretch, with OpenHAB2 2.5.3, as shown below. A mosquitto mqtt broker is also running on the network, and python3 is installed.

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
pi@raspberrypi:~ $ apt list openhab2
Listing... Done
openhab2/stable,now 2.5.3-1 all [installed]

Configuration

Install python-broadlink

Install the python-broadlink package directly from github. I used the following commands:

sudo apt-get install python3-dev python3-pip git
git clone https://github.com/mjg59/python-broadlink.git
cd python-broadlink
python3 -m pip install pycrypto
python3 -m pip install netaddr
python3 -m pip install --upgrade pyopenssl
sudo python3 setup.py install

Connect RM4C Mini to wifi

The following methods will connect the RM4C Mini to the local wifi network:

  1. The first method uses only the python-broadlink project
  2. The second uses the Broadlink app

I recommend trying the first option first, if only so you don’t have to make a Broadlink account.

Important Only get the RM4C Mini connected to your wifi network - DO NOT allow it to connect to the cloud.

Method 1 - python-broadlink

Important Perform the following steps using your native/local machine, not through an SSH terminal. This method will connect your device to the RM4C Mini’s wifi, so you may lose your SSH connection!

  1. Connect the RM4C Mini to power, and press the reset button until the blue light starts to flash quickly (multiple times a second).
  2. Press the reset again for longer (>10 seconds) until the blue light starts to flash more slowly (about once per second).
  3. The RM4C Mini is now a wifi access point. Connect your computer to the access point (it will probably have Broadlink in the name). It may take a little bit of time for the access point to appear in your wifi list.
  4. Once connected, in a terminal on your computer, start the python console by typing python3 and hitting enter.
python3
  1. Import the broadlink library by typing the following and hitting enter.:
import broadlink
  1. Send your wifi credentials to the device by typing the following, swapping out mysside and mynetworkpass for your wifi name and password respectively, and hitting enter.:
broadlink.setup('myssid', 'mynetworkpass', 3)
  1. You don’t seem to get any feedback to announce it has worked, other than your PC losing connection as the RM4C Mini stops being an access point and connects to your wifi.
  2. Once I’d confirmed that the RM4C Mini was connected to my network via the wifi routers management pages, I had to re-power the device for the next steps to work (pull the power cable out, count to 10, put the power cable back in).
  3. At this point, I also blocked the RM4C Mini from accessing the internet, again using the wifi routers management pages.

Note: to exit from the python3 console in your terminal, type exit() and hit enter.

Method 2 - Broadlink app
  1. Install the Broadlink app from the Android Play store (I presume an iOS equivalent is available)
  2. Make an account with Broadlink - this is unfortunately necessary because you can’t seem to use the app without one
  3. Exit out of the app completely (for me, that’s pressing the square icon on the Android menu bar at the bottom of the screen, then swiping that app window upwards)
  4. Connect the RM4C Mini to power, and press the reset until the blue light starts to flash quickly (multiple times a second)
  5. Press the reset again for longer (>10 seconds) until the blue light starts to flash more slowly (about once per second).
  6. The RM4C Mini is now a wifi access point. Connect your phone to the access point (it will probably have Broadlink in the name). It may take a little bit of time for the access point to appear in your wifi list.
  7. Once connected, start up the Broadlink app. I was asked for a bunch of information again (country etc), and had to login again. There was then a complaint that it can’t connect to the internet, but ultimately it goes through a ‘home screen’, and it will inform you (potentially not immediately) that it has found a compatible device.
  8. Choose to setup the device, and enter your home wifi name and password. Watch as it sets up the device, then exit the app again.
  9. Find out the IP address of the RM4C Mini on your network using your wifi router’s management pages. Mine was 192.168.1.120 .
  10. At this point, I also blocked the RM4C Mini from accessing the internet, again using the wifi routers management pages.

Check connection

Whilst in the python-broadlink folder in your terminal, move to the cli folder.

cd cli/

Open the broadlink_discovery file, and alter the top line so it references Python 3:

#!/usr/bin/env python3

Try to discover the RM4C Mini. Replace the IP address with the one for your RM4C Mini device:

./broadlink_discovery --timeout 10 --dst-ip 192.168.1.120

Hopefully that works, and you will get something similar to the output below:

Discovering...
###########################################
RM4
# broadlink_cli --type 0x62be --host 192.168.1.120 --mac a57c4fa7df24
Device file data (to be used with --device @filename in broadlink_cli) : 
0x62be 192.168.1.120 a57c4fa7df24
temperature = 0.0

Install broadlink-mqtt

Note You can now switch to SSHing into your Raspberry Pi, and continue following the steps below.

Setup is as per the installation instructions at on github.

  • Ensure the named prerequisites are installed.
  • At the configuration step, the only lines I altered in custom.conf was entering the correct IP address for my mqtt broker and un-commenting the mqtt_birth_topic and mqtt_birth_payload lines.

Startup broadlink-mqtt using python3 from within the broadlink-mqtt folder:

python3 mqtt.py
[2020-05-03 16:10:50,482] DEBUG Connected to 'RM4' Broadlink device at '192.168.1.120' (MAC 24:df:a7:4f:7c:a5) and started listening for commands at MQTT topic having prefix 'broadlink/' 
[2020-05-03 16:10:50,493] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#

Connected! Move this terminal or command window to one side - we’ll call it Terminal 1.

Teach remote codes

Two methods again. The first uses broadlink-mqtt and should be the easiest. However, this sometimes results in errors (usually as a result of issues with python-broadlink), so the second method uses the base commands from python-broadlink. Both routes will ensure you end up at the same place!

Click to teach via broadlink-mqtt

Teach via broadlink-mqtt

To teach broadlink-mqtt what each button press is for, you:

  1. Tell broadlink-mqtt (via MQTT) that you’re about to press a specific button
  2. Press the button (and keep it pressed) whilst pointing it at the RM4C Mini.

The example below is for the button which turns the light on and off. In a second terminal (Terminal 2) type:

mosquitto_pub -t 'broadlink/masterbedroom/light/power' -m 'record'

Point the remote at the RM4C Mini and press the button until the messages in Terminal 1 says Done, as below:

[2020-05-02 08:25:57,997] DEBUG Received MQTT message broadlink/masterbedroom/light/power record
[2020-05-02 08:25:57,998] DEBUG Recording command to file ~/src/broadlink-mqtt/commands/masterbedroom/light/power
[2020-05-02 08:26:09,023] DEBUG Done

You can test if this has worked by entering the following into Terminal 2, which should force the RM4C Mini to blast out the correct IR command, and switch on the light:

mosquitto_pub -t 'broadlink/masterbedroom/light' -m 'power'

I repeated this process for the 4 fan buttons too: hi, med, low and off:

mosquitto_pub -t 'broadlink/masterbedroom/fan/hi' -m 'record'
mosquitto_pub -t 'broadlink/masterbedroom/fan/med' -m 'record'
mosquitto_pub -t 'broadlink/masterbedroom/fan/low' -m 'record'
mosquitto_pub -t 'broadlink/masterbedroom/fan/off' -m 'record'
Click to teach via python-broadlink

Teach via python-broadlink

In a terminal, enter the python3 console:

python3
Python 3.6.9 (default, Jul 17 2020, 12:50:27) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

import the python-broadlink module by typing import broadlink and hitting enter. You won’t get any feedback other than a new prompt >>>:

>>> import broadlink
>>> 

discover your device You won’t get any feedback other than a new prompt >>>:

>>> devices = broadlink.discover(timeout=5)
>>> 

check that the device was discovered:

>>> print(devices)
[<broadlink.rm4 object at 0x7fe1e484ce10>]
>>> 

connect to your device. This should return True when connected:

>>> devices[0].auth()
True
>>> 

Put device into learning mode. The white LED on the device should then become visible (different devices [non-RM4C Mini] may have different coloured LEDs).

>>> devices[0].enter_learning()
>>> 

Point your remote at the device, and keep the desired button pressed until the white LED turns off. Then, in the terminal grab the data:

>>> packet = devices[0].check_data()
>>>

and print the data to the screen:

>>> print(packet.hex())
2600b0040d2b0c2b0d2a0d2a0d2b280f0d2a0d2b0c000108280f290f0c2b0d2a0d2b0c2b0d2a0d2b280f0c2b0d2a0d000108290e290e0d2b0c2b0d2a0d2b0c2b0d2a290f0c2b0c2b0d000108280f290e0d2a0d2b0c2b0d2a0d2b0c2b280f0d2b0c2b0c000108290f280f0c2b0d2a0d2b0c2b0d2a0d2b280f0d2a0d2a0d000108280f290f0c2b0d2a0d2a0d2b0c2b0d2a290f0c2b0d2a0d000108280f280f0d2b0c2b0d2a0d2a0d2b0c2b280f0d2b0c2b0d000107290f280f0d2a0d2b0c2b0d2a0d2b0d2a280f0d2a0d2b0d000107280f290f0c2b0e290d2b0c2b0d2a0d2b280f0c2b0d2a0d000108280f290f0c2b0d2a0d2a0e2a0c2b0d2a290f0c2b0d2a0d000108280f280f0d2b0c2b0d2a0d2a0e2a0c2b280f0d2b0c2b0d000107290f280f0d2a0d2b0c2b0d2a0d2a0e2a280f0d2a0d2b0d000107280f290f0c2b0d2a0d2b0c2b0c2b0e29290f0c2b0d2a0d000108280f280f0d2b0c2b0d2a0d2b0c2b0c2b280f0d2b0c2b0d000108280f280f0d2a0d2b0c2b0d2a0d2b0c2b280f0d2a0d2b0c000108290f280f0c2b0d2a0d2b0c2b0d2a0d2b280f0c2b0d2a0d000108280f290f0c2b0c2b0d2a0d2b0c2b0d2a290f0c2b0d2a0d000108280f280f0d2b0c2b0d2a0e290e2a0d2a280f0d2b0d2a0d000107290f280f0d2a0e2a0d2a0d2a0e290e2a280f0d2a0e2a0c000108280f290f0c2b0d2a0d2b0c2b0c2b0d2a290f0c2b0d2a0d000108280f28100c2b0c2b0d2a0d2b0c2b0c2b28100c2b0c2b0d000108280f280f0d2a0d2b0c2b0d2a0d2b0c2b28100c2b0c2b0c000108281028100b2b0d2a0d2b0c2b0d2a0d2b28100c2a0d2b0c000108281027100c2b0c2b0d2a0d2b0c2b0d2a29100b2b0d2a0d000108281027100c2b0c2b0c2b0d2b0c2b0c2b28100c2b0c2b0c000108291027100c2a0d2b0c2b0c2b0d2b0c2b28100c2a0d2b0c000108281028100b2c0c2b0c2c0b2c0b2b0d2b28100b2c0c2b0c000108281027100c2c0b2c0c2b0c2b0c2c0b2c27100c2c0b2c0c000108281027100c2b0c2c0b2c0c2b0c2b0c2c27100c2b0c2c0b000109281027100b2c0c2b0c2c0b2c0c2b0c2c27100c2b0c2b0c000109271027100c2c0b2c0c2b0c2c0b2c0c2b28100b2c0b2c0c000109271027100c2b0c2c0b2c0c2b0c2c0b2c27100c2c0b2c0b000109281027100c2b0c2b0c2c0b2c0c2b0c2c27100c2b0c2c0b000109271028100b2c0c2b0c2c0b2c0b2c0c2b28100b2c0c2b0c000109271027100c2c0b2c0c2b0c2c0b2c0b2c27110b2c0b2c0c000108281126110b2b0c2c0b2c0c2b0c2c0b2c27110b2b0c2c0b000109271127110a2c0c2b0c2c0b2c0c2b0c2c27110a2c0c2c0b000109271126110b2c0b2c0c2b0c2c0b2c0c2b27110b2c0b2c0c00010a261126110b2c0b2d0a2d0b2c0b2d0a2d26110b2d0a2d0a00010a271126110a2d0b2c0b2d0a2d0b2c0b2d26110b2c0b2d0a00010a261127110a2d0b2c0b2c0b2d0a2d0b2c27110a2d0b2c0b00010a261225120a2d0a2e092d0b2d0a2e092e25120a2e092e0a00010a261225120a2d0a2e092e0a2d0a2d0a2e25120a2d0a2e0900010b25122612092f092e092e092f082f092e2513082f092e0900010c24132413092f082f092f082f0830082f2314082f08300800010d23142315073007300731073007300731221606310631060001102117200001691a000d05000000000000

This huge string is the code which needs to be saved. To double check that it works, you can send this code through python-broadlink back to your RM4C Mini device, and see whether it has the desired effect (switch things on/off etc):

>>> devices[0].send_data(packet)
>>> 

We now need to save this huge string so that broadlink-mqtt can use it. First, you need to decide what the structure of your MQTT topic will be. For me, the above example captured the power button on the remote, so I’m going to use the topic

broadlink/masterbedroom/light/power

As a result, go into the broadlink-mqtt folder, then into commands, and create a folder called masterbedroom. Inside masterbedroom, create a folder called light.

Inside the light folder, create an empty text file called power (strictly no extensions such as .txt), and inside that file copy and paste the huge string you’ve just captured.

And that’s it. I repeated the same thing for the fan commands (hi, med, low, off), saving those into the following topics/files:

broadlink/masterbedroom/fan/hi
broadlink/masterbedroom/fan/med
broadlink/masterbedroom/fan/low
broadlink/masterbedroom/fan/off

Configure OpenHAB

bridge.things

I have a separate file which just contains the bridge Thing to my Mosquitto MQTT broker:

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
	host="192.168.1.92",
	secure=false,
	port=1883,
	clientID="OpenHAB2"
]

broadlink.things

Thing mqtt:topic:swBedroomLight "Switch Bedroom Light" (mqtt:broker:MosquittoMqttBroker) {
	Channels:
		Type switch : swPower "Power switch" [
			commandTopic="broadlink/masterbedroom/light",
			on="power",
			off="power"
		]
		Type switch : swReachable "Reachable" [
			stateTopic = "clients/broadlink",
			on="Hello!",
			off="Adios!"
		]
		Type number : swFanControl "Fan control" [
			commandTopic="broadlink/masterbedroom/fan",
			transformationPatternOut="JS:bedroomfan.js"
		]
}

bedroomfan.js

Saved into the transform folder:

(function(x) {
	var result = "";

	switch(x) {
		case '0':
	    		result="off";
			break;
		case '1':
	    		result="low";
			break;
		case '2':
	    		result="med";
			break;
		case '3':
	    		result="hi";
			break;
		default:
			result="off";
	}

	return result;
})(input)

broadlink.items

Switch sBedroomMainLight "Bedroom Main Light" { channel="mqtt:topic:swBedroomLight:swPower", autoupdate="false"}
Switch sBedroomMainLightReachable "Bedroom Main Light Reachable" { channel="mqtt:topic:swBedroomLight:swReachable" }

Number nFanControl "Bedroom fan control" { channel="mqtt:topic:swBedroomLight:swFanControl" }

Sitemap

(See the next post for alternative Sitemap configurations)

image

Switch item=sBedroomMainLight label="sBedroomMainLight"  mappings=[ON="PUSH"]
Setpoint item=nFanControl label="Fan speed [%d]" icon="fan" minValue=0 maxValue=3 step=1

I hope this helps someone, and would be happy to hear about more efficient or elegant methods! I’m especially interested in any solutions for the dimmer button. When pressed, this reduces the brightness to a minimum level, then increases it again to maximum. Each press is a decrease or increase, depending on which part of the curve the light is currently on…


Edits

Edit 27/12/2020: Added command to upgrade existing pyopenssl package.

Edit 23/08/2020: Added section in teaching codes to use base python-broadlink commands, as some are having issues with teaching via broadlink-mqtt.

Edit 17/08/2020: Improved formatting slightly, and added instructions to ensure the discovery script is run using Python 3.

Edit 04/08/2020: Added notes regarding what device you should be performing particular actions with.

Edit 31/05/2020: Managed to setup the device on the Wifi without needing the app! Instructions updated.

Edit 30/05/2020: broadlink-mqtt has now implemented Last Will and Testament (LWT) messages. Added the default configuration into the thing and item descriptions.

8 Likes

Improvements

Since the original post I’ve made improvements.

Selection picker

Instead of a Setpoint speed picker, we’re now using a Selection picker. This allows mapping of friendly names to the speed numbers.

image

image

Sitemap snippet

Switch item=sBedroomMainLight label="Bedroom main light []" icon="light" mappings=[ON="PUSH"]
Selection item=nFanControl label="Fan speed" icon="fan" mappings=[0="HI", 1="MED", 2="LOW", 3="OFF"]

bedroomfan.js

Note that the speed numbers have been switched round, where 0 = HI and 3 = OFF. In the Android app the numbers are shown in ascending order, top to bottom. I wanted HI to appear at the top, and OFF to appear at the bottom, hence the order in the Selection. As a result, the transformation file bedroomfan.js has had to be flipped around:

(function(x) {
	var result = "";

	switch(x) {
		case '3':
	    		result="off";
			break;
		case '2':
	    		result="low";
			break;
		case '1':
	    		result="med";
			break;
		case '0':
	    		result="hi";
			break;
		default:
			result="off";
	}

	return result;
})(input)

Switch with mappings

Screenshot

image

Sitemap snippet

Switch item=sBedroomMainLight label="Bedroom main light []" icon="light" mappings=[ON="PUSH"]
Switch item=nFanControl label="Main fan []" icon="fan" mappings=[0="H", 1="M", 2="L", 3="OFF"]

bedroomfan.js

Same as for use with the Selection picker.


Switch with mappings and no more transformations

By simply changing the channel type for fan control from a number to a string, we no longer need to use a transformation!

broadlink.things

Thing mqtt:topic:swBedroomLight "Switch Bedroom Light" (mqtt:broker:MosquittoMqttBroker) {
	Channels:
		Type switch : swPower "Power switch" [
			commandTopic="broadlink/masterbedroom/light",
			on="power",
			off="power"
		]
		Type switch : swReachable "Reachable" [
			stateTopic = "clients/broadlink",
			on="Hello!",
			off="Adios!"
		]
		Type string : swFanMode "Fan mode" [
			commandTopic="broadlink/masterbedroom/fan"
		]
}

broadlink.items

Switch sBedroomMainLight "Bedroom Main Light" { channel="mqtt:topic:swBedroomLight:swPower", autoupdate="false"}
Switch sBedroomMainLightReachable "Bedroom Main Light Reachable" { channel="mqtt:topic:swBedroomLight:swReachable" }

String strFanMode "Bedroom fan mode" { channel="mqtt:topic:swBedroomLight:swFanMode" }

Sitemap snippet

Switch item=sBedroomMainLight label="Bedroom main light []" icon="light" mappings=[ON="PUSH"]
Switch item=strFanMode label="Main fan []" icon="fan" mappings=[hi="H", med="M", low="L", off="OFF"]

Hi
Do you mean to do it on the openhabian with putty?

Whichever computer you installed python3 and python-broadlink onto. It must be a computer that you can easily change WiFi networks on…

Hi @hafniumzinc,

In the first place, thanks for your post… I`m having problems at the moment of dicovery, when it run the command, it send me this error:

Traceback (most recent call last):
File “./broadlink_discovery”, line 13, in
devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip, discover_ip_address=args.dst_ip)
File “/usr/local/lib/python2.7/dist-packages/broadlink-0.14.0-py2.7.egg/broadlink/init.py”, line 105, in discover
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
AttributeError: exit

Any suggestion about that? I think I follow all steps but I have that problem.

Thanks in advance.

I’m no expert, but I do know that I only got everything working using Python3, after having issues using Python2.7, hence only using Python3 in my example.

If this issue continues I would suggest having a look or searching through the python-broadlink GitHub pages to see if anyone else has experienced the same thing.

Sorry I can’t be of more help!

Hi @hafniumzinc

Thank you for this excellently detailed tutorial.

Unfortunately, I was not able to connect my RM4 Pro to my wifi network using the command you described:
broadlink.setup('myssid', 'mynetworkpass', 3)
[I filled my wifi network credentials].

The RM4 Pro continues to blink slowly and stays in AP mode connected to my Raspberry pi.

Any idea how I can solve this issue?

I don’t unfortunately, other than to unhelpfully steer you towards the python-broadlink project and see if they can help.

Another option is to click the history tab of my first post (top right of my post), and move back a couple of edits - I used to have instructions using the broadlink app which you could try and follow.

Thank you for the idea.
Pressing the “pencil” button next to your original post doesn’t show the history.
I think you are the only one that can see your writing history.
Can you please send me a copy of the history?

Ah, apologies. See below:

Important Only get the RM4C Mini connected to your wifi network - DO NOT allow it to connect to the cloud. The following worked for me:

  1. Install the Broadlink app from the Android Play store (I presume an iOS equivalent is available)
  2. Make an account with Broadlink - this is unfortunately necessary because you can’t seem to use the app without one
  3. Exit out of the app completely (for me, that’s pressing the square icon on the Android menu bar at the bottom of the screen, then swiping that app window upwards)
  4. Connect the RM4C Mini to power, and press the reset until the blue light starts to flash quickly (multiple times a second)
  5. Press the reset again for longer (>10 seconds) until the blue light starts to flash more slowly (about once per second).
  6. The RM4C Mini is now a wifi access point. Connect your phone to the access point (it will probably have Broadlink in the name). It may take a little bit of time for the access point to appear in your wifi list.
  7. Once connected, start up the Broadlink app. I was asked for a bunch of information again (country etc), and had to login again. There was then a complaint that it can’t connect to the internet, but ultimately it goes through a ‘home screen’, and it will inform you (potentially not immediately) that it has found a compatible device.
  8. Choose to setup the device, and enter your home wifi name and password. Watch as it sets up the device, then exit the app again.
  9. Find out the IP address of the RM4C Mini on your network using your wifi router’s management pages. Mine was 192.168.1.120 .
  10. At this point, I also blocked the RM4C Mini from accessing the internet, again using the wifi routers management pages.

Many thanks for sharing the history.
I was able to connect the RM4 Pro using Broadlink’s app and I made sure not to add the device into the app after it connected to my wifi network.
I then disconnected the RM4 Pro from the cable and waited at least 10 seconds.
Next, I reconnected the cable and tried to run the next step in terminal:

pi@raspberrypi:~/python-broadlink/cli $ ./broadlink_discovery --timeout 10 --dst-ip 192.168.1.6

However, I received this error message:

Traceback (most recent call last):
      File "./broadlink_discovery", line 5, in <module>
        import broadlink
    ImportError: No module named broadlink

The script can’t find the python-broadlink module - are you sure you installed it fully, using python3?

I think I installed it correctly with the commands you included:

sudo apt-get install python3-dev python3-pip git
git clone https://github.com/mjg59/python-broadlink.git
cd python-broadlink
python3 -m pip install pycrypto
python3 -m pip install netaddr
sudo python3 setup.py install

This is the terminal output i got when I tried again:

pi@raspberrypi:~ $ sudo apt-get install python3-dev python3-pip git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
git is already the newest version (1:2.20.1-2+deb10u3).
python3-dev is already the newest version (3.7.3-1).
python3-pip is already the newest version (18.1-5+rpt1).
0 upgraded, 0 newly installed, 0 to remove and 167 not upgraded.
pi@raspberrypi:~ $ git clone https://github.com/mjg59/python-broadlink.git
fatal: destination path 'python-broadlink' already exists and is not an empty directory.
pi@raspberrypi:~ $ cd python-broadlink
pi@raspberrypi:~/python-broadlink $ python3 -m pip install pycrypto
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pycrypto in /usr/lib/python3/dist-packages (2.6.1)
pi@raspberrypi:~/python-broadlink $ python3 -m pip install netaddr
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: netaddr in /home/pi/.local/lib/python3.7/site-packages (0.8.0)
pi@raspberrypi:~/python-broadlink $ sudo python3 setup.py install
running install
running bdist_egg
running egg_info
writing broadlink.egg-info/PKG-INFO
writing dependency_links to broadlink.egg-info/dependency_links.txt
writing requirements to broadlink.egg-info/requires.txt
writing top-level names to broadlink.egg-info/top_level.txt
reading manifest file 'broadlink.egg-info/SOURCES.txt'
writing manifest file 'broadlink.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/broadlink
copying build/lib/broadlink/exceptions.py -> build/bdist.linux-armv7l/egg/broadlink
copying build/lib/broadlink/__init__.py -> build/bdist.linux-armv7l/egg/broadlink
byte-compiling build/bdist.linux-armv7l/egg/broadlink/exceptions.py to exceptions.cpython-37.pyc
byte-compiling build/bdist.linux-armv7l/egg/broadlink/__init__.py to __init__.cpython-37.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/not-zip-safe -> build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/requires.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
copying broadlink.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG-INFO
creating 'dist/broadlink-0.14.1-py3.7.egg' and adding 'build/bdist.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing broadlink-0.14.1-py3.7.egg
removing '/usr/local/lib/python3.7/dist-packages/broadlink-0.14.1-py3.7.egg' (and everything under it)
creating /usr/local/lib/python3.7/dist-packages/broadlink-0.14.1-py3.7.egg
Extracting broadlink-0.14.1-py3.7.egg to /usr/local/lib/python3.7/dist-packages
broadlink 0.14.1 is already the active version in easy-install.pth

Installed /usr/local/lib/python3.7/dist-packages/broadlink-0.14.1-py3.7.egg
Processing dependencies for broadlink==0.14.1
Searching for cryptography==2.6.1
Best match: cryptography 2.6.1
Adding cryptography 2.6.1 to easy-install.pth file

Using /usr/lib/python3/dist-packages
Finished processing dependencies for broadlink==0.14.1
pi@raspberrypi:~/python-broadlink $

My version of broadlink_discovery has this as the first line:

#!/usr/bin/env python

I’m no expert, but I think this means that it will try to use python 2 if that’s also installed. If so, try changing that line to:

#!/usr/bin/env python3

Saving, and trying the

./broadlink_discovery --timeout 10 --dst-ip 192.168.1.6

command again.

It’s possible that I have the python-broadlink module installed for both python 2 and python 3, which means that I wouldn’t have got the error you’re showing. If that’s the case, I need to update the guide!

Wonderful!! Changing the first line to python3 worked, as you suggested
:slight_smile:

pi@raspberrypi:~/python-broadlink/cli $ ./broadlink_discovery --timeout 10 --dst-ip 192.168.1.6
Discovering...
###########################################
RM4
# broadlink_cli --type 0x61a2 --host 192.168.1.6 --mac 24dfa7b9c689
Device file data (to be used with --device @filename in broadlink_cli) : 
0x61a2 192.168.1.6 24dfa7b9c689
temperature = 0.0

Now I need to learn how to record my RF remotes to work with this Broadlink binding:
Broadlink binding for RMx, A1, SPx and MP. Any interest?

By chance, do you know a good tutorial for learning RF codes and how to set them up to work with the binding in the link?

1 Like

Excellent - I’ll update my tutorial! Done!

Unfortunately not - I don’t use that binding!

1 Like

OK. You’ve helped me plenty already :slight_smile:
I’ll try to find another way, and if I don’t find one, I’ll try the MQTT solution in your explanation.
Many many thanks :pray: :pray: :pray:

Hi @hafniumzinc
I want to try your full MQTT solution.
Can you suggest which Mosquitto package I should install for your solution?
On the Raspberry pi’s “add/remove software” I see a few Mosquitto packages:

  1. MQTT version 3.1/3.1.1 client library
  2. MQTT version 3.1/3.1.1 client library, development files
  3. MQTT version 3.1/3.1.1 client C++ library
  4. MQTT version 3.1/3.1.1 client C++ library, development files
  5. MQTT version 3.1/3.1.1 compatible message broker
  6. Mosquitto command line MQTT clients
  7. Development files for Mosqiutto

Oooh, no idea! I think I just used the terminal:

sudo apt install mosquitto mosquitto-clients
1 Like

I’ll just do whatever you did :slight_smile:
Hopefully it will will work with no problems :wink: