Broadlink/Bestcon RM4C Mini via MQTT

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:

I followed your tutorial till the Install broadlink-mqtt part, but I’m getting this error message:

pi@raspberrypi:~/broadlink-mqtt $ python3 mqtt.py
Traceback (most recent call last):
  File "mqtt.py", line 3, in <module>
    import paho.mqtt.client as paho  # pip install paho-mqtt
ModuleNotFoundError: No module named 'paho'

Did you follow the instructions here?: https://github.com/eschava/broadlink-mqtt#installation

Either way, in a terminal, try

sudo pip install paho-mqtt

Then try re-running mqtt.py. If that doesn’t work, try:

sudo pip3 install paho-mqtt
1 Like

Yes. I followed the installation process on the link for MQTT client to control BroadLink devices.

Wonderful! This fixed the error message I got.

I’m continuing to the next steps :slight_smile:

Next step, learning remote codes.
I’m seeing this error in Terminal 1:

pi@raspberrypi:~/broadlink-mqtt $ python3 mqtt.py
[2020-08-21 16:59:53,757] DEBUG Connected to 'RM4' Broadlink device at '192.168.1.6' (MAC 89:c6:b9:a7:df:24) and started listening for commands at MQTT topic having prefix 'broadlink/' 
[2020-08-21 16:59:53,764] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#
[2020-08-21 17:01:53,995] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature
[2020-08-21 17:03:54,091] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature
[2020-08-21 17:05:54,104] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature
[2020-08-21 17:07:54,226] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature
[2020-08-21 17:07:55,133] DEBUG Received MQTT message broadlink/bedroom/bedroom_fan/low record
[2020-08-21 17:07:55,133] DEBUG Recording command to file /home/pi/broadlink-mqtt/commands/bedroom/bedroom_fan/low
[2020-08-21 17:08:00,467] ERROR Error
Traceback (most recent call last):
  File "mqtt.py", line 198, in on_message
    record(device, file)
  File "mqtt.py", line 254, in record
    ir_packet = device.check_data()
  File "/usr/local/lib/python3.7/dist-packages/broadlink/__init__.py", line 631, in check_data
    check_error(response[0x22:0x24])
  File "/usr/local/lib/python3.7/dist-packages/broadlink/exceptions.py", line 97, in check_error
    raise exception(error_code)
broadlink.exceptions.StorageError: The device storage is full
[2020-08-21 17:09:54,234] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature
[2020-08-21 17:11:54,351] DEBUG Sending RM temperature 0.0 to topic broadlink/temperature

Looks like your Pi has run out of space?

Based on this terminal output, the SD card space is mostly free:

pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  4.6G   24G  17% /
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           2.0G   74M  1.9G   4% /dev/shm
tmpfs           2.0G  8.6M  1.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   54M  199M  22% /boot
tmpfs           391M  4.0K  391M   1% /run/user/1000

Looks like that is a current problem with the project:

Looks like the error might actually stem from the python-broadlink project:

Thanks for this info :pray:
Does it mean I’m stuck till they fix the problem?
Or will I be able to use the workaround described in the second link?

Try the following lines in the Python interactive shell:

First find your device and enter learning mode

import broadlink device = broadlink.discover() devices.auth() device.enter_learning()

Now the LED indicator should be white, press the button now. After that, run:

packet = devices.check_data() print(packet.hex())

This should show the IR packet in hex format.

I’m not sure at this stage! If it was me I would certainly try the workaround - worst case is that it doesn’t work.

Where do you get to with using the Broadlink binding for openHAB? Still stuck on learning codes?