mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.36k stars 477 forks source link

Broadlink RM4 PRO is not able to learn or to send RF Signal #358

Closed Virtual-Nomad closed 3 years ago

Virtual-Nomad commented 4 years ago

Unsure if this is the right place to raise this issue, however, I cam across https://github.com/mjg59/python-broadlink/issues/355 which relates to a similar issue except with IR. Currently, I am trying to get my RM4 Pro to work with the HA and having issues bring able to learn RF (IR learns and sends no problem at all) with both python-broadlink and Home assistant. (I also have an issue with it as a sensor (temperature and humidity) - although not that concerned/interested in this side at the moment)

Current Setup Home Assistant 0.109.3 Broadlink RM4 Pro Added to network using python-broadlink - PASS when I attempt devices[0].host[0] > ‘192.168.1.172’ - PASS devices[0].get_type() > ‘Unknown’ - Cant get the type (so this may be a concern or compatibility issue) devices[0].enter_learning() > AttributeError: device instance has no attribute ‘enter_learning’ _FAIL

Under Home assistant Added to HA as switch - configuration.yaml switch: platform: broadlink host: 192.168.1.172 mac: 24:df:a7:b9:c0:5a type: rm4_pro timeout: 15 retry: 5 switches: tv_samsung_power: friendly_name: "Samsung TV Power" command_on: IRSTRING command_off: IRSTRING When I run broadlink.learn

As far as the sensor is concerned sensor: platform: broadlink host: 192.168.1.172 mac: 24:df:a7:b9:c0:5a type: rm4_pro monitored_conditions: temperature humidity Both Temperature and Humidity just show a value of 0

Do you know if anyone has been successful with the RM4 Pro and RF?

Another point is that I cant get the RM4 Pro to work with e-control (or broadlink manager) so have not been able to get any RF packets to test it broadlink.send command to see if that works.

felipediel commented 4 years ago

@Virtual-Nomad The RF functionality has not been fully tested because I don't have the device. Would you like to help me by making some captures in Wireshark so I can add this functionality?

Virtual-Nomad commented 4 years ago

@felipediel more than happy to. Just be aware I am from the windows world and only now trying to get up to speed with all things python, home assistant. But I am familiar with wireshark (in windows world) so with a little guidance would be able to help out.

felipediel commented 4 years ago

@Virtual-Nomad Do you have an iOS device? It is not necessary, but it will be easier if you have it.

Virtual-Nomad commented 4 years ago

Yes mate (although I can arrange an android if required). Is there an alternate communications channel you wish to use for all testing results/process etc. I am in Brisbane, Australia so time zone wise it is UTC +10 with evenings and weekends being the times I can devote to any testing.

felipediel commented 4 years ago

@Virtual-Nomad Great!

  1. You need to run this program on Windows and make some captures while controlling the device with the official app on an iOS device. Execute only one type of command per capture and name the file with the name of the command (e.g. learn_rf).
  2. Run this script using python3 debug.py. A file named debug.txt will be created.
  3. Send me the files.
Virtual-Nomad commented 4 years ago

So currently setup Windows 10 Installed Wireshark (Windows) installed itunes Installed python3 Downloaded rvi_capture.py Downloaded debug.py

First run of "rvi_capture.py"

when I run debug.py however I am getting this error ... do I need to download additional components? C:\Temp\rvi_capture-master>python3 debug.py Traceback (most recent call last): File "debug.py", line 40, in from cryptography.hazmat.backends import default_backend ModuleNotFoundError: No module named 'cryptography'

Virtual-Nomad commented 4 years ago

image So as per the above (with the exception of debug) I think I have everything running. Connected the iphone to the PC via the USB Installed the Broadlink App

No files created (although there is an empty pycache sub directory)

I assume I am missing something basic (NB I have also removed webroot incase it was an issue)

Virtual-Nomad commented 4 years ago

@felipediel This may not actually achieve what it is you are after, however, given I wasn't really sure how the requested approach worked. I setup a hotspot AP on my laptop and connected both the iphone and RM4 Pro to the Wifi. I then used wireshark to record all traffic across the hotspot wifi during the process of learning an RF signal. It will probably have a lot of there traffic captured but it may hold what you are after. in this capture the iphone is 192.168.137.152 and the RM4 is 192.168.137.126 RFOfficeFan-LearnLowSpeed.zip

Virtual-Nomad commented 4 years ago

Side note ... I just noticed rvi_capture states "NOTE: There has been a major protocol change in iOS 13, so this will only work for iOS 12 and earlier." my iphone is IOS 13. Not sure if that has factored.

