Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to RF scan a specific frequency #613

Merged
merged 5 commits into from
Apr 9, 2024
Merged

Conversation

DarkStarSword
Copy link
Contributor

@DarkStarSword DarkStarSword commented Aug 15, 2021

This adds an optional parameter to find_rf_packet(), along with a
corresponding --rflearn parameter (defaulting to 433.92) to
broadlink_cli that specifies the frequency to tune to, rather than
requiring the frequency be found via sweeping. This is almost mandatory
for certain types of remotes that do not repeat their signals while the
button is held, and saves significant time when the frequency is known
in advance or when many buttons are to be captured in a row.

Fixes #459

This adds an optional parameter to find_rf_packet(), along with a
corresponding --rflearn parameter (defaulting to 433.92) to
broadlink_cli that specifies the frequency to tune to, rather than
requiring the frequency be found via sweeping. This is almost mandatory
for certain types of remotes that do not repeat their signals while the
button is held, and saves significant time when the frequency is known
in advance or when many buttons are to be captured in a row.

Additionally:

- A get_frequency() API is added to return the current frequency the
  device is tuned to.

- A check_frequency_ex() API is added to perform functions of both
  check_frequency() and get_frequency() in a single call.

- broadlink_cli --rfscanlearn will now report the current frequency at 1
  second intervals during sweeping, and will report the frequency it
  finally locks on to.
@DarkStarSword
Copy link
Contributor Author

Just amended the commit to fix a typo in the commit message specifying the wrong default frequency. Code is unchanged.

@valleedelisle
Copy link

Just tested this PR because who needs to scan the whole spectrum right? And it just worked. Nice job and thanks.

@rinie
Copy link

rinie commented Sep 4, 2021

On
python broadlink_cli --type 0x272a --host ... --mac ... --rflearn 433.92

I get Device tuned to 0.0MHz
Is that correct?

And
--rfscanlearn
Learning RF Frequency, press and hold the button to learn...
Sweeping 0.0MHz...
Sweeping 0.0MHz...
Sweeping 0.0MHz...
Found RF Frequency 0.0MHz - 1 of 2!
You can now let go of the button
Press enter to continue...
To complete learning, single press the button you want to learn
Found RF Frequency - 2 of 2!

@hamwong
Copy link

hamwong commented Sep 6, 2021

I am using RM pro, type ID: 0x2712, does python-broadlink support RF on this model? I found LED never turn red when I start learnRF and when I use app e-broadlink, led turn red immediately after I press learn

@DanielBaulig
Copy link

Can we get this merged? Anything that is still blocking this?

As outlined this is super useful for remotes that don't repeat their code when holding the button. It's virtually impossible to read codes from those remotes using python-broadlink without this change.

@felipediel
Copy link
Collaborator

Hi. Much better, thanks a lot!

I just came to say that I have not forgotten this PR, it will be included as soon as I find time to give it some treatment and prepare an update for Home Assistant 👍

@ScottESanDiego
Copy link

Currently HA is a bit broken for learning, at least for remotes like @DarkStarSword mentioned that don't repeat the signal. I can't find a way to work around it.

@felipediel
Copy link
Collaborator

felipediel commented Mar 21, 2022

Hi @DarkStarSword. I made some changes. My remote works a bit different so I can't test. Still works for you?

@romelec
Copy link

romelec commented Jun 19, 2022

I'm not @DarkStarSword but successfully tested it with an A-OK remote for a roller shutter.
It does not repeats the signal so you need to push the button at least 10 times to have a chance to detect the frequency that is reported between 433.88 and 433.92, this is much better/faster with this fix.

@jkor03
Copy link

jkor03 commented Oct 21, 2022

@felipediel are there still plans to add this functionality? After doing a few hours of research online, it seems like remotes with the ~433 frequency won't work until something like this is implemented. I think this frequency is especially common for ceiling fan remotes (at least that's my use case). Appreciate any insight you can provide!

@ahaverty
Copy link

Anything I can do to help here?
Context: I'm trying to learn a tonne of rollerhouse rf commands, to combat their rolling codes, but the sweep limitation is making it a very long manual process.

@ahaverty
Copy link

I've tested this PR via the cli, and it's working well for my RM4Pro,
and can confirm your changes look good too @felipediel

