Broadlink/Bestcon RM4C Mini via MQTT

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?

Like other people, the broadlink binding gave me the OFFLINE error code when I added the RM4 Pro to OpenHAB.

I’m sorry if this is a complete noob question, but how do I use the workaround?
Do I need to add my network/device info in every place there are brackets () in the workaround commands?
If that’s the case, I’m not sure what info I should add.

@mjeshurun I’ve updated my tutorial to include using python-broadlink to capture codes. Go back to my first post, to the Teach remote codes header, then click on Click to teach via python-broadlink. Let me know how it goes.

(This would probably also answer the first part of your question in post 15).

1 Like

I really don’t know how to thank you for all your good efforts and help.
You have my deepest gratitude! :pray: :pray: :pray:

I tried the python-broadlink solution you added, but I’m still getting error messages when I try to capture remote codes.
Here is a copy of the messages output when I followed your steps:

pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import broadlink
>>> devices = broadlink.discover(timeout=5)
>>> print(devices)
[<broadlink.rm4 object at 0xb66aadf0>]
>>> devices[0].auth()
True
>>> devices[0].enter_learning()
>>> packet = devices[0].check_data()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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
>>> print(packet.hex())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'packet' is not defined
>>> devices[0].send_data(packet)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'packet' is not defined
>>> 

I don’t know if this is related to the problem, but my RM4 Pro LED turns to color RED after I enter learning mode (It’s not WHITE as in your description). Also, the LED does not turn off after I press the remote button I want to learn.
I’m pretty sure the remote is close enough to the RM4 Pro to capture the code. The distance between the remote and RM4 Pro was 10 cm.

Yes, 10cm should certainly be close enough, unless the batteries in your remote have died!

Hmmm, I’m not sure what’s happening. I’ve never seen a red LED!

It might be worth completely re-setting the Broadlink device, and re-connecting it back to the wifi - just to start from new. Then try the new learning method?

I’ll have a think, but because I can’t replicate the error it’s a little tricky to debug. It’s obviously an issue, as evidenced by the GitHub link above, but not one I currently have!

EDIT: OK, so according to this comment, you will need to remove line 74 in the exceptions.py file within your python-broadlink folder.

You will then need to reinstall python-broadlink:

sudo python3 setup.py install

Then retry all the teaching stuff.

Still doesn’t explain the red LED though, I don’t think…

1 Like

Removed line 74, but it seems the problem still stays the same, as the error message indicates error 0xfffb (which was part of line 74).

pi@raspberrypi:~/python-broadlink $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import broadlink
>>> devices = broadlink.discover(timeout=5)
>>> print(devices)
[<broadlink.rm4 object at 0xb66b2cf0>]
>>> devices[0].auth()
True
>>> devices[0].enter_learning()
>>> packet = devices[0].check_data()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/python-broadlink/broadlink/__init__.py", line 631, in check_data
    check_error(response[0x22:0x24])
  File "/home/pi/python-broadlink/broadlink/exceptions.py", line 96, in check_error
    raise exception(error_code)
broadlink.exceptions.UnknownError: Unknown error: 0xfffb

I’ll try to reset the device and start again.

Unfortunately, resetting the device didn’t help. I’m still getting the same error message.

For the sake of documentation, here is a photo of the RM4 Pro with the red LED. Maybe it will help someone understand what’s going on.

When you’ve got time, could you run the following command when inside your python-broadlink folder, and paste the output here?

git log -1

Additionally, check out this post, especially when it gets to learning codes: could you try that method and let me know if it works? You’ve done almost all of it before, except it uses a slightly different learning method. I expect this to fail too, but just want to check!

Also, just to double check: how are you connecting the device to your WiFi? App or python-broadlink? If it’s the app I wonder whether it is somehow still connecting to the cloud, therefore disabling local control?

1 Like

Hi :slight_smile:
Here is the terminal output you requested:

 pi@raspberrypi:~/python-broadlink $ git log -1
commit fe4aa5b991e033d865e956d7a96526998e917e0f (HEAD -> master, tag: 0.14.1, origin/master, origin/HEAD)
Author: Daniel Hjelseth Høyer <mail@dahoiv.net>
Date:   Fri Jul 31 07:11:51 2020 +0200

    0.14.1

I connected my device to Wifi using the Broadlink app, but once the device was added to the Wifi network (and AP mode slow LED flashing stopped) I did not continue to add the device to the app.

I tried using the python-broadlink method to connect the device to the Wifi network, but the command did not do anything and the device stayed in AP mode with blue LED flashing slowly.
This is the command I used (with my network’s name and passcode):

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

Reading around online, it looks like your device only has a blue LED and a red/orange LED, and when it is in learning mode the red/orange LED is on. So it might actually be working as intended! If you have the user guide, it might be worth checking. Don’t forget that my guide is based on the RM4C Mini, which is not the same as yours!

When learning a remote code my white LED (your red/orange LED) remains on for at least 10 seconds after I started pressing the remote button. Make sure to keep pressing the button until the LED turns off! I don’t know whether this affects the broadlink.exceptions.StorageError: The device storage is full issue though.

If I was you, I would contribute to the open issue on the python-broadlink GitHub, explain the steps you’ve taken, and the results you’re getting, and see if anyone else can help!

can I use this command for block internet (cloud) access to the RM? I’ve a simple router and I can not block a single IP, only configure an IP reservation.

No, that command is only used to connect the RM device to your local wifi network.