felipediel commented 4 years ago

@Virtual-Nomad Wireshark alone does not solve. If you did not succeed with rvictl you can install the Broadlink application on an Android emulator and make the captures with Wireshark. I recommend MEmu emulator. You may find this comment useful.

To solve the cryptography error just type: pip install cryptography

Virtual-Nomad commented 4 years ago

@felipediel wasn't able to install MEmu as just get a run time error. Anyway found an older iphone with IOS12 so managed to revert back to RVICTL. so I have attached both learning and sending captures. Not sure about the debug.txt but I have included it I am correct you simply run python debup.py once you have finished the capture? RFOfficeFan-LearningOff.zip RFOfficeFan-SendingOff.zip

felipediel commented 4 years ago

@Virtual-Nomad Great! The captures are good. Now I need you to disable the cloud, run debug.py again and send me debug.txt.

Virtual-Nomad commented 4 years ago

Not sure if I am clear what I need to do however;

Re-established direct connection/setup using python-broadlink

import broadlink broadlink.setup('','',3) devices = broadlink.discover(timeout=5) devices[0].auth() True devices[0].host ('192.168.137.220', 80)

I did go to the disable the cloud link above but wasn't really sure what was required. So hoping I read between the lines correctly

felipediel commented 4 years ago

@Virtual-Nomad Sorry, I was unable to decrypt the content of the messages because your device was connected to the cloud during the captures. You need to block the device from accessing the internet using a firewall. Here are the instructions from someone who has achieved this before.

Virtual-Nomad commented 4 years ago

@felipediel just so I am clear should I be using the python-broadlink integration to simply establish a connection to the device and run the debug.py. I guess follow what i did above but simply be disconnected from the internet during this the tests (As in my entire wifi network should be offline from the internet (both the RM4 Pro and My laptop) ? Or should I still have the device connected to the broadlink app (with network disconnected from the internet)

felipediel commented 4 years ago

@Virtual-Nomad The debug serves to intercept your local key. It worked, you don't need to run it anymore.

The problem is with the captures. You need to block the IP address of the Broadlink device using a firewall (your router probably has a built-in firewall). If the device connects to the internet all captures will be lost because they will be encrypted with a key that is in the cloud and I have no access to it. Don't block the phone or the laptop, they need access to the internet.

Do this and capture the commands again (yes, sorry about that).

Virtual-Nomad commented 4 years ago

@felipediel No problem although will be later tonight

Virtual-Nomad commented 4 years ago

@felipediel Ok so a new set of results for you Setup Iphone ios12 with broadlink app with RM4 Pro added as a device

RM4 Pro Connected to WfFi

Wireshark Captures for

RM4ProInternetBlock-RFOfficeFan.zip

felipediel commented 4 years ago

@Virtual-Nomad It didn't work, your device is still connected to the cloud. I'll teach you how to check if it worked.

  1. Open the captures in Wireshark.
  2. In filter, type ip.addr == 192.168.1.172.
  3. Find a packet that has 07 in the sixth row of the first column (beside 0050).
  4. Check the last byte of that packet. It needs to be 00.
  5. If the last byte is 01, it didn’t work. You need to stop everything and start over.
felipediel commented 4 years ago

Try blocking your phone with the firewall.

Virtual-Nomad commented 4 years ago

I'll get another router that allows me to view packets/traffic and has better capabilities than my current home internet router. Any chance you can send me a screenshot of what you mean in the above? I am not sure if my columns are possibly different. Ie my 6th column is Length and I can't seem to find any 07 or 0050 (See screenshot) image

For the heck of it I have taken another record and send with the phone blocked as well. So you never know that may work the way you need.

RM4Pro+PhoneInternetBlock.zip

Thanks for the patients.

felipediel commented 4 years ago

wireshark

Virtual-Nomad commented 4 years ago

SO not sure where I am going wrong. I disabeld the internet router all together but still get the following

image RM4Pro+PhoneInternetBlock-RFBedroomFan-LearnOff-LongPress+ShortPress2.zip

I have done another capture in that state just the same

felipediel commented 4 years ago

Hey @Virtual-Nomad, good news for you. My code is working fine for the RF functions, I don't need to torture you anymore.

After this update you will be able to learn RF from your RM4 Pro using the CLI. Soon I will take this changes to Home Assistant, but we still have other updates in the queue, so don't hold your breath.

felipediel commented 4 years ago

What worries me is the temperature and humidity. Is it showing zero? Are you using the HTS2 cable?

Virtual-Nomad commented 4 years ago

@felipediel sounds good ... How do I keep tabs on when it has been included in a beat or release version?

Virtual-Nomad commented 4 years ago

What worries me is the temperature and humidity. Is it showing zero? Are you using the HTS2 cable?

Ok so that would be the issue then. I don't and assumed it was part of the RM4 Pro. Thanks

felipediel commented 4 years ago

@felipediel sounds good ... How do I keep tabs on when it has been included in a beat or release version?

I will keep you informed here.

Lecturer555 commented 4 years ago

Felipediel, Virtual-Nomad Hello! I am also really looking forward to solving this problem with RF. Thank you for not leaving this unattended! Waiting for an update at Home Assistents

com-xuonghuynh commented 4 years ago

Hope this will work soon!

Virtual-Nomad commented 4 years ago

@felipediel Any chance there may be an update on when we may see this built into a beta or full release I would love to test it as I need to make a call if I continue with the broadlink or move to something else. Thanks in advance.

felipediel commented 4 years ago

We are in the middle of a refactor with 4 updates in the queue. New features are blocked. I also need this. Once everything is ready, I will add it, but as I said, it will take a while.

Virtual-Nomad commented 4 years ago

@felipediel Thanks for the response ... without much experience in code dev is it likely to be weeks or months? I certainly understand you will have priorities so I am not wishing to pressure you.

Thanks as always your skills and efforts are appreciated

com-xuonghuynh commented 4 years ago

@felipediel Sorry, can it work with broadlink_cli yet ? I just try to pull the new code then try to catch from broadlink_cli with my RF remote but it not catch anything. Just can't wait it update to home assistant 😄

felipediel commented 4 years ago

@Virtual-Nomad Sorry, I can't give you a deadline because there are steps that don't depend on me. But I promise to dedicate all my free time to these updates.

@com-xuonghuynh Are you sure? Did you use --rfscanlearn?

com-xuonghuynh commented 4 years ago

@felipediel I just did it. Press and hold the remote button until the orange light gone but "RF Frequency not found". I can add it by using Broadlink App before.

perfektor2007 commented 4 years ago

@com-xuonghuynh out of curiosity, what is your device type and what firmware are you running (from the broadlink app)?

I tried to figure rfscanlearn for days without success and finally gave up and tried adding the RM4 pro back to the broadlink app. Tried learning RF within the app but also failed there☹️.

At the end I stumbled upon few posts from the community within the app that rf learning is broken in the last updates... Maybe you can check it out as well.

My device type is 0x61a2 and broadlink app states firmware version v52076.

Cheers

Virtual-Nomad commented 4 years ago

@felipediel just checking in to see if it has now been incorporated. Or is there a way I can pull down your fix separately?

felipediel commented 4 years ago

@Virtual-Nomad This will take time. It is not as simple as it looks. This feature requires modifying the database structure. We are in the middle of a refactoring. I can't touch this right now.

You can use the CLI for now.

ryanerwin commented 4 years ago

You can use the CLI for now

@felipediel How do use the CLI for now to learn RF signals with the RM4 pro? Do I need to be running the latest git checkout or is the 0.14.0 latest pip3 release sufficient?

I've tried broadlink_cli --learn and I get: Learning... No data received... I've tried broadlink_cli --rfscanlearn and I get: RF Frequency not found

Here are background details on my systems

broadlink_discovery
``` Discovering... ########################################### RM4 # broadlink_cli --type 0x6026 --host 192.168.1.51 --mac 6c79e4a7df24 Device file data (to be used with --device @filename in broadlink_cli) : 0x6026 192.168.1.51 6c79e4a7df24 temperature = 30.38 ```
pip3 show broadlink
``` Version: 0.14.0 Summary: Python API for controlling Broadlink IR controllers Home-page: http://github.com/mjg59/python-broadlink Author: Matthew Garrett Author-email: mjg59@srcf.ucam.org License: UNKNOWN Location: /usr/local/lib/python3.8/dist-packages Requires: cryptography Required-by: ```
neofetch
  neofetch
            .-/+oossssoo+/-.               ryan@ri9 
        `:+ssssssssssssssssss+:`           -------- 
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 20.04 LTS x86_64 
    .ossssssssssssssssssdMMMNysssso.       Kernel: 5.4.0-37-generic 
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Uptime: 1 hour, 50 mins 
  +ssssssssshmydMMMMMMMNddddyssssssss+     Packages: 4642 (dpkg), 7 (snap) 
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Shell: zsh 5.8 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Resolution: 5120x1440 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   DE: GNOME 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM: Mutter 
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   WM Theme: Adwaita 
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Theme: Yaru-light [GTK2/3] 
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Icons: Papirus-Dark [GTK2/3] 
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/    Terminal: gnome-terminal 
  +sssssssssdmydMMMMMMMMddddyssssssss+     CPU: Intel i9-9900K (16) @ 5.000GHz 
   /ssssssssssshdmNNNNmyNMMMMhssssss/      GPU: AMD ATI Radeon RX 470/480/570/5 
    .ossssssssssssssssssdMMMNysssso.       Memory: 5771MiB / 31842MiB 
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`                                   
            .-/+oossssoo+/-.
felipediel commented 4 years ago

@ryanerwin I think there is a problem with the latest firmware on these devices. Some users are complaining that the RF doesn't work even with the official app. If confirmed, you have to wait for the next firmware update.

ryanerwin commented 4 years ago

Some users are complaining that the RF doesn't work even with the official app

I had been avoiding the official app until now, but was concerned that perhaps my devices were not compatible all all... So I connected the official (Android app) to my RM4 pro and I'm able to learn most of the RF signals that I'm concerned about via the official app.

I can now confirm, with the latest firmware (v52076) and the official Android app (v1.3.31), the RF function does work on the RM4 Pro.

Virtual-Nomad commented 4 years ago

@felipediel ... that annoying Australian is back just checking up if there has been any movement on this? I will start fitting out the new house in 2 weeks, so probably at the point at which I need to make a call if I will wait for the inclusion of your fix, or changing platforms. What are your thoughts? Should i move to a different HA rf bridge solution?

ryanerwin commented 4 years ago

@Virtual-Nomad Same question....

What are your thoughts? Should i move to a different HA RF bridge solution?

Sure wish Broadlink would actually help support @felipediel ... I messaged them to ask what sort of developer support they offer, but they want to hear from the actual project owner, not some random user

felipediel commented 4 years ago

@Virtual-Nomad We are in the middle of a refactor. Then we have two updates in the queue. And then I can start working on this feature. It won't be ready in two weeks.

You can use --rfscanlearn as a temporary solution to obtain RF codes:

$ ./broadlink_cli --rfscanlearn --device "0x6026 192.168.1.172 24dfa7b9c05a"
Learning RF Frequency, press and hold the button to learn...

Press and hold a button on the remote.

Found RF Frequency - 1 of 2!
You can now let go of the button
Press enter to continue...

Press enter.

To complete learning, single press the button you want to learn

Short press the button and you get the code:

Found RF Frequency - 2 of 2!
b2002c0221000017b1121101121112112211022101221121211011222110110000000
Base64: b'sgAsAhEREhESEQIEhEBEhESERISERIRARIiEQESERISERESEhEAAF3AAAAAAAAA=='

Now you can set up a switch with Home Assistant:

switch:
  - platform: broadlink
    host: 192.168.1.172
    mac: 24:df:a7:b9:c0:5a
    switches:
        name_of_the_switch:
            friendly_name: "LG Tv Power"
            command_on: sgAsAhEREhESEQIEhEBEhESERISERIRARIiEQESERISERESEhEAAF3AAAAAAAAA==
            command_off: sgAsAhEREhESEQIEhEBEhESERISERIRARIiEQESERISERESEhEAAF3AAAAAAAAA==

You can also use broadlink.send:


script:
  name_of_the_script:
    sequence:
      - service: broadlink.send
        data:
          host: 192.168.1.172
          packet: sgAsAhEREhESEQIEhEBEhESERISERIRARIiEQESERISERESEhEAAF3AAAAAAAAA==
Virtual-Nomad commented 4 years ago

@felipediel thanks for the above .... works a treat so I can go ahead as planned. Really appreciate all the help

burakcankose commented 4 years ago

Hi !

I tried this but discovery OK! but learn have error.

Traceback (most recent call last): File "./broadlink_cli", line 8, in import broadlink ModuleNotFoundError: No module named 'broadlink'

felipediel commented 4 years ago

@burakcankose Try this:

$ python3 broadlink_cli --rfscanlearn --device "0x6026 192.168.1.172 24dfa7b9c05a"

If it does not work you need to install the module:

$ pip3 install broadlink
burakcankose commented 4 years ago

@felipediel

Traceback (most recent call last): File "broadlink_cli", line 8, in import broadlink ModuleNotFoundError: No module named 'broadlink'

after

pip install broadlink Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: broadlink in /usr/local/lib/python2.7/dist-packages (0.14.0) Requirement already satisfied: cryptography>=2.1.1 in /usr/lib/python2.7/dist-packages (from broadlink) (2.6.1)

felipediel commented 4 years ago

Try pip3