For anyone else looking to quickstart on the PR:
Install broadlink from DarkStarSword dev branch
pip3 install git+https://github.com/DarkStarSword/python-broadlink.git@dev

Checkout the branch or download the cli file
git clone https://github.com/DarkStarSword/python-broadlink
git checkout dev
cd python-broadlink/cli

Get your broadlink devices details for the --device flag with:
python3 broadlink_discovery

Run a specific frequency learn with the above device details, and your frequency:
python3 broadlink_cli --device "0x649b 192.168.01.22 ec0bae3dea8d" --frequency 433.92 --rflearn

I'm rusty on my python/pip, so apologies if this is a roundabout way of testing the PR, but it seems to work for me on mac.

@felipediel
Copy link
Collaborator

Thank you! I'll merge as soon as I have time to create a PR in Home Assistant.

@Chanete Chanete mentioned this pull request Feb 8, 2023
@abreups
Copy link

abreups commented Mar 8, 2023

I've tested this PR via the cli, and it's working well for my RM4Pro, and can confirm your changes look good too @felipediel

For anyone else looking to quickstart on the PR: Install broadlink from DarkStarSword dev branch pip3 install git+https://github.com/DarkStarSword/python-broadlink.git@dev

Checkout the branch or download the cli file git clone https://github.com/DarkStarSword/python-broadlink git checkout dev cd python-broadlink/cli

Get your broadlink devices details for the --device flag with: python3 broadlink_discovery

Run a specific frequency learn with the above device details, and your frequency: python3 broadlink_cli --device "0x649b 192.168.01.22 ec0bae3dea8d" --frequency 433.92 --rflearn

I'm rusty on my python/pip, so apologies if this is a roundabout way of testing the PR, but it seems to work for me on mac.

I tried the steps above but command complains that arguments --frequency and --rflearn are unrecognized. dev branch, yes. What am I missing?

@ahaverty
Copy link

I tried the steps above but command complains that arguments --frequency and --rflearn are unrecognized. dev branch, yes. What am I missing?

Are you sure you're trying the correct repo's dev branch?

@abreups
Copy link

abreups commented Mar 12, 2023

You are right. I was actually using the wrong repo. Fixed.
Now when I issue the command:
./broadlink_cli --device "0x520b 192.168.68.123 ec0baea07173" --frequency 433.92 --rflearn
I immeadiately get the following message in response:

Press the button you want to learn, a short press...
Traceback (most recent call last):
  File "/home/paulo/broadlink_docker/python-broadlink/cli/./broadlink_cli", line 225, in <module>
    dev.find_rf_packet(frequency)
AttributeError: 'Device' object has no attribute 'find_rf_packet'

@sthales
Copy link

sthales commented Apr 14, 2023

I've tested this PR via the cli, and it's working well for my RM4Pro, and can confirm your changes look good too @felipediel

For anyone else looking to quickstart on the PR: Install broadlink from DarkStarSword dev branch pip3 install git+https://github.com/DarkStarSword/python-broadlink.git@dev

Checkout the branch or download the cli file git clone https://github.com/DarkStarSword/python-broadlink git checkout dev cd python-broadlink/cli

Get your broadlink devices details for the --device flag with: python3 broadlink_discovery

Run a specific frequency learn with the above device details, and your frequency: python3 broadlink_cli --device "0x649b 192.168.01.22 ec0bae3dea8d" --frequency 433.92 --rflearn

I'm rusty on my python/pip, so apologies if this is a roundabout way of testing the PR, but it seems to work for me on mac.

Amazing. Thank you!!

@abreups
Copy link

abreups commented Jun 28, 2023

You are right. I was actually using the wrong repo. Fixed. Now when I issue the command: ./broadlink_cli --device "0x520b 192.168.68.123 ec0baea07173" --frequency 433.92 --rflearn I immeadiately get the following message in response:

Press the button you want to learn, a short press...
Traceback (most recent call last):
  File "/home/paulo/broadlink_docker/python-broadlink/cli/./broadlink_cli", line 225, in <module>
    dev.find_rf_packet(frequency)
AttributeError: 'Device' object has no attribute 'find_rf_packet'

I still get the same error. Not working.

@krozgrov
Copy link

krozgrov commented Jul 2, 2023

