eschava / broadlink-mqtt

MQTT client to control BroadLink devices
MIT License
222 stars 60 forks source link

Can this repo work with RM4C mini? #64

Closed sangnguyenz closed 4 years ago

sangnguyenz commented 4 years ago

I wonder if this repo can work with this model (RM4C mini) as link below? https://www.amazon.com/Broadlink-BestCon-Universal-Control-Compatible/dp/B07ZGH8CLL Thanks for your contribution.

eschava commented 4 years ago

It should, do not have a device to check

sangnguyenz commented 4 years ago

Thank you

sangnguyenz commented 4 years ago

@eschava I have a question, can this publish a message from laptop to RM Mini 3 to control the devices? Thank you

eschava commented 4 years ago

@sangnguyenz This utility is MQTT based so you can use any MQTT client for sending a command to the device. For console I use mosquitto_pub

digitlength commented 4 years ago

I have an RM4C mini, but am not able to record. The below is the terminal output:

pi@raspberrypi:~/broadlink-mqtt $ python mqtt.py
[2020-04-27 20:59:26,762] DEBUG Connected to 'RM4' Broadlink device at '192.168.1.117' (MAC 24:df:a7:4f:7c:e6) and started listening for commands at MQTT topic having prefix 'broadlink/' 
[2020-04-27 20:59:26,771] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#
[2020-04-27 20:59:48,815] DEBUG Received MQTT message broadlink/masterbedroom/light/power record
[2020-04-27 20:59:48,817] DEBUG Recording command to file /home/pi/broadlink-mqtt/commands/masterbedroom/light/power
[2020-04-27 21:00:18,951] WARNING No command received

I am able to record commands using the Broadlink app.

Is there anything I can glean at this end to help?

eschava commented 4 years ago

Could you please try to record commands using broadlink_cli utility from python-broadlink package?

digitlength commented 4 years ago

I can't seem to get the python-broadlink package to discover my device.

Here's what I've done:

apt-get install -y git python3 python3-setuptools python3-crypto
git clone https://github.com/mjg59/python-broadlink.git
cd broadlink-python
python3 setup.py build
sudo python3 setup.py install
cd cli
python3 broadlink_discovery

When I run that last line, I get the following:

python3 broadlink_discovery
Discovering...
Traceback (most recent call last):
  File "broadlink_discovery", line 14, in <module>
    devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip, discover_ip_address=args.dst_ip)
  File "/usr/local/lib/python3.6/dist-packages/broadlink-0.13.2-py3.6.egg/broadlink/__init__.py", line 132, in discover
    cs.sendto(packet, (discover_ip_address, 80))
TypeError: str, bytes or bytearray expected, not NoneType

Not sure what to do from here...!

eschava commented 4 years ago

Hmm. Pretty weird. The same result with broadlink_cli?

digitlength commented 4 years ago

EDIT: Ignore all the below, other than as a reference. I now have it working, and the only thing I've done different to what's written below is used python3 rather than python when running mqtt.py.

pi@raspberrypi:~/broadlink-mqtt $ python3 mqtt.py
[2020-05-03 16:10:50,482] DEBUG Connected to 'RM4' Broadlink device at '192.168.1.117' (MAC 24:df:a7:4f:7c:e6) 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/#

Original comment below:

OK, after patching the python-broadlink source with this and this I finally got the cli scripts working:

pc@pc:~/Documents/src/python-broadlink/cli$ ./broadlink_discovery --dst-ip 192.168.1.117
Discovering...
###########################################
RM4
# broadlink_cli --type 0x62be --host 192.168.1.117 --mac e67c4fa7df24
Device file data (to be used with --device @filename in broadlink_cli) : 
0x62be 192.168.1.117 e67c4fa7df24
temperature = 0.0

I couldn't get ./broadlink_discovery working without the --dst-ip argument.

I can then use the --learnfile argument for broadlink_cli to learn the IR command from the remote:

pc@pc:~/Documents/src/python-broadlink/cli$ ./broadlink_cli --type 0x62be --host 192.168.1.117 --mac e67c4fa7df24 --learnfile BEDROOM-LIGHT.power
Learning...
Saving to BEDROOM-LIGHT.power

The contents of BEDROOM-LIGHT.power is:

2600b0040c2c0c000108281027100c2b0d2b0b2c0c2b0c2c0b2c27100c2b0c2c0b000108281028100b2c0c2b0c2c0b2c0b2c0c2b28100b2b0d2b0d000108271027100c2c0b2b0d2b0c2c0b2c0b2c280f0c2c0b2c0c000108281027100c2b0d2b0b2c0b2c0c2b0c2c27100c2b0c2c0c000107281028100c2b0c2b0c2c0b2c0b2b0d2b28100b2c0c2b0c000109271027110b2c0c2b0b2c0c2c0b2c0b2c280f0c2c0b2c0b000109281027100c2b0c2c0b2c0b2c0c2b0c2c27110b2b0c2c0b000109271127100b2c0b2c0c2c0c2b0b2c0d2a28110a2c0c2b0c000109271027100c2c0b2c0b2c0c2b0c2c0c2a28110c2b0b2c0c000108281126100c2b0c2c0b2c0b2c0c2b0c2c27100c2b0d2b0b000109271028100b2c0c2b0c2c0b2c0b2c0c2b28110a2c0c2b0c00010a261027110b2c0b2c0b2d0c2b0c2b0b2d26100c2c0b2c0c000108281126100c2b0c2c0b2c0b2c0d2b0c2b27100c2b0c2c0b000109271226110a2c0c2b0c2c0b2c0b2c0c2c27110a2c0c2b0c00010a261027110b2c0b2c0b2c0c2c0b2d0a2c27100c2c0b2c0c000109271126110b2b0c2c0b2c0b2c0c2c0b2d26100c2b0c2c0b000109271127110a2c0c2b0c2c0b2c0b2c0c2c27110a2c0c2b0c000109271028100b2d0a2c0b2d0b2c0b2c0b2c27110b2c0b2c0c000109271127100b2b0c2c0c2b0b2c0c2c0b2d27100b2c0b2c0c000109261226110a2d0b2b0c2c0b2c0b2c0c2c27100b2d0b2c0b000109271126110b2c0b2c0b2c0d2b0b2d0a2d26100c2d0a2c0c000109271126110b2c0b2d0a2d0a2d0b2c0b2c27110b2c0b2c0b000109271127100b2d0b2b0d2b0b2c0b2c0c2c27110a2d0b2c0b00010a261126110b2d0a2c0b2d0b2c0b2d0a2c27110b2c0b2c0c000109271225110b2c0b2d0a2d0a2d0b2c0c2c26110b2c0b2c0b00010927112712092d0b2c0b2d0a2d0a2d0b2c27110a2d0b2b0c00010a261126110b2d0b2b0b2d0b2d0a2c0c2b28100b2d0a2d0b00010a261027110b2c0c2c0b2c0a2d0b2c0c2d25100c2d0b2c0a00010a261127110a2d0b2c0b2c0b2d0a2e0a2c27110a2e0a2d0a00010a261126110b2e092d0a2e0a2d0a2d0a2d26110b2d0a2d0b00010a261027110b2c0b2e092d0a2e0a2d0a2e25110b2d0b2d0900010b251226110a2d0b2c0b2d0a2d0a2d0b2d26110a2e0a2d0a00010b251225120a2e092d0a2e0a2d0a2e092e25110b2d0a2e0a00010b25112613092e092e0a2d092e0a2d0b2d25110b2d0a2d0a00010b25132512092d0a2d0b2d0a2e092e0a2d26110a2f092e0a000109261225120a2e0a2d092f092e092e092f24120a2e092e0900010a27122513092d0a2e092e0930082f082f24120a2d0a2e0900010b251325120930082d0a2e092e092d0b2e25130930062f0900010c2415221408310630072e0a2f082f08312213092e092e0a00010a26122514082e092f082e092f092d0a2e2514082e092e0900010b25132512092f092e092f0830072f092f24140730082f0800010b25132414082f0831062f092f082f082f2415072e09300800010e22142314083106660831063008302315073105300800010e2215234c062f093204300830083023140600017e221522bb0632062f08351e1606300700014622191b8705d624140800018915172114063009a0057d0a0001a31b25090001710d0001aa1e000d05000000000000

Now, back to broadlink-mqtt:

pc@pc:~/Documents/src/broadlink-mqtt$ python mqtt.py 
[2020-05-02 08:24:49,500] DEBUG Connected to 'RM4' Broadlink device at '192.168.1.117' (MAC 24:df:a7:4f:7c:e6) and started listening for commands at MQTT topic having prefix 'broadlink/' 
[2020-05-02 08:24:49,513] DEBUG Connected to MQTT broker, subscribing to topic broadlink/#

Great, we're connected to the device, and to the MQTT broker. I now send the following command to the broker:

pi@raspberrypi:~ $ mosquitto_pub -t 'broadlink/masterbedroom/light/power' -m 'record'

And the response in broadlink-mqtt is:

[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 /home/adams-pc/Documents/src/broadlink-mqtt/commands/masterbedroom/light/power
[2020-05-02 08:26:09,023] DEBUG Done

The contents of power are:

2600ae04281028100b2b0d2b0b2c0b2c0c2b0c2c27100c2b0c2c0b000109271028110a2c0b2c0c2b0c2c0b2c0c2b28100b2c0b2c0c000109271027100c2c0b2c0b2c0c2b0c2b0c2c280f0c2c0b2c0b000109281027100b2c0c2b0c2c0b2c0c2b0c2c27100b2c0c2b0c000109271127100b2c0b2c0c2b0c2c0b2c0b2c27110b2c0b2c0c000108281126100c2b0c2c0c2b0b2c0c2c0b2c27100c2b0c2c0b000109271028100c2b0c2b0c2c0c2b0b2c0c2b28100b2c0c2b0c000109271126100c2c0b2c0b2c0c2c0b2c0b2c280f0c2c0b2c0b000109281027100b2c0c2c0b2c0b2c0c2b0d2b27100b2c0c2c0c000108271028100b2c0b2c0c2b0c2c0b2c0c2b27110b2c0b2c0c000109271126100c2c0c2b0b2c0c2b0c2c0b2c27110b2c0b2c0b000109271127110a2c0c2b0c2c0b2c0b2c0d2b280f0b2c0c2b0c000109281026100c2c0c2b0c2c0b2c0b2c0b2c27110b2c0b2c0b00010a271126100c2b0c2c0b2c0b2d0b2b0c2c27110b2b0c2c0b000109281026120a2c0b2c0c2c0b2c0b2d0b2b28110a2c0b2c0c000109271126110b2c0b2c0b2c0c2b0c2c0b2c27110b2c0b2d0a000109271127100b2c0c2c0b2c0b2d0b2c0b2d26110a2d0b2c0b000109271126120a2c0b2c0c2b0d2c0a2c0b2c27110b2c0b2c0c000109271126110b2c0b2c0b2c0c2b0c2c0b2c27100c2b0c2c0b00010a261127110a2d0a2c0c2c0c2b0b2d0b2c27110a2c0c2c0b000109271126110b2c0b2d0a2d0b2c0b2c0b2d26110b2c0b2d0a00010a271027110a2d0b2c0b2c0b2d0b2c0b2d26100b2c0c2c0b000109281125110b2c0b2c0c2d0a2d0a2d0a2c27120a2d0b2c0b000109281026110b2c0b2d0a2d0a2d0b2d0a2d26110b2c0b2c0b00010b251127110a2d0b2b0c2d0a2d0a2d0b2c27110a2d0b2c0b000109271127110a2c0b2d0a2c0c2c0b2d0a2c27110b2d0a2c0b00010a271126110a2e0a2d0a2d0a2d0b2c0b2d26110a2e0a2d0a00010a261126120a2d0a2d0b2c0b2e092d0b2c26120a2d0a2e0a00010a261027110b2c0b2d0a2d0b2d0a2d0a2e25120a2c0c2c0b00010a25122612092d0b2d0a2d0a2d0b2c0b2c2712092d0b2c0b00010b251225110b2e092e0a2d0a2d0a2e092e25110b2e092d0b000109271225120a2c0b2d0a2e092e0a2d0b2d2513092d0a2d0a00010b251126120a2e092e0a2d0a2e092e0a2d26110a2e092d0b00010b251126120a2d0a2e092d0b2d0a2e092e25120b2c0a2e0900010a26122612092f092d0a2e092f092d0a2e2611092f092e0900010b261224120a2e092d0b2c0b2e092e092f2413092e092e0a00010a261324120a2d0a2e092f082e0a2d0a2e25120a2d0a2e0a00010b24112712092f082f092e0930072f092e2513082e092e0a00010b25122513092e092e092f0930072e092f2413092f08300700010d2413241308310730072f0830082e092e2512093008300700010e22152213092f08660931062e0a2f2314082f08300800010b25132415072e092f092f082f0830072f241408660800010c241424150630082f08300730072f09302314073008300700010d23142315073106310631076806312216053107300800010f211225150667082f086708312214083006300800010f211d1b8307310631066a2000019b201c1a0001661d00019f1c1c1c000160230001aa10000d050000000000000000

The two strings (BEDROOM-LIGHT.power and power) do not match!

I can run the following, and it works - the light toggles on and off:

pc@pc:~/Documents/src/python-broadlink/cli$ ./broadlink_cli --type 0x62be --host 192.168.1.117 --mac e67c4fa7df24 --send @BEDROOM-LIGHT.power

But if I run the following, it doesn't work - the light doesn't change state:

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

I have tried overwritting the content of power with BEDROOM-LIGHT.power, but that doesn't seem to work either, unfortunately.

EDIT: Versions of things, if it helps:

pc@pc:~/Documents/src/python-broadlink/cli$ git show
commit f3d0427133072f919768d5af81df7ba93bffcf07 (HEAD -> master, origin/master, origin/HEAD)
Author: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com>
Date:   Sat Apr 25 06:41:04 2020 -0300

    Extend support to RM4c Mini (0x6070) (#348)
pc@pc:~/Documents/src/broadlink-mqtt$ git show
commit b3b2815d654e8a482aaa6f57670544ba4ba8fa7a (HEAD -> master, origin/master, origin/HEAD)
Merge: 0e2d3d0 11a8672
Author: Eugene Schava <eschava@gmail.com>
Date:   Wed Apr 29 11:28:09 2020 +0300

    Merge pull request #70 from digitlength/patch-1