I'm seeing the same error Press the button you want to learn, a short press...
Traceback (most recent call last):
File "/Users/krozgrov/Desktop/broadlink_cli.py", line 225, in
dev.find_rf_packet(frequency)
AttributeError: 'Device' object has no attribute 'find_rf_packet'

@clockbrain
Copy link

AttributeError: 'Device' object has no attribute 'find_rf_packet'

Sounds to me like you either didn't update broadlink/remote.py or are invoking an unpatched version. The patched version implements the frequency parameter.

In my case I manually applied the changes to broadlink_cli in my home directory and the changes to remote.py in .local/lib/python3.9/site-packages/broadlink

Works great for me.

@LordIvanhoe
Copy link

I'm seeing the same error Press the button you want to learn, a short press... Traceback (most recent call last): File "/Users/krozgrov/Desktop/broadlink_cli.py", line 225, in dev.find_rf_packet(frequency) AttributeError: 'Device' object has no attribute 'find_rf_packet'

I had the same problem, eventually i figured out that my RM4 Pro is newer model than those in init.py, so i just added mine and it worked. Check the ID of your RM against those listed in _init.py.

This was what i added:
0x520B: ("RM4 pro", "Broadlink")

@brentleeper
Copy link

Hello. Please merge this PR into the main branch. This feature works and otherwise does not change any existing functionality (the change is backwards compatible). If you do not implement this change I will fork this repo and actually maintain it.

@LordIvanhoe
Copy link

Hello. Please merge this PR into the main branch. This feature works and otherwise does not change any existing functionality (the change is backwards compatible). If you do not implement this change I will fork this repo and actually maintain it.

if its any help , i've already forked this and merged it, also added some new devices.. Feel free to start from there.

Here is my fork

@brentleeper
Copy link

Hello. Please merge this PR into the main branch. This feature works and otherwise does not change any existing functionality (the change is backwards compatible). If you do not implement this change I will fork this repo and actually maintain it.

if its any help , i've already forked this and merged it, also added some new devices.. Feel free to start from there.

Here is my fork

Awesome! Do you have this in PyPi?

@LordIvanhoe
Copy link

Hello. Please merge this PR into the main branch. This feature works and otherwise does not change any existing functionality (the change is backwards compatible). If you do not implement this change I will fork this repo and actually maintain it.

if its any help , i've already forked this and merged it, also added some new devices.. Feel free to start from there.
Here is my fork

Awesome! Do you have this in PyPi?

Sorry, no, i just needed a quick fix to be able to capture couple of RF remotes for my homeassistant, didnt bother any further :) But it works perfectly, no idea why this was abandoned...

@brentleeper
Copy link

Ok no worries. Curious if you want to make me a contributor on your repo or if I should make my own?

@LordIvanhoe
Copy link

Ok no worries. Curious if you want to make me a contributor on your repo or if I should make my own?

Sure thing, i've added you just now.

@brentleeper
Copy link

Thanks, I'll try to contribute there soon. I plan on adding a more advanced interface for creating custom devices, which are cached and available for use later and can also be edited later.

@tablatronix
Copy link

tablatronix commented Mar 30, 2024

What is the hold up here? More testing needed?

I need to bring this into
https://github.com/t0mer/broadlinkmanager-docker
and
https://github.com/kiwi-cam/homebridge-broadlink-rm

Anyone fork these yet with this? all my remotes are 433.92 and none learn with the rm40 pro unless I set freq with the app first, maybe Ill just have it not actually sweep...

@brentleeper
Copy link

What is the hold up here? More testing needed?

I need to bring this into

https://github.com/t0mer/broadlinkmanager-docker

and

https://github.com/kiwi-cam/homebridge-broadlink-rm

Anyone fork these yet with this? all my remotes are 433.92 and none learn with the rm40 pro unless I set freq with the app first, maybe Ill just have it not actually sweep...

See here: https://github.com/brentleeper/python-broadlink

@felipediel felipediel merged commit 634370d into mjg59:dev Apr 9, 2024
@felipediel
Copy link
Collaborator

Thanks @DarkStarSword! 🎉

@felipediel
Copy link
Collaborator

Ok guys, now to implement this in Home Assistant we need to create a new service to sweep the frequency separately, and this involves discussing with the core team why these changes are important. If anyone can join the discussion and share the experience with the current interface, explaining why it is problematic I would appreciate that: home-assistant/architecture#1076

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet